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

# 使用 GitHub 工作流构建

export const QLI_TAG = 'qli-2.1';

按照详细说明同步 Qualcomm Yocto 和 QIR SDK 层，并构建 robotics 镜像（在 Dragonwing<sup>TM</sup> 设备上运行）以及 QIR SDK 制品（在主机计算机上用于开发和交叉编译）。

<Warning>
  **警告**

  不建议重新构建 QIR SDK，因为构建过程对非专业人员而言较为复杂。仅当你了解该过程并有以下需求时，才应构建 QIR SDK：

  * 为没有预构建镜像的设备构建镜像。
  * 为 QIR SDK 添加新功能。
  * 更改目标镜像的内容。
  * 修复 QIR SDK 的缺陷。
  * 优化 QIR SDK 的性能。
  * 更改某些组件的版本。
</Warning>

1. [为构建设置主机计算机](#set-up-the-host-computer-for-build)
2. [构建 robotics 镜像](#build-the-robotics-image)
3. [生成 QIR SDK 制品](#generate-qir-sdk-artifacts)
4. [将 robotics 镜像刷写到设备](#flash-the-robotics-image-to-devices)

## 为构建设置主机计算机

准备用于构建和安装操作的主机计算机，确保其满足 [主机计算机要求](./build-the-qir-sdk#host-computer-requirements)。

1. 安装所需的软件包。
   ```shell 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 gfortran
   ```
2. 设置语言环境。
   ```shell theme={null}
   sudo locale-gen en_US.UTF-8
   sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
   export LC_ALL=en_US.UTF-8
   export LANG=en_US.UTF-8
   ```
3. 更新 git 配置。
   ```shell theme={null}
   # Check if your identity is configured in .gitconfig
   git config --get user.email
   git config --get user.name
   # Run the following commands if you do not have your account identity set in .gitconfig
   git config --global user.email <Your email ID>
   git config --global user.name <"Your Name">
   # Add the following UI color option for output of console (optional)
   git config --global color.ui auto
   # 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
   ```
4. 将 `/bin/sh` 符号链接更改为默认指向 `/bin/bash`。
   ```shell theme={null}
   sudo ln -sf /bin/bash /bin/sh
   ```

## 构建 robotics 镜像

以下步骤在 Yocto Project 之上设置基于 KAS 的编译环境，并使用 KAS 工具构建 robotics 镜像。

1. 参考 [Yocto Project 参考手册](https://docs.yoctoproject.org/ref-manual/system-requirements.html) 中的步骤设置你的 Yocto Project 构建环境。

2. KAS 工具提供了一种简便的方式来设置基于 bitbake 的项目。有关详细信息，请参见 [KAS 文档](https://kas.readthedocs.io/en/latest/index.html)。使用以下命令安装 KAS 工具。

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

   # Restart your shell session after running this command to ensure
   # path changes take effect
   pipx ensurepath

   # The kas version is expected to be 4.8 or higher
   pipx install kas
   ```

3. 使用其中一个支持的开发板的 KAS 配置进行构建。

   1. 使用最新的 `<meta-qcom-robotics-sdk-release-tag>` 下载 Qualcomm 的 Yocto 层 `meta-qcom-robotics-sdk`。

      下表说明了当前发布的构建标签。

      | **发布标签**                           | **标识符**                |
      | :--------------------------------- | :--------------------- |
      | meta-qcom-robotics-sdk-release-tag | <code>{QLI_TAG}</code> |

      ```shell theme={null}
      git clone https://github.com/qualcomm-linux/meta-qcom-robotics-sdk \
      -b qli-2.1
      ```

   2. 使用 `kas` 构建软件性能镜像。

      ```shell theme={null}
      kas build meta-qcom-robotics-sdk/ci/<MACHINE>.yml:meta-qcom-robotics-sdk/ci/<DISTRO>.yml:meta-qcom-robotics-sdk/ci/<TARGET>.yml:meta-qcom-robotics-sdk/ci/<KERNEL>.yml
      ```

      下表列出了支持的 `<MACHINE>`、`<DISTRO>`、`<TARGET>` 和 `<KERNEL>` 组合。从每一列中选择一项以替换命令中相应的占位符。有关这些 KAS 配置片段的更多详细信息，请参见 [Robotics OpenEmbedded 层变更](./migration-robotics-oe-layer-changes#qir-sdk-for-qualcomm-linux-20-single-unified-layer) 以及 Qualcomm Linux Yocto 指南的 [`meta-qcom`](../../../Key-Documents/Yocto-Guide/meta-qcom) 和 [`meta-qcom-distro`](../../../Key-Documents/Yocto-Guide/meta-qcom-distro) 部分。

      <table>
        <thead>
          <tr>
            <th align="center" valign="top">MACHINE 配置<br /></th>
            <th align="center" valign="top">DISTRO 配置<br /></th>
            <th align="center" valign="top">TARGET 镜像 recipe<br /></th>
            <th align="center" valign="top">KERNEL 提供者<br /></th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td align="left">
              <ul>
                <li><code>iq-8275-evk</code></li>
                <li><code>iq-9075-evk</code></li>
              </ul>
            </td>

            <td align="left">
              <ul>
                <li><code>qcom-robotics-distro</code></li>
                <li><code>qcom-robotics-distro-catchall</code></li>
              </ul>
            </td>

            <td align="left">
              <ul>
                <li><code>qcom-robotics-image</code></li>
                <li><code>qcom-robotics-proprietary-image</code></li>
              </ul>
            </td>

            <td align="left">
              <ul>
                <li><code>linux-qcom-6.18</code></li>
                <li><code>linux-qcom-rt-6.18</code></li>
              </ul>
            </td>
          </tr>
        </tbody>
      </table>

      **示例**：

      * 要基于开源组件构建 robotics 镜像，请使用 [qcom-robotics-image](https://github.com/qualcomm-linux/meta-qcom-robotics-sdk/blob/wrynose/recipes-products/images/qcom-robotics-image.bb) recipe：

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

        ```bash IQ-8275-EVK theme={null}
        kas build meta-qcom-robotics-sdk/ci/iq-8275-evk.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-distro.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-image.yml:meta-qcom-robotics-sdk/ci/linux-qcom-6.18.yml:meta-qcom-robotics-sdk/ci/performance.yml
        ```
      </CodeGroup>

      * 要构建包含 Qualcomm 专有组件功能的 robotics 镜像，请使用 [qcom-robotics-proprietary-image](https://github.com/qualcomm-linux/meta-qcom-robotics-sdk/blob/wrynose/recipes-products/images/qcom-robotics-proprietary-image.bb) recipe：

      <CodeGroup>
        ```bash IQ-9075-EVK theme={null}
        kas build meta-qcom-robotics-sdk/ci/iq-9075-evk.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-distro.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-proprietary-image.yml:meta-qcom-robotics-sdk/ci/linux-qcom-6.18.yml:meta-qcom-robotics-sdk/ci/performance.yml
        ```

        ```bash IQ-8275-EVK theme={null}
        kas build meta-qcom-robotics-sdk/ci/iq-8275-evk.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-distro.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-proprietary-image.yml:meta-qcom-robotics-sdk/ci/linux-qcom-6.18.yml:meta-qcom-robotics-sdk/ci/performance.yml
        ```
      </CodeGroup>

4. **（可选）** 构建调试镜像。

   要构建调试镜像，请将相应的 yaml 片段文件附加到 `kas build` 命令末尾：

   **示例**（machine：`iq-9075-evk`，调试构建）：

   ```shell theme={null}
   kas build meta-qcom-robotics-sdk/ci/iq-9075-evk.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-distro.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-proprietary-image.yml:meta-qcom-robotics-sdk/ci/linux-qcom-6.18.yml:meta-qcom-robotics-sdk/ci/debug.yml
   ```

5. `kas build` 会在以下路径生成镜像：

   ```shell theme={null}
   build/tmp/deploy/images/<MACHINE NAME>/<TARGET image>-<MACHINE NAME>.rootfs.qcomflash
   ```

   **示例**（machine：`iq-9075-evk`，target：`qcom-robotics-proprietary-image`）

   ```shell theme={null}
   build/tmp/deploy/images/iq-9075-evk/qcom-robotics-proprietary-image-iq-9075-evk.rootfs.qcomflash
   ```

<Note>
  **注意**

  如果遇到任何构建问题，请参见 [故障排除常见问题](./troubleshoot)。
</Note>

## 生成 QIR SDK 制品

要生成 QIR SDK，请在镜像构建完成后运行 `generate_qirp_sdk` 任务：

```shell theme={null}
kas build meta-qcom-robotics-sdk/ci/<MACHINE>.yml:meta-qcom-robotics-sdk/ci/<DISTRO>.yml:meta-qcom-robotics-sdk/ci/<TARGET>.yml:meta-qcom-robotics-sdk/ci/<KERNEL>.yml -c generate_qirp_sdk
```

**示例**（machine：`iq-9075-evk`，kernel：`linux-qcom-6.18`）：

```shell theme={null}
kas build meta-qcom-robotics-sdk/ci/iq-9075-evk.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-distro.yml:meta-qcom-robotics-sdk/ci/qcom-robotics-image.yml:meta-qcom-robotics-sdk/ci/linux-qcom-6.18.yml -c generate_qirp_sdk
```

`kas build` 会在以下路径生成 QIR SDK 制品：

```shell theme={null}
build/tmp/deploy/qirpsdk_artifacts/<MACHINE NAME>/qirp_sdk.tar.gz
```

## 将 robotics 镜像刷写到设备

要将 robotics 镜像刷写到设备，请按照 [刷写 robotics 镜像](./flash-the-robotics-image) 中的步骤操作，使用在 [构建 robotics 镜像](#build-the-robotics-image) 中生成的 `qcom-robotics-image` 或 `qcom-robotics-proprietary-image` 镜像。
