> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 构建 RTSS 固件 

构建 RTSS 固件的前提条件和步骤。

## **前提条件**

<Note>
  **注意**

  * 在 Ubuntu 22.04 主机上编译 RTSS 源代码。
  * 按照 [BSP image build with firmware](https://dragonwingdocs.qualcomm.com/Key-Documents/Firmware-Guide/build-firmware#host-setup) 中的说明初始化构建环境。
</Note>

1. 运行 `git clone` 命令下载 RTSS 固件：
   ```xml theme={null}
   mkdir -p <FIRMWARE_ROOT>
   cd <FIRMWARE_ROOT>
   git clone -b <firmware release tag> --depth 1 https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0_ap_standard_oem_sail.git
   ```
   例如：
   ```css theme={null}
   git clone -b r2.0_00007.2 --depth 1 https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0_ap_standard_oem_sail.git
   ```
   `git clone` 命令会将内容克隆到 `<FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail.git` 目录中。有关最新的 `<firmware release tag>`，请参阅 [Release tags](https://dragonwingdocs.qualcomm.com/Key-Documents/Software-Release-Notes/introduction#release-tags)。

2. 下载 FreeRTOS 内核。
   1. 使用 `git clone` 命令克隆 FreeRTOS 内核：
      ```cpp theme={null}
      git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git -b V11.0.1
      ```
   2. 进入 FreeRTOS 内核目录：
      ```powershell theme={null}
      cd FreeRTOS-Kernel
      ```
   3. 将 `croutine.c`、`cspell.config.yaml`、`event_groups.c`、`include manifest.yml`、`queue.c`、`stream_buffer.c`、`tasks.c`、`timers.c` 和 `list.c` 文件复制到 `<top_directory>/sail_proc/FreeRTOS/kernel/`：
      ```cpp theme={null}
      cp -r croutine.c cspell.config.yaml event_groups.c include manifest.yml queue.c stream_buffer.c tasks.c timers.c list.c <top_directory>/sail_proc/FreeRTOS/kernel/
      ```

3. 下载 Arm<sup>®</sup> GNU Toolchain 编译器：

   <Note>
     **注意**

     仅在 x86 64 位主机上安装 Arm GNU Toolchain 编译器。
   </Note>

   1. 从 [Arm GNU Toolchain Downloads](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) 下载 `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi` 工具链变体：
      ```cpp theme={null}
      wget https://developer.arm.com/-/media/Files/downloads/gnu/14.3.rel1/binrel/arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi.tar.xz
      ```
   2. 解压下载的 `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi.tar.xz` 文件：
      ```undefined theme={null}
      tar -xf arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi.tar.xz
      ```
   3. 进入 `sail_proc` 目录：
      ```powershell theme={null}
      cd sail_proc
      ```
   4. 在 `sail_proc` 目录下创建 `toolchain` 文件夹：
      ```undefined theme={null}
      mkdir toolchain
      ```
   5. 将解压得到的 `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi` 文件夹复制到 `sail_proc/toolchain` 目录中。
      ```powershell theme={null}
      cp -r arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/SAIL.SI.1.2/sail_proc/toolchain
      ```
   6. 从 `<FIRMWARE_ROOT>/` 的顶层目录导出 `SECTOOLS` 变量：
      对于 IQ-9075：
      ```typescript theme={null}
      export SECTOOLS= <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/QCS9100.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR= <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/QCS9100.LE.2.0/common/sectoolsv2/ext/Linux
      ```
      对于 IQ-8275：
      ```typescript theme={null}
      export SECTOOLS= <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/QCS8300.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR= <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/QCS8300.LE.2.0/common/sectoolsv2/ext/Linux
      ```

## **步骤**

1. 进入 bash：
   ```undefined theme={null}
   bash
   ```
2. 进入 RTSS 的主目录：
   ```powershell theme={null}
   cd <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/SAIL.SI.1.2`
   ```
3. 在设备上设置构建环境：

   ```css theme={null}
   source sail_proc/build/ms/setupenv.sh
   ```

   <Note>
     **注意**

     1. 在运行该命令之前，请确保工具链和 RTOS 代码/二进制文件已复制到构建中，以避免编译问题。
   </Note>
4. 构建镜像：
   ```xml theme={null}
   make TARGET=<target name>
   ```
   对于 IQ-9075：
   ```undefined theme={null}
   make TARGET=lemans
   ```
   对于 IQ-8275：
   ```undefined theme={null}
   make TARGET=monaco
   ```
   RTSS 构建成功执行后，会在以下位置生成 `sailhyp.elf` 和 `sailsw1.elf`：
   对于 IQ-9075：
   > `qualcomm-linux-spf-2-0_ap_standard_oem_sail/SAIL.SI.1.2/sail_proc/build/ms/bin/SAIL_RTOS/DEBUG/lemans/signed`
   > 对于 IQ-8275：
   > `qualcomm-linux-spf-2-0_ap_standard_oem_sail/SAIL.SI.1.2/sail_proc/build/ms/bin/SAIL_RTOS/DEBUG/monaco/signed`
5. 将生成的 RTSS 文件复制到 `<workspace_path>/build-<DISTRO>/tmp-glibc/deploy/images/<MACHINE>/<IMAGE>/sail_nor` 文件夹中，以便对 NOR 闪存进行编程。
   示例：`<workspace_path>/build-qcom-wayland/tmp-glibc/deploy/images/qcs9075-iq-9075-evk/qcom-multimedia-image/sail_nor`
   参数：

   > * \<DISTRO>: `qcom-wayland`
   > * \<MACHINE>: `qcs9075-iq-9075-evk`
   > * \<IMAGE>: `qcom-multimedia-image`

   <Note>
     **注意**

     有关 \<MACHINE> 的信息，请参阅 [Software Release Notes](https://dragonwingdocs.qualcomm.com/Key-Documents/Software-Release-Notes/introduction)。
   </Note>
6. （可选）要刷新构建，请清理构建：
   ```xml theme={null}
   make clean TARGET=<target name>
   ```
   对于 IQ-9075：
   ```undefined theme={null}
   make clean TARGET=lemans
   ```
   对于 IQ-8275：
   ```undefined theme={null}
   make clean TARGET=monaco
   ```
   运行 `make clean TARGET=<target name>` 命令后，执行以下步骤，使用 `make TARGET=<target name>` 命令重新构建镜像：
   > 1. 进入 RTSS 的主目录：
   >    ```powershell theme={null}
   >    cd <FIRMWARE_ROOT>/qualcomm-linux-spf-1-0_ap_standard_oem_sail/SAIL.SI.1.2`
   >    ```
   > 2. 在设备上设置构建环境：
   >    ```css theme={null}
   >    source sail_proc/build/ms/setupenv.sh
   >    ```
   > 3. 重新构建镜像：
   >    ```xml theme={null}
   >    make TARGET=<target name>
   >    ```
   >    对于 IQ-9075：
   >    ```undefined theme={null}
   >    make TARGET=lemans
   >    ```
   >    对于 IQ-8275：
   >    ```undefined theme={null}
   >    make TARGET=monaco
   >    ```
7. 有关刷写 RTSS 的说明，请参阅 [Flash SAIL](https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/flash-with-qdl#flash-sail)。

## **后续步骤**

* [调试 RTSS](Debug-RTSS)
* [RTSS 测试命令](RTSS-test-commands)
* [向 SPINOR 闪存添加分区](Add-partitions-to-SPINOR-flash-memory)
