> ## 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.

# Build RTSS firmware 

Prerequisites and procedure for building RTSS firmware.

## **Prerequisites**

<Note>
  **Note**

  * Compile the RTSS source code on an Ubuntu 22.04 host computer.
  * The build environment is initialized as described in the [BSP image build with firmware](https://dragonwingdocs.qualcomm.com/Key-Documents/Firmware-Guide/build-firmware#host-setup).
</Note>

1. Download the RTSS firmware by running the `git clone` command:
   ```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
   ```
   For example:
   ```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
   ```
   The `git clone` command clones the content into the `<FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail.git` directory. For the latest `<firmware release tag>`, see [Release tags](https://dragonwingdocs.qualcomm.com/Key-Documents/Software-Release-Notes/introduction#release-tags).

2. Download the FreeRTOS kernel.
   1. Clone the FreeRTOS kernel using the `git clone` command:
      ```cpp theme={null}
      git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git -b V11.0.1
      ```
   2. Go to the FreeRTOS kernel directory:
      ```powershell theme={null}
      cd FreeRTOS-Kernel
      ```
   3. Copy the `croutine.c`, `cspell.config.yaml`, `event_groups.c`, `include manifest.yml`, `queue.c`, `stream_buffer.c`, `tasks.c`, `timers.c`, and `list.c` files to `<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. Download the Arm<sup>®</sup> GNU Toolchain compiler:

   <Note>
     **Note**

     Install the Arm GNU Toolchain compiler on x86 64-bit host computer only.
   </Note>

   1. Download the `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi` toolchain variant from [Arm GNU Toolchain Downloads](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads):
      ```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. Extract the downloaded `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi.tar.xz` file:
      ```undefined theme={null}
      tar -xf arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi.tar.xz
      ```
   3. Go to the `sail_proc` directory:
      ```powershell theme={null}
      cd sail_proc
      ```
   4. Create the `toolchain` folder under the `sail_proc` directory:
      ```undefined theme={null}
      mkdir toolchain
      ```
   5. Copy the extracted `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi` folder into the `sail_proc/toolchain` directory.
      ```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. Export the `SECTOOLS` variable from the top-level directory of `<FIRMWARE_ROOT>/`:
      For 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
      ```
      For 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
      ```

## **Procedure**

1. Enter bash:
   ```undefined theme={null}
   bash
   ```
2. Go to the main directory of RTSS:
   ```powershell theme={null}
   cd <FIRMWARE_ROOT>/qualcomm-linux-spf-2-0_ap_standard_oem_sail/SAIL.SI.1.2`
   ```
3. Set up the build environment on the device:

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

   <Note>
     **Note**

     1. Before running the command, ensure that the toolchain and RTOS code/binaries are copied to the build to avoid compilation issues.
   </Note>
4. Build the image:
   ```xml theme={null}
   make TARGET=<target name>
   ```
   For IQ-9075:
   ```undefined theme={null}
   make TARGET=lemans
   ```
   For IQ-8275:
   ```undefined theme={null}
   make TARGET=monaco
   ```
   After successful execution of the RTSS build, `sailhyp.elf` and `sailsw1.elf` are generated at:
   For 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`
   > For 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. Copy the generated RTSS files into the `<workspace_path>/build-<DISTRO>/tmp-glibc/deploy/images/<MACHINE>/<IMAGE>/sail_nor` folder to program on the NOR flash.
   Example: `<workspace_path>/build-qcom-wayland/tmp-glibc/deploy/images/qcs9075-iq-9075-evk/qcom-multimedia-image/sail_nor`
   Parameters:

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

   <Note>
     **Note**

     For information about \<MACHINE>, see the [Software Release Notes](https://dragonwingdocs.qualcomm.com/Key-Documents/Software-Release-Notes/introduction).
   </Note>
6. (Optional) To refresh the build, clean the build:
   ```xml theme={null}
   make clean TARGET=<target name>
   ```
   For IQ-9075:
   ```undefined theme={null}
   make clean TARGET=lemans
   ```
   For IQ-8275:
   ```undefined theme={null}
   make clean TARGET=monaco
   ```
   After running the `make clean TARGET=<target name>` command, perform the following steps to rebuild the image using the `make TARGET=<target name>` command:
   > 1. Go to the main directory of RTSS:
   >    ```powershell theme={null}
   >    cd <FIRMWARE_ROOT>/qualcomm-linux-spf-1-0_ap_standard_oem_sail/SAIL.SI.1.2`
   >    ```
   > 2. Set up the build environment on the device:
   >    ```css theme={null}
   >    source sail_proc/build/ms/setupenv.sh
   >    ```
   > 3. Rebuild the image:
   >    ```xml theme={null}
   >    make TARGET=<target name>
   >    ```
   >    For IQ-9075:
   >    ```undefined theme={null}
   >    make TARGET=lemans
   >    ```
   >    For IQ-8275:
   >    ```undefined theme={null}
   >    make TARGET=monaco
   >    ```
7. For instructions about flashing RTSS, see [Flash SAIL](https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/flash-with-qdl#flash-sail).

## **Next steps**

* [Debug RTSS](Debug-RTSS)
* [RTSS test commands](RTSS-test-commands)
* [Add partitions to SPINOR flash memory](Add-partitions-to-SPINOR-flash-memory)
