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

# 使用 GitHub 工作流构建

按照详细说明同步 Qualcomm Yocto 层和 QIR SDK 层，并构建机器人镜像及 QIR SDK 构建产物。

<Warning>
  **警告**

  不建议重新构建 QIR SDK，因为对于非专业人员来说构建过程较为复杂。仅当您理解构建过程且有以下需求时，才构建 QIR SDK：

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

1. [为构建设置主机](#set-up-the-host-computer-for-build)
2. [构建机器人镜像](#build-the-robotics-image)
3. [生成 QIR SDK 构建产物](#generate-qir-sdk-artifacts)
4. [将机器人镜像烧录到设备](#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. 设置区域语言（locales）。
   ```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
   ```

## 构建机器人镜像

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

1. 参考 [Yocto Project Reference Manual](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 | `qli-2.0` |

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

   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 镜像配方<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>

      **示例**：

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

      <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 专有组件功能的机器人镜像，请使用 [qcom-robotics-proprietary-image](https://github.com/qualcomm-linux/meta-qcom-robotics-sdk/blob/wrynose/recipes-products/images/qcom-robotics-proprietary-image.bb) 配方：

      <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
```

## 将机器人镜像烧录到设备

要将机器人镜像烧录到设备，请参阅 [烧录机器人镜像](./flash-the-robotics-image)，使用在 [构建机器人镜像](#build-the-robotics-image) 中生成的 `qcom-robotics-image` 或 `qcom-robotics-proprietary-image`。
