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

# 带固件的 BSP 镜像构建

## 简介

本文提供从源代码构建固件组件并将其集成到 Qualcomm BSP 镜像中的
概要说明。

固件源代码可供已签署所需协议的用户获取。如果您尚未获得访问权限，请创建
[Qualcomm ID](https://www.qualcomm.com/support/working-with-qualcomm)，
并查看 Working with Qualcomm 页面以了解有关帐户
验证和访问级别的更多信息。

从整体上看，您将学习以下内容：

* 设置主机系统并安装所需软件包 – [主机设置](#host-setup)
* 从 Chipcode 下载固件源代码 – [同步固件源代码](#sync-firmware-sources)
* 从源代码构建固件 – [构建固件](#build-firmware)
* 将构建好的固件包含到 BSP 镜像中 – [构建 BSP 镜像](#build-bsp-image)

## 支持的 SoC

本文档支持以下 SoC。如果你的芯片组未在
下表中列出，则此处描述的固件构建流程不适用于你的设备。

| SoC      | 说明                                             | 是否支持 |
| -------- | ---------------------------------------------- | ---- |
| QCS6490  | Qualcomm Dragonwing™ RB3 Gen 2 Vision Kit      | ✓    |
|          | Qualcomm Dragonwing™ RB3 Gen 2 Core Kit        | ✓    |
|          | Qualcomm Dragonwing™ RB3 Gen 2 Industrial Kit  | ✓    |
| QCS5430  | Qualcomm Dragonwing™ RB3 Gen 2 Lite Vision Kit | ✓    |
|          | Qualcomm Dragonwing™ RB3 Gen 2 Lite Core Kit   | ✓    |
| IQ9      | Qualcomm Dragonwing™ IQ-9075 评估套件              | ✓    |
| IQ8      | Qualcomm Dragonwing™ IQ-8275 评估套件              | ✓    |
| IQ6      | Qualcomm Dragonwing™ IQ-615 评估套件               | ✓    |
| IQ-X7181 | Qualcomm Dragonwing™ IQ-X7181 评估套件             | ✓    |
| IQ-X5121 | Qualcomm Dragonwing™ IQ-X5121 评估套件             | ✓    |

## 主机系统要求

* 操作系统
  * Ubuntu 22.04

- 配置
  * x86 机器
  * 四核 CPU，例如主频 3.4 GHz 的 Intel i7-2600（同等或更高配置）
  * 300 GB 可用磁盘空间（交换分区 > 32 GB）
  * 16 GB 内存

* 工具
  * Git 1.8.3.1 或更高版本
  * Tar 1.28 或更高版本
  * Python 3.10.2 或更高版本
  * GCC 10.1 或更高版本
  * GNU Make 4.0 或更高版本
  * Kas 4.8 或更高版本

- 权限
  * 运行部分命令需要 `sudo` 权限

## 安装 QSC-CLI

`qsc-cli` 是 Qualcomm 提供的命令行工具，为访问、管理和构建
Qualcomm 软件提供端到端的工作流。按照以下步骤在你的系统上安装
`qsc-cli`：

* 访问 [Qualcomm 支持页面](https://www.qualcomm.com/support/working-with-qualcomm)注册你的 Qualcomm 电子邮件 ID。

* 下载 `qsc-cli` 的 Debian 软件包：

  <CodeGroup>
    ```bash x86 theme={null}
    wget https://softwarecenter.qualcomm.com/api/download/software/tools/Qualcomm_Software_Center/Linux/Debian/latest.deb -O qsc_installer.deb
    ```

    ```bash ARM64 theme={null}
    wget https://softwarecenter.qualcomm.com/api/download/software/tools/Qualcomm_Software_Center/Linux/ARM64/Debian/latest.deb -O qsc_installer.deb
    ```
  </CodeGroup>

* 安装 `qsc-cli` Debian 软件包：
  ```bash theme={null}
  sudo apt update
  sudo apt install ./qsc_installer.deb
  ```

* 使用你的 Qualcomm ID 登录 `qsc-cli`。对大多数用户而言，Qualcomm ID 就是你的
  电子邮件地址。此命令会打开浏览器窗口以完成身份验证。如果浏览器
  没有自动打开，请复制终端中打印的链接并粘贴到浏览器中
  完成身份验证。
  ```bash theme={null}
  qsc-cli login
  ```

## 主机设置

以下说明适用于 Ubuntu 主机系统。Yocto 构建同样支持与 Yocto 兼容的其他[发行版](https://docs.yoctoproject.org/ref-manual/system-requirements.html#supported-linux-distributions)，但未针对它们进行验证。

* 安装以下软件包，为 Yocto 构建准备主机环境

  ```bash theme={null}
  sudo apt update
  sudo apt install build-essential chrpath cpio debianutils diffstat \
       file gawk gcc git iputils-ping libacl1 locales python3 python3-git \
       python3-jinja2 python3-pexpect python3-pip python3-subunit socat \
       texinfo unzip wget xz-utils zstd
  ```

* Qualcomm 使用 `kas` 工具来同步和构建 Yocto 项目。请按照以下步骤在系统上安装 `kas`

  <Note>
    在较旧的 Ubuntu 版本上，系统包管理器提供的 `kas` 版本可能已过时。推荐使用 `pipx` 安装 kas。
  </Note>

  1. 安装 `pipx`

     ```bash theme={null}
     sudo apt install pipx
     ```

  2. 将 `pipx` 的安装位置添加到 `PATH` 中

     ```bash theme={null}
     pipx ensurepath
     ```

     此命令会更新 shell 的启动文件，因此更改仅在新的 shell 会话中生效。请重启 shell 会话后再继续下一步。

  3. 安装 `kas`（需要 4.8 或更高版本）

     ```bash theme={null}
     pipx install "kas>=4.8"
     ```

* 验证 kas 是否安装成功。

  ```bash theme={null}
  kas --version
  ```

- 编译固件还需要以下软件包：
  ```bash theme={null}
  sudo apt-get install lib32stdc++6 libncurses5 checkinstall libreadline-dev \
       libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev \
       libbz2-dev libffi-dev curl
  ```

- 使用 `qsc-cli` 获取访问 Chipcode 所需的 PAT 令牌。该令牌
  将在两周后过期。

  ```bash theme={null}
  qsc-cli show-access-token
  ```

  ```text Sample output theme={null}
  user@hostname:/local/mnt/workspace$ qsc-cli show-access-token
  [Info]: Starting qsc-cli version 0.0.0.9
  5LThNlklb55mMVLB5C2KqUGU2jCF
  ```

- 在你的 `~/.netrc` 文件中添加以下条目，以完成对 Chipcode
  仓库访问的身份验证：
  ```text theme={null}
  machine chipmaster2.qti.qualcomm.com
  login <login-id>
  password <access-token>

  machine qpm-git.qualcomm.com
  login <login-id>
  password <access-token>
  ```

- 更新 git 配置：
  ```bash theme={null}
  # Add the following git configurations to fetch large size repositories and to avoid unreliable connections
  git config --global http.postBuffer 1048576000
  git config --global http.maxRequestBuffer 1048576000
  git config --global http.lowSpeedLimit 0
  git config --global http.lowSpeedTime 999999
  # Add the following git configurations to follow remote redirects from http-alternates files or alternates
  git config --global http.https://chipmaster2.qti.qualcomm.com.followRedirects true
  git config --global http.https://qpm-git.qualcomm.com.followRedirects true
  ```

## 配置参数

下表描述了当前版本的构建标签。这些
值需要替换到构建命令中。

| 发布标签                                     | 标识符            |
| ---------------------------------------- | -------------- |
| meta-qcom-release-tag                    | qli-2.0        |
| meta-qcom-extras-release-tag             | 213195-wrynose |
| firmware-release-tag                     | r2.0\_00007.2  |
| firmware-release-tag (IQ-X7181/IQ-X5121) | r2.0\_00008.0  |

## 映射固件源代码

下表描述了你可以下载的固件发行版。
有关 Yocto 层的更多信息，请参阅
[Qualcomm Linux 元数据层](/zh/Key-Documents/Yocto-Guide/qualcomm-linux-metadata-layers)。

**访问级别与固件发行版的映射**

| **发行版**                                             | **说明**                  | **Yocto 层**                                                 |
| --------------------------------------------------- | ----------------------- | ----------------------------------------------------------- |
| Qualcomm\_Linux.SPF.2.0\|AP\|Standard\|OEM\|NoModem | 高层 OS 和固件源码，不含调制解调器     | `meta-qcom`<br />`meta-qcom-distro`<br />`meta-qcom-extras` |
| Qualcomm\_Linux.SPF.2.0\|AP\|Standard\|OEM          | 高层 OS 和固件（仅 GPS）源码      | `meta-qcom`<br />`meta-qcom-distro`<br />`meta-qcom-extras` |
| Qualcomm\_Linux.SPF.2.0\|AMSS\|Standard\|OEM        | 高层 OS 和固件（GPS 和调制解调器）源码 | `meta-qcom`<br />`meta-qcom-distro`<br />`meta-qcom-extras` |

**固件发行版与 git 仓库的映射**

| **发行版**                                               | **仓库 URL**                                                                                                                                                                                                   | **克隆目录**                                           |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| Qualcomm\_Linux.SPF.2.0\|AP\|Standard\|OEM\|NoModem\| | [https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0\_ap\_standard\_oem\_nomodem.git](https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0_ap_standard_oem_nomodem.git) | qualcomm-linux-spf-2-0\_ap\_standard\_oem\_nomodem |
| Qualcomm\_Linux.SPF.2.0\|AP\|Standard\|OEM\|          | [https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0\_ap\_standard\_oem.git](https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0_ap_standard_oem.git)                  | qualcomm-linux-spf-2-0\_ap\_standard\_oem          |
| Qualcomm\_Linux.SPF.2.0\|AMSS\|Standard\|OEM\|        | [https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0\_amss\_standard\_oem.git](https://qpm-git.qualcomm.com/home2/git/qualcomm/qualcomm-linux-spf-2-0_amss_standard_oem.git)              | qualcomm-linux-spf-2-0\_amss\_standard\_oem        |

<Note>
  `Qualcomm_Linux.SPF.2.0|AP|Standard|OEM|` 和 `Qualcomm_Linux.SPF.2.0|AMSS|Standard|OEM|` 发行版仅在 QCS6490 芯片组上受支持。
</Note>

## 构建固件

* 为固件源码创建一个工作区目录并进入该目录。
  后续所有指令均假定该目录为工作目录。
  ```bash theme={null}
  mkdir -p <firmware-root>
  cd <firmware-root>
  ```

* 使用 [固件源码映射](#firmware-source-mapping) 表中的发布标签和克隆
  URL，从 Chipcode 克隆固件源码。
  ```bash theme={null}
  git clone -b <firmware-release-tag> --depth 1 <clone-url>
  ```

* 根据所选的访问配置文件，将以下命令中的 `<firwmare-root>` 和
  `<distro-clone-directory>` 替换为正确的值。

<Tabs>
  <Tab title="QCM6490/QCS5430">
    **前提条件**

    * 确保当前工作 shell 为 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入 bash
      shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件。
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境
      (TEE) 和 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm
      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm
      # LLVM requirement for boot compilation is 14.0.4
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.4 --path <firmware-root>/llvm/14.0.4
      chmod -R 777 <firmware-root>/llvm/14.0.4
      # LLVM requirement for the Qualcomm TEE compilation is 16.0.7
      qsc-cli tool install --name sdllvm_arm --required-version 16.0.7 --path <firmware-root>/llvm/16.0.7
      chmod -R 777 <firmware-root>/llvm/16.0.7
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>`
      是顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/QCM6490.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/QCM6490.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup> 处理器。将
      环境变量 HEXAGON\_ROOT 设置为 Hexagon SDK 的
      安装路径。要在使用 `qsc-cli` 时更改安装路径，请参阅
      [更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.4 --required-version 8.4.07
      qsc-cli tool extract --name hexagon8.4 --required-version 8.4.10
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 cDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.4.07
    * Python 版本：Python 3.10.2
    * libffi6 软件包

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/CDSP.HT.2.5.c3/cdsp_proc/build/ms
      ```

    * 清理构建：
      ```bash theme={null}
      python ./build_variant.py kodiak.cdsp.prod --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      python ./build_variant.py kodiak.cdsp.prod
      ```

    **构建 aDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.4.07
    * Python 版本：Python 3.10.2
    * libffi6 软件包

    **构建步骤**

    * Nanopb 集成（一次性设置）：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.5.c8/adsp_proc/qsh_api
      curl https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.5-linux-x86.tar.gz -o nanopb-0.3.9.5-linux-x86.tar.gz
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.5.c8/adsp_proc/
      python qsh_api/build/config_nanopb_dependency.py -f nanopb-0.3.9.5-linux-x86
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.5.c8/adsp_proc/build/ms
      ```

    * 清理构建：
      ```bash theme={null}
      python ./build_variant.py kodiak.adsp.prod --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      python ./build_variant.py kodiak.adsp.prod
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.4
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.4/
      ```
    * Python 版本：Python 3.10
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.1.0.c1/
      ```

    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```

    * 清理构建：
      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t kodiak,QcomToolsPkg -v LAA -r RELEASE --build_flags=cleanall
      ```

    * 构建镜像：

      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t kodiak,QcomToolsPkg -v LAA -r RELEASE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 Qualcomm TEE 固件**

    **所需工具**

    * 编译器版本：LLVM 16.0.7
    * Python 版本：Python 3.10

    **构建步骤**

    * 安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      vi build_config_deploy_kodiak.xml
      # Edit all the occurrences of /pkg/qct/software/llvm/release/arm/16.0.7/ to <firmware-root>/llvm/16.0.7/
      ```

    * 清理构建：
      ```bash theme={null}
      python build_all.py -b TZ.XF.5.0 CHIPSET=kodiak --cfg=build_config_deploy_kodiak.xml --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      python build_all.py -b TZ.XF.5.0 CHIPSET=kodiak --cfg=build_config_deploy_kodiak.xml
      ```

    **构建 AOP 固件**

    **所需工具**

    * 编译器版本：LLVM 14.0.4
    * Python 版本：Python 3.10

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.3.6/aop_proc/build/
      ```

    * 清理构建：
      ```bash theme={null}
      ./build_kodiak.sh -c -l <firmware-root>/llvm/14.0.4/
      ```

    * 构建镜像：
      ```bash theme={null}
      ./build_kodiak.sh -l <firmware-root>/llvm/14.0.4/
      ```

    **构建 MPSS**

    <Note>
      此步骤仅适用于 `Qualcomm_Linux.SPF.2.0|AMSS|Standard|OEM|`。
    </Note>

    **所需工具**

    * 编译器版本：Hexagon 8.4.10
    * Python 版本：Python 3.8.2

    **构建步骤**

    * Nanopb 集成（一次性设置）：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/MPSS.HI.4.3.3.c6.2/modem_proc/ssc_api
      curl https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.5-linux-x86.tar.gz -o nanopb-0.3.9.5-linux-x86.tar.gz
      cd <firmware-root>/<distro-clone-directory>/MPSS.HI.4.3.3.c6.2/modem_proc
      python ssc_api/build/config_nanopb_dependency.py -f  nanopb-0.3.9.5-linux-x86
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/MPSS.HI.4.3.3.c6.2/modem_proc/build/ms
      ```

    * 清理构建：
      ```bash theme={null}
      python build_variant.py kodiak.gen.prod --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      python build_variant.py kodiak.gen.prod bparams=-k
      ```

    **CPUCP 固件**

    Qualcomm 以二进制形式发布 CPUCP 固件，你无需编译
    该构建。

    **CPUSYS.VM 固件**

    Qualcomm 以二进制形式发布 CPUSYS.VM 固件，你无需
    编译该构建。

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需编译
    该构建。

    **生成固件预构建产物（boot 关键和拆分固件二进制文件）**

    <Note>
      此步骤仅适用于 `Qualcomm_Linux.SPF.2.0|AP|Standard|OEM|`。

      ```bash theme={null}
      rm -rf <firmware-root>/<distro-clone-directory>/QCM6490.LE.2.0/common/build/ufs/bin/*
      ```
    </Note>

    * 使用已编译的各个组件创建一个集成的固件
      二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/QCM6490.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在
      `<firmware-root>/<distro-clone-directory>/QCM6490.LE.2.0/common/build/ufs/bin`
      目录中生成了以下 zip 文件，则表示固件预构建成功：
      * `QCM6490_bootbinaries.zip`
      * `QCM6490_dspso.zip`
      * `QCM6490_fw.zip`
  </Tab>

  <Tab title="IQ-9075">
    **前提条件**

    * 确保当前工作 shell 为 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入
      bash shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件：
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境
      (TEE) 和 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm
      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm
      # LLVM requirement for boot compilation is 14.0.4
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.4 --path <firmware-root>/llvm/14.0.4
      chmod -R 777 <firmware-root>/llvm/14.0.4
      # LLVM requirement for the Qualcomm TEE compilation is 16.0.7
      qsc-cli tool install --name sdllvm_arm --required-version 16.0.7 --path <firmware-root>/llvm/16.0.7
      chmod -R 777 <firmware-root>/llvm/16.0.7
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>` 是
      顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/QCS9100.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/QCS9100.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup>。将环境变量 HEXAGON\_ROOT 设置为
      Hexagon SDK 的安装路径。要在使用
      `qsc-cli` 时更改安装路径，请参阅[更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.6 --required-version 8.6.05.2
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 DSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.05.2
    * Python 版本：Python 3.8.2

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC_PATH=/usr/bin
      ```

    * 安装依赖项：
      ```bash theme={null}
      pip install ruamel.yaml==0.17.17
      pip install dtschema==2021.10
      pip install jsonschema==4.0.0
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/DSP.AT.1.0.1/dsp_proc/build/ms
      ```

    * 清理构建：
      ```bash theme={null}
      python ./build_variant.py lemans.adsp.prod --clean
      python ./build_variant.py lemans.cdsp0.prod --clean
      python ./build_variant.py lemans.cdsp1.prod --clean
      python ./build_variant.py lemans.gpdsp0.prod --clean
      python ./build_variant.py lemans.gpdsp1.prod --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      python ./build_variant.py lemans.adsp.prod && python ./build_variant.py lemans.cdsp0.prod && python ./build_variant.py lemans.cdsp1.prod && python ./build_variant.py lemans.gpdsp0.prod && python ./build_variant.py lemans.gpdsp1.prod
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.4
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.4/
      ```
    * Python 版本：Python 3.10
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.1.0.c1/
      ```

    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```

    * 清理构建：
      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t lemans,QcomToolsPkg -v LAA -r RELEASE --build_flags=cleanall
      ```

    * 构建镜像：

      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t lemans,QcomToolsPkg -v LAA -r RELEASE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 Qualcomm TEE 固件**

    **所需工具**

    * 编译器版本：LLVM 16.0.7
    * Python 版本：Python 3.10

    **构建步骤**

    * 安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      vi build_config_deploy_lemans.xml
      # Edit all the occurrences of /pkg/qct/software/llvm/release/arm/16.0.7/ to <firmware-root>/llvm/16.0.7/
      ```

    * 清理构建：
      ```bash theme={null}
      python build_all.py -b TZ.XF.5.0 CHIPSET=lemans --cfg=build_config_deploy_lemans.xml --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      python build_all.py -b TZ.XF.5.0 CHIPSET=lemans --cfg=build_config_deploy_lemans.xml
      ```

    **构建 AOP 固件**

    **所需工具**

    * 编译器版本：LLVM 14.0.4
    * Python 版本：Python 3.10

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.3.6.1/aop_proc/build/
      ```

    * 清理构建：
      ```bash theme={null}
      ./build_lemansau.sh -c -l <firmware-root>/llvm/14.0.4/
      ```

    * 构建镜像：
      ```bash theme={null}
      ./build_lemansau.sh -l <firmware-root>/llvm/14.0.4/
      ```

    **CPUCP 固件**

    Qualcomm 以二进制形式发布 CPUCP 固件，你无需编译
    该构建。

    **CPUSYS.VM 固件**

    Qualcomm 以二进制形式发布 CPUSYS.VM 固件，你无需
    编译该构建。

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需编译
    该构建。

    **生成固件预构建产物（boot 关键和拆分固件二进制文件）**

    * 使用已编译的各个组件创建一个集成的固件
      二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/QCS9100.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在 `<firmware-root>/<distro-clone-directory>/QCS9100.LE.2.0/common/build/ufs/bin`
      目录中生成了以下 zip 文件，则表示固件预构建成功：
      * `QCS9100_bootbinaries.zip`
      * `QCS9100_dspso.zip`
      * `QCS9100_fw.zip`
  </Tab>

  <Tab title="IQ-8275">
    **前提条件**

    * 确保当前工作 shell 为 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入
      bash shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件。
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境
      (TEE) 和 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm
      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm
      # LLVM requirement for boot compilation is 14.0.4
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.4 --path <firmware-root>/llvm/14.0.4
      chmod -R 777 <firmware-root>/llvm/14.0.4
      # LLVM requirement for the Qualcomm TEE compilation is 16.0.7
      qsc-cli tool install --name sdllvm_arm --required-version 16.0.7 --path <firmware-root>/llvm/16.0.7
      chmod -R 777 <firmware-root>/llvm/16.0.7
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>` 是
      顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/QCS8300.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/QCS8300.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup>。将环境变量 HEXAGON\_ROOT 设置为
      Hexagon SDK 的安装路径。要在使用
      `qsc-cli` 时更改安装路径，请参阅[更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.6 --required-version 8.6.05.2
      qsc-cli tool extract --name hexagon8.7 --required-version 8.7.02.1
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 DSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.05.2 和 8.7.02.1
    * Python 版本：Python 3.8.2

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC_PATH=/usr/bin
      ```

    * 安装依赖项：
      ```bash theme={null}
      pip install ruamel.yaml==0.17.17
      pip install dtschema==2021.10
      pip install jsonschema==4.0.0
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/DSP.AT.1.0.1/dsp_proc/build/ms
      ```

    * 清理构建：
      ```bash theme={null}
      python ./build_variant.py lemans.adsp.prod --clean
      python ./build_variant.py monaco.cdsp0.prod --clean
      python ./build_variant.py lemans.gpdsp0.prod --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      python ./build_variant.py lemans.adsp.prod && python ./build_variant.py monaco.cdsp0.prod && python ./build_variant.py lemans.gpdsp0.prod
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.4
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.4/
      ```
    * Python 版本：Python 3.10
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.1.0.c1/
      ```

    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```

    * 清理构建：
      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t monaco,QcomToolsPkg -v LAA -r RELEASE --build_flags=cleanall
      ```

    * 构建镜像：

      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t monaco,QcomToolsPkg -v LAA -r RELEASE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 Qualcomm TEE 固件**

    **所需工具**

    * 编译器版本：LLVM 16.0.7
    * Python 版本：Python 3.10

    **构建步骤**

    * 安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      vi build_config_deploy_monaco.xml
      # Edit all the occurrences of /pkg/qct/software/llvm/release/arm/16.0.7/ to <firmware-root>/llvm/16.0.7/
      ```

    * 清理构建：
      ```bash theme={null}
      python build_all.py -b TZ.XF.5.0 CHIPSET=monaco --cfg=build_config_deploy_monaco.xml --clean
      ```

    * 构建镜像：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      python build_all.py -b TZ.XF.5.0 CHIPSET=monaco --cfg=build_config_deploy_monaco.xml
      ```

    **构建 AOP 固件**

    **所需工具**

    * 编译器版本：LLVM 14.0.4
    * Python 版本：Python 3.10

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.3.6.1/aop_proc/build/
      ```

    * 清理构建：
      ```bash theme={null}
      ./build_monaco.sh -c -l <firmware-root>/llvm/14.0.4/
      ```

    * 构建镜像：
      ```bash theme={null}
      ./build_monaco.sh -l <firmware-root>/llvm/14.0.4/
      ```

    **CPUCP 固件**

    Qualcomm 以二进制形式发布 CPUCP 固件，你无需编译
    该构建。

    **CPUSYS.VM 固件**

    Qualcomm 以二进制形式发布 CPUSYS.VM 固件，你无需
    编译该构建。

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需编译
    该构建。

    **生成固件预构建产物（boot 关键和拆分固件二进制文件）**

    * 使用已编译的各个组件创建一个集成的固件
      二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/QCS8300.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在 `<firmware-root>/<distro-clone-directory>/QCS8300.LE.2.0/common/build/ufs/bin`
      目录中生成了以下 zip 文件，则表示固件预构建成功：
      * `QCS8300_bootbinaries.zip`
      * `QCS8300_dspso.zip`
      * `QCS8300_fw.zip`
  </Tab>

  <Tab title="IQ-615">
    **先决条件**

    * 确保当前使用的 shell 是 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入
      bash shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件。
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 安装 Python 2.7.18：
      ```bash theme={null}
      wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
      tar -xvf Python-2.7.18.tgz
      cd Python-2.7.18
      ./configure
      make
      sudo make install
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境（TEE）以及 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm
      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm
      # LLVM requirement for AOP is 3.9.3
      mkdir -p /pkg/qct/software/llvm
      qsc-cli tool install --name sdllvm_arm --required-version 3.9.3 --path /pkg/qct/software/llvm/release/arm/3.9.3
      chmod -R 777 /pkg/qct/software/llvm/release/arm/3.9.3
      # LLVM requirement for boot compilation is 14.0.4
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.4 --path <firmware-root>/llvm/14.0.4
      chmod -R 777 <firmware-root>/llvm/14.0.4
      # LLVM requirement for Qualcomm TrustZone compilation is 16.0.7
      qsc-cli tool install --name sdllvm_arm --required-version 16.0.7 --path <firmware-root>/llvm/16.0.7
      chmod -R 777 <firmware-root>/llvm/16.0.7
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>` 为顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/QCS615.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/QCS615.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup>。将环境变量 `HEXAGON_ROOT`` 设置为
      Hexagon SDK 的安装路径。若要在使用
      `qsc-cli\` 时更改安装路径，请参阅[更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.2 --required-version 8.2.05.1
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 cDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.2.05
    * Python 版本：Python 2.7.18
    * libffi6 软件包

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/CDSP.VT.2.2.c4
      ```

    * 清理构建：
      ```bash theme={null}
      python cdsp_proc/build/build.py -c sm6150 -o clean -f CDSP
      ```

    * 构建镜像：
      ```bash theme={null}
      python cdsp_proc/build/build.py -c sm6150 -o all -f CDSP
      ```

    **构建 aDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.2.05
    * Python 版本：Python 2.7.18
    * libffi6 软件包

    **构建步骤**

    * Nanopb 集成（一次性设置）：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.VT.5.2.c6/adsp_proc/ssc_api
      curl https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.5-linux-x86.tar.gz -o nanopb-0.3.9.5-linux-x86.tar.gz
      cd <firmware-root>/<distro-clone-directory>/ADSP.VT.5.2.c6/adsp_proc/
      python ssc_api/build/config_nanopb_dependency.py -f nanopb-0.3.9.5-linux-x86
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.VT.5.2.c6
      ```

    * 清理构建：
      ```bash theme={null}
      python adsp_proc/build/build.py -c sm6150 -o clean -f ADSP
      ```

    * 构建镜像：
      ```bash theme={null}
      python adsp_proc/build/build.py -c sm6150 -o all -f ADSP
      ```

    **构建 AOP**

    **所需工具**

    * 编译器版本：LLVM 3.9.3
    * Python 版本：Python 2.7.18

    **构建步骤**

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.3.6.2/aop_proc/build/
      ```

    * 清理构建：
      ```bash theme={null}
      ./build_TalosAU.sh -c
      ```

    * 构建镜像：
      ```bash theme={null}
      ./build_TalosAU.sh
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.4
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.4/
      ```
          <Note>
            为避免构建错误，请确保命令末尾带有 /
          </Note>

    * Python 版本：Python 3.10

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```

    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.1.0.c1/
      ```

    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```

    * 清理构建：
      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t talos,QcomToolsPkg -v LAA -r RELEASE --build_flags=cleanall
      ```

    * 构建镜像：

      ```bash theme={null}
      python -u boot_images/boot_tools/buildex.py -t talos,QcomToolsPkg -v LAA -r RELEASE
      ```

          <Note>
            对于 debug 变体构建，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 TrustZone**

    **所需工具**

    * 编译器版本：LLVM 16.0.7
    * Python 版本：Python 3.10

    **构建步骤**

    * 安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      vi build_config_deploy_talos.xml
      # Edit all the occurrences of /pkg/qct/software/llvm/release/arm/16.0.7/ to <firmware-root>/llvm/16.0.7/
      ```
    * 清理构建：
      ```bash theme={null}
      python build_all.py -b TZ.XF.5.0 CHIPSET=talos --cfg=build_config_deploy_talos.xml --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.29.1/trustzone_images/build/ms/
      python build_all.py -b TZ.XF.5.0 CHIPSET=talos --cfg=build_config_deploy_talos.xml
      ```

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需自行编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需自行编译
    该构建。

    **生成固件预构建产物（boot-critical 和 split-firmware 二进制文件）**

    * 使用你编译好的各个组件创建一个集成的固件二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/QCS615.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在 `<firmware-root>/<distro-clone-directory>/QCS615.LE.2.0/common/build/common/bin`
      目录中生成了以下 zip 文件，则说明固件预构建成功：
      * `QCS615_bootbinaries.zip`
      * `QCS615_dspso.zip`
      * `QCS615_fw.zip`
  </Tab>

  <Tab title="IQ-X7181">
    **前提条件**

    * 确保当前工作 shell 为 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入
      bash shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件。
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境
      (TEE) 和 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm

      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm

      # LLVM requirement for aDSP is 14.0.1
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.1 --path <firmware-root>/llvm/14.0.1
      chmod -R 777 <firmware-root>/llvm/14.0.1

      # LLVM requirement for the AOP is 14.0.0
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.0 --path <firmware-root>/llvm/14.0.0
      chmod -R 777 <firmware-root>/llvm/14.0.0

      # LLVM requirement for BOOT compilation is 16.0.2
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.0 --path <firmware-root>/llvm/16.0.2
      chmod -R 777 <firmware-root>/llvm/16.0.2

      # LLVM requirement for BOOT_UEFI and Qualcomm TEE (TZ_XF) compilation is 18.0.1
      qsc-cli tool install --name sdllvm_arm --required-version 18.0.1 --path <firmware-root>/llvm/18.0.1
      chmod -R 777 <firmware-root>/llvm/18.0.1
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>` 是顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup> 处理器。将
      环境变量 HEXAGON\_ROOT 设置为 Hexagon SDK 的
      安装路径。要在使用
      `qsc-cli` 时更改安装路径，请参阅[更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.4 --required-version 8.6.06
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 aDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.06
    * Python 版本：Python 3.8.2
    * libffi6 软件包

    **构建步骤**

    * 检查 Hexagon 目录：
      ```bash theme={null}
      export HEXAGON_ROOT=$HOME/QUalcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```
    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * Nanopb 集成（一次性设置）：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/qsh_api
      curl https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.5-linux-x86.tar.gz -o nanopb-0.3.9.5-linux-x86.tar.gz
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/
      python qsh_api/build/config_nanopb_dependency.py -f nanopb-0.3.9.5-linux-x86
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.adsp.prod --clean && python3 ./build_variant.py hamoa.adsp.charger --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.adsp.prod && python3 ./build_variant.py hamoa.adsp.charger
      ```

    **构建 cDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.06
    * Python 版本：Python 3.8.2
    * libffi6 软件包

    **构建步骤**

    * 检查 Hexagon 目录：
      ```bash theme={null}
      export HEXAGON_ROOT=$HOME/QUalcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```
    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/CDSP.HT.2.9.c1/cdsp_proc/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.cdsp.prod --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.cdsp.prod
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 16.0.2
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/16.0.2/
      ```
    * Python 版本：Python 3.10.6
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.2.4.2/
      ```
    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```
    * 清理构建：
      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE --build_flags=cleanall
      ```
    * 构建镜像：

      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 BOOT\_UEFI**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 18.0.1
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/18.0.1/
      ```
    * Python 版本：Python 3.10.6
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF_UEFI.2.5/
      ```
    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```
    * 清理构建：
      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE --build_flags=cleanall
      ```
    * 构建镜像：

      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 Qualcomm TEE 固件**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 18.0.1
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/18.0.1/
      ```
    * Python 版本：Python 3.10

    **构建步骤**

    * 导出 `SECTOOLS` 变量：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/ext/Linux
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.0/trustzone_images/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 build_all.py -b TZ.XF.5.0 CHIPSET=hamoa --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 build_all.py -b TZ.XF.5.0 CHIPSET=hamoa
      ```

    **构建 AOP 固件**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.0
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.0/
      ```
    * Python 版本：Python 3.10

    **构建步骤**

    * 导出 `SECTOOLS` 变量：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/ext/Linux
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.5.2/
      ```
    * 构建镜像：
      ```bash theme={null}
      ./aop_proc/build/build_hamoa.sh
      ```

    **CPUCP 固件**

    Qualcomm 以二进制形式发布 CPUCP 固件，你无需编译
    该构建。

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需编译
    该构建。

    **生成固件预构建产物（boot 关键和拆分固件二进制文件）**

    * 使用已编译的各个组件创建一个集成的固件
      二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在 `<firmware-root>/<distro-clone-directory>/Hamoa_IOT.LE.2.0/common/build/ufs/bin`
      目录中生成了以下 zip 文件，则表示固件预构建成功：
      * `HAMOA_bootbinaries.zip`
      * `HAMOA_fw.zip`
  </Tab>

  <Tab title="IQ-X5121">
    **前提条件**

    * 确保当前工作 shell 为 `bash`：

      ```bash theme={null}
      echo $0
      ```

      该命令的预期输出应为 `bash`。如果不是，请进入
      bash shell。

      ```bash theme={null}
      bash
      ```

    * 使用以下命令安装 libffi6 软件包。QAIC 编译器需要该软件包，
      它用于从 IDL 文件生成头文件和源文件。
      ```bash theme={null}
      curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
      sudo dpkg -i libffi6_3.2.1-8_amd64.deb
      ```

    * 为 AOP、Qualcomm<sup>®</sup> 可信执行环境
      (TEE) 和 boot 编译安装 LLVM：
      ```bash theme={null}
      cd <firmware-root>
      mkdir llvm

      # Sign in to qsc-cli and activate the license
      qsc-cli login
      qsc-cli tool activate-license --name sdllvm_arm

      # LLVM requirement for aDSP is 14.0.1
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.1 --path <firmware-root>/llvm/14.0.1
      chmod -R 777 <firmware-root>/llvm/14.0.1

      # LLVM requirement for the AOP is 14.0.0
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.0 --path <firmware-root>/llvm/14.0.0
      chmod -R 777 <firmware-root>/llvm/14.0.0

      # LLVM requirement for BOOT compilation is 16.0.2
      qsc-cli tool install --name sdllvm_arm --required-version 14.0.0 --path <firmware-root>/llvm/16.0.2
      chmod -R 777 <firmware-root>/llvm/16.0.2

      # LLVM requirement for BOOT_UEFI and Qualcomm TEE (TZ_XF) compilation is 18.0.1
      qsc-cli tool install --name sdllvm_arm --required-version 18.0.1 --path <firmware-root>/llvm/18.0.1
      chmod -R 777 <firmware-root>/llvm/18.0.1
      ```

    * 导出 `SECTOOLS` 变量并编译固件构建
      （`<firmware-root>/<distro-clone-directory>` 是顶层目录）：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Purwa_IOT.LE.2.0/common/sectoolsv2/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Purwa_IOT.LE.2.0/common/sectoolsv2/ext/Linux
      ```

    * 安装并设置 Qualcomm<sup>®</sup> Hexagon<sup>™</sup> 处理器。将
      环境变量 HEXAGON\_ROOT 设置为 Hexagon SDK 的
      安装路径。要在使用
      `qsc-cli` 时更改安装路径，请参阅[更改 Hexagon 工具安装路径](/zh/Key-Documents/Firmware-Guide/how-to-change-hexagon-install-path)。
      ```bash theme={null}
      qsc-cli tool extract --name hexagon8.4 --required-version 8.6.06
      export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```

    **构建 aDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.06
    * Python 版本：Python 3.8.2
    * libffi6 软件包

    **构建步骤**

    * 检查 Hexagon 目录：
      ```bash theme={null}
      export HEXAGON_ROOT=$HOME/QUalcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```
    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * Nanopb 集成（一次性设置）：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/qsh_api
      curl https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.5-linux-x86.tar.gz -o nanopb-0.3.9.5-linux-x86.tar.gz
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/
      python qsh_api/build/config_nanopb_dependency.py -f nanopb-0.3.9.5-linux-x86
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/ADSP.HT.5.9/adsp_proc/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.adsp.prod --clean && python3 ./build_variant.py hamoa.adsp.charger --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.adsp.prod && python3 ./build_variant.py hamoa.adsp.charger
      ```

    **构建 cDSP**

    **所需工具**

    * 编译器版本：Hexagon 8.6.06
    * Python 版本：Python 3.8.2
    * libffi6 软件包

    **构建步骤**

    * 检查 Hexagon 目录：
      ```bash theme={null}
      export HEXAGON_ROOT=$HOME/QUalcomm/HEXAGON_Tools
      echo $HEXAGON_ROOT
      ```
    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/CDSP.HT.2.9.c1/cdsp_proc/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.cdsp.prod --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 ./build_variant.py hamoa.cdsp.prod
      ```

    **构建 Boot**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 16.0.2
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/16.0.2/
      ```
    * Python 版本：Python 3.10.6
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF.2.4.2/
      ```
    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```
    * 清理构建：
      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE --build_flags=cleanall
      ```
    * 构建镜像：

      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 BOOT\_UEFI**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 18.0.1
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/18.0.1/
      ```
    * Python 版本：Python 3.10.6
    * libffi6 软件包

    **构建步骤**

    * 安装设备树编译器：
      ```bash theme={null}
      sudo apt-get install device-tree-compiler
      export DTC=/usr/bin
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/BOOT.MXF_UEFI.2.5/
      ```
    * 安装依赖项：
      ```bash theme={null}
      python -m pip install -r boot_images/boot_tools/dtschema_tools/oss/requirements.txt
      pip install json-schema-for-humans
      ```
    * 清理构建：
      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE --build_flags=cleanall
      ```
    * 构建镜像：

      ```bash theme={null}
      python3 boot_images/boot_tools/buildex.py -t Hamoa,QcomToolsPkg -r RELEASE -v LE
      ```

          <Note>
            如需构建 debug 变体，请将 `RELEASE` 替换为 `DEBUG`。
          </Note>

    **构建 Qualcomm TEE 固件**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 18.0.1
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/18.0.1/
      ```
    * Python 版本：Python 3.10

    **构建步骤**

    * 导出 `SECTOOLS` 变量：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/ext/Linux
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/TZ.XF.5.0/trustzone_images/build/ms
      ```
    * 清理构建：
      ```bash theme={null}
      python3 build_all.py -b TZ.XF.5.0 CHIPSET=hamoa --clean
      ```
    * 构建镜像：
      ```bash theme={null}
      python3 build_all.py -b TZ.XF.5.0 CHIPSET=hamoa
      ```

    **构建 AOP 固件**

    **所需工具**

    * 编译器版本：LLVM 版本必须更新到 14.0.0
      ```bash theme={null}
      export LLVM=<firmware-root>/llvm/14.0.0/
      ```
    * Python 版本：Python 3.10

    **构建步骤**

    * 导出 `SECTOOLS` 变量：
      ```bash theme={null}
      export SECTOOLS=<firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/ext/Linux/sectools
      export SECTOOLS_DIR=<firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/ext/Linux
      ```
    * 进入以下目录：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/AOP.HO.5.2/
      ```
    * 构建镜像：
      ```bash theme={null}
      ./aop_proc/build/build_hamoa.sh
      ```

    **CPUCP 固件**

    Qualcomm 以二进制形式发布 CPUCP 固件，你无需编译
    该构建。

    **BTFM 固件**

    Qualcomm 以二进制形式发布 BTFM 固件，你无需编译
    该构建。

    **WLAN 固件**

    Qualcomm 以二进制形式发布 WLAN 固件，你无需编译
    该构建。

    **生成固件预构建产物（boot 关键和拆分固件二进制文件）**

    * 使用已编译的各个组件创建一个集成的固件
      二进制文件：
      ```bash theme={null}
      cd <firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/common/build
      python build.py --imf
      ```

    * 如果在 `<firmware-root>/<distro-clone-directory>/Purwa.LE.2.0/common/build/ufs/bin`
      目录中生成了以下 zip 文件，则表示固件预构建成功：
      * `HAMOA_bootbinaries.zip`
      * `HAMOA_fw.zip`
  </Tab>
</Tabs>

## 构建 BSP 镜像

本节介绍如何使用 meta-qcom-extras 层将固件二进制文件和其他源代码
组件集成到完整的 BSP 镜像中。BSP 镜像构建将上一步编译的固件与
Yocto 层栈相结合，生成包含所有所需二进制文件的可刷写镜像。

* 下载 Qualcomm 的 Yocto 层 `meta-qcom-extras`。有关最新的 `<meta-qcom-extras-release-tag>`，请参阅[配置参数](#configuration-parameters)。

  ```bash theme={null}
  git clone https://qpm-git.qualcomm.com/home2/git/component-revision-history/qualcomm-linux/meta-qcom-extras.git -b <meta-qcom-extras-release-tag> --depth 1
  ```

**层设置**

* 导出 `NETRC_FILE` 参数，确保 `~/.netrc` 凭据在 `kas` 环境中可见：
  ```bash theme={null}
  export NETRC_FILE=~/.netrc
  ```

* 将 CUST\_ID 值设置为 "213195"，用于 meta-qcom-extras 的编译。
  ```bash theme={null}
  export CUST_ID="213195"
  ```

* 设置该层的对外（outbound）许可证及其校验和。该层中的每个配方都需要 `CUST_LICENSE` 和 `CUST_LIC_CHKSUM`。
  * 客户必须在配方中指定合适的对外许可证，才能构建专有源码。
  * 客户应咨询自己的法律团队，以获取有关对外许可决策的指导。
  * 所选的对外许可证必须与 PKLA 兼容。
  ```bash theme={null}
  export CUST_LICENSE="<CUST_LICENSE>"
  export CUST_LIC_CHKSUM="<CUST_LIC_CHKSUM>"
  ```

* 以下值与源码仓库中已有的占位 LICENSE 文件相匹配。可将它们用于内部构建和评估，无需替换任何许可证文件。
  **请勿将这些值用于生产构建。任何部署都应定义你自己的许可证值。**

  | 变量                | 值                                  |
  | ----------------- | ---------------------------------- |
  | `CUST_LICENSE`    | `LICENSE.qcom-2`                   |
  | `CUST_LIC_CHKSUM` | `165287851294f2fb8ac8cbc5e24b02b0` |

* 构建前请更新源码仓库中的许可证文件。`meta-qcom-extras` 使用的所有源码默认都包含一个占位 LICENSE 文件。配方会在构建时根据该文件验证 `CUST_LICENSE`，因此必须将其替换为你选择的对外许可证。

  上游仓库无法直接修改。请将每个仓库镜像到你自己拥有的本地或远程服务器上，替换占位 LICENSE 文件，然后更新受影响配方中的 `SRC_URI` 变量，使其指向新的 URI。

<Note>
  上述同步和层设置步骤适用于所有开发板。但是，
  meta-qcom-extras 尚未为在 IQ-X7181 和 IQ-X5121 上加载自定义
  固件二进制文件提供现成的配方（recipe）；请改用 `devtool` 修改
  上游配方，如下方"IQ-X7181"和"IQ-X5121"标签页所示。
</Note>

<Tabs>
  <Tab title="IQ-X7181">
    **固件设置**

    * 将 `FWZIP_PATH` 设置为包含固件 ZIP 文件的目录，以便在构建中包含本地编译的固件 zip 路径。
      ```bash theme={null}
      export FWZIP_PATH="<FWZIP_PATH>"
      ```

    * **覆盖 Linux-firmware 二进制文件**

      如果您想修改 Linux 固件二进制文件，请使用本节将它们替换到构建中。

      * 在 `meta-qcom-extras/ci/firmware.yml` 创建一个包含以下内容的 kas 配置文件：

        ```bash theme={null}
        cat << EOF > meta-qcom-extras/ci/firmware.yml
        header:
         version: 14

        local_conf_header:
         firmware-build: |
           SRCREV:pn-linux-firmware = "dc85ccedc9c973682fbcf4d628ca61174bcc3120"
        EOF
        ```

      * 然后使用 `devtool` 修改 linux-firmware recipe：

        ```bash theme={null}
        kas shell -c "devtool modify linux-firmware" meta-qcom-extras/ci/iq-x7181-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml:meta-qcom-extras/ci/firmware.yml
        ```

      * 解压固件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_fw.zip -d $FWZIP_PATH
        ```

      * 将固件 zip 文件的内容复制到 devtool 工作区

        ```bash theme={null}
        cp $FWZIP_PATH/HAMOA_fw/lib/firmware/qcom/x1e80100/*.{mbn,jsn} build/workspace/sources/linux-firmware/qcom/x1e80100/
        ```

            <Note>
              当您覆盖 `linux-firmware` 中的固件时，还必须同时覆盖 Hexagon DSP 二进制文件。
            </Note>

    * **覆盖 DSPSO 二进制文件**

      如果您想修改 Hexagon DSP 共享对象二进制文件，请使用本节将 ADSP 和 CDSP 二进制文件替换到构建中。

      * 为 `hexagon-dsp-binaries` 初始化一个 devtool 工作区：

        ```bash theme={null}
        kas shell -c "devtool modify hexagon-dsp-binaries" meta-qcom-extras/ci/iq-x7181-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
        ```

      * 解压固件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_fw.zip -d $FWZIP_PATH
        ```

      * 将 ADSP 二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_fw/usr/share/qcom/x1e80100/Qualcomm/X1E80100/dsp/adsp/* build/workspace/sources/hexagon-dsp-binaries/x1e80100/Qualcomm/Hamoa-IoT-EVK/ADSP.HT.5.9-00839-HAMOA-1/
        ```

      * 将 CDSP 二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_fw/usr/share/qcom/x1e80100/Qualcomm/X1E80100/dsp/cdsp/* build/workspace/sources/hexagon-dsp-binaries/x1e80100/Qualcomm/Hamoa-IoT-EVK/CDSP.HT.2.9.c1-00069-HAMOA-1/
        ```

    * **覆盖启动固件二进制文件**

      如果您想修改启动关键固件二进制文件，请使用本节将它们替换到构建中。

      * 为启动固件 recipe 初始化一个 devtool 工作区：

        ```bash theme={null}
        kas shell -c "devtool modify firmware-qcom-boot-iq-x7181" meta-qcom-extras/ci/iq-x7181-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
        ```

      * 解压启动二进制文件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_bootbinaries.zip -d $FWZIP_PATH
        ```

      * 将启动二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_bootbinaries/* build/workspace/sources/firmware-qcom-boot-iq-x7181
        ```

        然后将所需的配置追加到 `.bbappend` 文件：

        ```bash theme={null}
        echo 'ALLOW_EMPTY:${PN} = "1"' >> build/workspace/appends/firmware-qcom-boot-iq-x7181_00012.bbappend
        ```

    所有覆盖步骤完成后，后续的 Yocto 镜像构建将自动使用本地提供的固件二进制文件，而不是上游来源。

    **构建镜像**

    * 运行安装脚本，将这些参数应用到构建环境。

      ```bash theme={null}
      meta-qcom-extras/setup_extras_config.sh
      ```

    * 使用 `kas` 构建软件镜像。您可以基于机器和发行版组合定义构建目标。

      ```bash theme={null}
      kas shell -c "devtool build-image qcom-multimedia-proprietary-image" meta-qcom-extras/ci/iq-x7181-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
      ```
  </Tab>

  <Tab title="IQ-X5121">
    **固件设置**

    * 将 `FWZIP_PATH` 设置为包含固件 ZIP 文件的目录，以便在构建中包含本地编译的固件 zip 路径。
      ```bash theme={null}
      export FWZIP_PATH="<FWZIP_PATH>"
      ```

    * **覆盖 Linux-firmware 二进制文件**

      如果您想修改 Linux 固件二进制文件，请使用本节将它们替换到构建中。

      * 在 `meta-qcom-extras/ci/firmware.yml` 创建一个包含以下内容的 kas 配置文件：

        ```bash theme={null}
        cat << EOF > meta-qcom-extras/ci/firmware.yml
        header:
         version: 14

        local_conf_header:
         firmware-build: |
           SRCREV:pn-linux-firmware = "dc85ccedc9c973682fbcf4d628ca61174bcc3120"
        EOF
        ```

      * 然后使用 `devtool` 修改 linux-firmware recipe：

        ```bash theme={null}
        kas shell -c "devtool modify linux-firmware" meta-qcom-extras/ci/iq-x5121-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml:meta-qcom-extras/ci/firmware.yml
        ```

      * 解压固件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_fw.zip -d $FWZIP_PATH
        ```

      * 将固件 zip 文件的内容复制到 devtool 工作区

        ```bash theme={null}
        cp $FWZIP_PATH/HAMOA_fw/lib/firmware/qcom/x1e80100/*.{mbn,jsn} build/workspace/sources/linux-firmware/qcom/x1e80100/
        ```

            <Note>
              当您覆盖 `linux-firmware` 中的固件时，还必须同时覆盖 Hexagon DSP 二进制文件。
            </Note>

    * **覆盖 DSPSO 二进制文件**

      如果您想修改 Hexagon DSP 共享对象二进制文件，请使用本节将 ADSP 和 CDSP 二进制文件替换到构建中。

      * 为 `hexagon-dsp-binaries` 初始化一个 devtool 工作区：

        ```bash theme={null}
        kas shell -c "devtool modify hexagon-dsp-binaries" meta-qcom-extras/ci/iq-x5121-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
        ```

      * 解压固件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_fw.zip -d $FWZIP_PATH
        ```

      * 将 ADSP 二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_fw/usr/share/qcom/x1e80100/Qualcomm/X1E80100/dsp/adsp/* build/workspace/sources/hexagon-dsp-binaries/x1e80100/Qualcomm/Hamoa-IoT-EVK/ADSP.HT.5.9-00839-HAMOA-1/
        ```

      * 将 CDSP 二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_fw/usr/share/qcom/x1e80100/Qualcomm/X1E80100/dsp/cdsp/* build/workspace/sources/hexagon-dsp-binaries/x1e80100/Qualcomm/Hamoa-IoT-EVK/CDSP.HT.2.9.c1-00069-HAMOA-1/
        ```

    * **覆盖启动固件二进制文件**

      如果您想修改启动关键固件二进制文件，请使用本节将它们替换到构建中。

      * 为启动固件 recipe 初始化一个 devtool 工作区：

        ```bash theme={null}
        kas shell -c "devtool modify firmware-qcom-boot-iq-x7181" meta-qcom-extras/ci/iq-x5121-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
        ```

      * 解压启动二进制文件压缩包：

        ```bash theme={null}
        unzip $FWZIP_PATH/HAMOA_bootbinaries.zip -d $FWZIP_PATH
        ```

      * 将启动二进制文件复制到 devtool 工作区：

        ```bash theme={null}
        cp -r $FWZIP_PATH/HAMOA_bootbinaries/* build/workspace/sources/firmware-qcom-boot-iq-x7181
        ```

        然后将所需的配置追加到 `.bbappend` 文件：

        ```bash theme={null}
        echo 'ALLOW_EMPTY:${PN} = "1"' >> build/workspace/appends/firmware-qcom-boot-iq-x7181_00012.bbappend
        ```

    所有覆盖步骤完成后，后续的 Yocto 镜像构建将自动使用本地提供的固件二进制文件，而不是上游来源。

    **构建镜像**

    * 运行安装脚本，将这些参数应用到构建环境。

      ```bash theme={null}
      meta-qcom-extras/setup_extras_config.sh
      ```

    * 使用 `kas` 构建软件镜像。您可以基于机器和发行版组合定义构建目标。

      ```bash theme={null}
      kas shell -c "devtool build-image qcom-multimedia-proprietary-image" meta-qcom-extras/ci/iq-x5121-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
      ```
  </Tab>

  <Tab title="其他套件">
    **固件设置**

    * 将 `FWZIP_PATH` 设置为包含固件 ZIP 文件的目录，以便在构建中包含本地编译的固件 zip 路径。
      ```bash theme={null}
      export FWZIP_PATH="<FWZIP_PATH>"
      ```

    * 设置调制解调器（modem）专用许可证及其校验和。`CUST_MDM_LICENSE` 和
      `CUST_MDM_LIC_CHKSUM` 仅在构建调制解调器固件时需要。
      ```bash theme={null}
      export CUST_MDM_LICENSE="<CUST_MDM_LICENSE>"
      export CUST_MDM_LIC_CHKSUM="<CUST_MDM_LIC_CHKSUM>"
      ```

    * 以下值与源码仓库中已有的占位 LICENSE 文件相匹配。可将其用于内部构建和评估，
      而无需替换任何许可证文件。
      **请勿将这些值用于生产构建。任何部署都应定义您自己的许可证值。**

      | 变量                    | 值                                  |
      | --------------------- | ---------------------------------- |
      | `CUST_MDM_LICENSE`    | `Modemreadme.txt`                  |
      | `CUST_MDM_LIC_CHKSUM` | `bcd23be15c15909fe9de30ec32af0f89` |

    * `firmware-qcom-selective.inc` 在解析时应用以下规则：

      * 如果 `FWZIP_PATH` 或 `FWZIP_NAME` 未设置，则会静默跳过该 recipe。
      * 如果两者都已设置但 ZIP 文件缺失，构建会以致命错误失败。
      * 如果没有 `PREFERRED_RPROVIDER` 指向该 recipe，则会静默跳过该 recipe。

    * 编辑 `meta-qcom-extras/ci/providers.yml`，添加所需的 `FWZIP_NAME`
      赋值，以便在镜像编译期间启用该 recipe。

          <CodeGroup>
            ```yaml IQ-9075 theme={null}
            firmware-qcs9100: |
              FWZIP_NAME:pn-firmware-qcs9100 = "QCS9100_dsp"
            firmware-qcs9100-bootbins: |
              FWZIP_NAME:pn-firmware-qcs9100-bootbins = "QCS9100_bootbinaries"
            ```

            ```yaml IQ-8275 theme={null}
            firmware-qcs8300: |
              FWZIP_NAME:pn-firmware-qcs8300 = "QCS8300_dsp"
            firmware-qcs8300-bootbins: |
              FWZIP_NAME:pn-firmware-qcs8300-bootbins = "QCS8300_bootbinaries"
            ```

            ```yaml QCS6490 theme={null}
            firmware-qcs6490-adsp: |
              FWZIP_NAME:pn-firmware-qcs6490-adsp = "QCM6490_adsp"
            firmware-qcs6490-cdsp: |
              FWZIP_NAME:pn-firmware-qcs6490-cdsp = "QCM6490_cdsp"
            firmware-qcs6490-modem: |
              FWZIP_NAME:pn-firmware-qcs6490-modem = "QCM6490_modem"
            firmware-qcs6490-bootbins: |
              FWZIP_NAME:pn-firmware-qcs6490-bootbins = "QCM6490_bootbinaries"
            ```

            ```yaml IQ-615-EVK theme={null}
            firmware-qcs615-adsp: |
              FWZIP_NAME:pn-firmware-qcs615-adsp = "QCS615_adsp"
            firmware-qcs615-cdsp: |
              FWZIP_NAME:pn-firmware-qcs615-cdsp = "QCS615_cdsp"
            firmware-qcs615-bootbins: |
              FWZIP_NAME:pn-firmware-qcs615-bootbins = "QCS615_bootbinaries"
            ```
          </CodeGroup>

    * 在构建之前，请更新固件 ZIP 中的许可证文件。
      `meta-qcom-extras` 使用的所有 ZIP 默认都包含一个占位 LICENSE
      文件。recipe 会在构建时根据此文件校验 `CUST_LICENSE`，
      因此必须将其替换为您选择的对外许可证。

    **构建镜像**

    * 运行安装脚本，将这些参数应用到构建环境。

      ```bash theme={null}
      meta-qcom-extras/setup_extras_config.sh
      ```

    * 使用 `kas` 构建软件镜像。您可以基于机器和发行版组合定义构建目标。

          <CodeGroup>
            ```bash IQ-9075-EVK theme={null}
            kas build meta-qcom-extras/ci/iq-9075-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
            ```

            ```bash IQ-8275-EVK theme={null}
            kas build meta-qcom-extras/ci/iq-8275-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
            ```

            ```bash IQ-615-EVK theme={null}
            kas build meta-qcom-extras/ci/iq-615-evk.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
            ```

            ```bash QCS6490 theme={null}
            kas build meta-qcom-extras/ci/rb3gen2-core-kit.yml:meta-qcom-extras/ci/qcom-distro.yml:meta-qcom-extras/ci/performance.yml
            ```
          </CodeGroup>
  </Tab>
</Tabs>

## 相关主题

* [如何更改 Hexagon 的默认安装路径？](./how-to-change-hexagon-install-path)
