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

# Qualcomm Linux 上的 U-Boot

## 概述

本页概述了 Qualcomm Linux（QLI）软件中对 U-Boot（通用引导加载程序）的支持。

## 支持的 SoC

| SoC 名称  | 是否支持 | 存储   |
| ------- | ---- | ---- |
| QCS6490 | 是    | UFS  |
| IQ-9075 | 是    | UFS  |
| IQ-615  | 是    | eMMC |
| IQ-8275 | 否    |      |

## 构建 U-Boot 镜像

本节介绍如何将 U-Boot 二进制文件作为 QLI 2.0 软件的一部分进行构建。

### 1. 从 Qualcomm Linux GitHub 仓库构建

#### 前提条件

在执行构建步骤之前，请执行以下操作：

1. 在本地计算机上安装以下软件包：
   ```bash theme={null}
   sudo apt install libgnutls28-dev
   ```

2. 下载并解压 Arm GNU 工具链：

   ```bash theme={null}
   cd ~  # or your preferred location
   wget https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
   tar -xf arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
   ```

   <Note>
     * 这会在 `~/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu/` 创建工具链目录。如果解压到其他位置，请相应调整构建命令中的路径。
     * 仅在 x86 64 位主机上安装该工具链。
     * 其他版本请访问 [Arm GNU 工具链下载](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads)。
   </Note>

3. 下载 qtestsign 实用程序：
   ```bash theme={null}
   cd ~  # or your preferred location
   git clone https://github.com/msm8916-mainline/qtestsign qtestsign
   ```

#### 构建步骤

1. 将 U-Boot 仓库从 Qualcomm Linux GitHub 下载到本地工作区，并进入 `u-boot` 文件夹：
   ```bash theme={null}
   git clone https://github.com/qualcomm-linux/u-boot.git
   ```

2. 切换分支：
   ```bash theme={null}
   git switch qcom-next
   ```

3. 检出 QLI 2.0 版本的 SRC REV：
   ```bash theme={null}
   git checkout 5a77d4670d8084ada24a2735dda75788ed5ce925
   ```

4. 由于 IQ-9075 和 IQ-615 默认启用了基于内核的虚拟机（KVM），请将以下配置选项添加到各自的 defconfig 文件中：

   ```
   CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK=y
   CONFIG_QCOM_EL2_GUNYAH_EXIT_SUPPORT=y
   ```

   <Note>
     QCS6490 请跳过此步骤，因为其默认未启用 KVM。
   </Note>

5. 为您的平台配置构建。此命令会在 `.output` 目录中创建所需的配置文件。请根据您的平台选择相应命令：

   | SoC     | 命令                                     |
   | ------- | -------------------------------------- |
   | QCS6490 | `make O=.output qcm6490_defconfig`     |
   | IQ-9075 | `make O=.output qcom_lemans_defconfig` |
   | IQ-615  | `make O=.output qcom_qcs615_defconfig` |

6. 使用交叉编译工具链构建 U-Boot：

   ```bash theme={null}
   make -j8 CROSS_COMPILE=~/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- O=.output
   ```

   <Note>
     如果将工具链解压到了其他位置，请将 `~/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu/` 替换为您的实际工具链安装路径。
   </Note>

   **预期结果：**

   * U-Boot 构建完成且无错误。
   * `u-boot.elf` 文件位于 `.output` 目录中。

#### 将 u-boot.elf 转换为 u-boot.mbn

此命令生成烧录所需的已签名 `u-boot.mbn` 文件：

```bash theme={null}
python ~/qtestsign/qtestsign.py -v6 aboot -o .output/u-boot.mbn .output/u-boot.elf
```

<Note>
  如果将 qtestsign 克隆到了其他位置，请将 `~/qtestsign/` 替换为您的实际 qtestsign 安装路径。
</Note>

### 2. 使用 Yocto 构建

按照[使用 Yocto 构建 Qualcomm Linux](/zh/Key-Documents/Yocto-Guide/build-qualcomm-linux) 页面上的说明操作，并进行以下修改：

* 要生成 U-Boot 二进制文件，请在"构建 BSP 镜像"第 3 步的构建命令中追加 `:meta-qcom/ci/u-boot-qcom.yml` KAS 片段。
* 在构建产物文件夹中，最终的 U-Boot 二进制文件以 `uefi.elf` 形式生成在 `<workspace-dir>/build/tmp/deploy/images/<MACHINE>/<IMAGE>-<MACHINE>.rootfs.qcomflash/` 目录中。

<Note>
  在 Yocto 构建中，支持 KVM 的目标（IQ-9075 和 IQ-615）默认启用基于内核的虚拟机（KVM）。为这些目标构建 U-Boot 时，会默认添加以下配置：

  ```
  CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK=y
  CONFIG_QCOM_EL2_GUNYAH_EXIT_SUPPORT=y
  ```
</Note>

## 烧录 U-Boot 镜像

### 使用 Qualcomm 工具

按照[烧录软件镜像](/zh/Key-Documents/Flash-Guide/flash-with-qdl)中的说明，随 QLI 2.0 构建一起烧录 U-Boot 二进制文件。

### 使用 Fastboot

1. 使用以下方法之一进入 fastboot 模式：
   * 从内核：
     ```bash theme={null}
     adb shell reboot bootloader
     ```
   * 从 U-Boot CLI：
     ```
     run fastboot
     ```
2. 从主机烧录所需镜像。例如，要烧录 U-Boot 镜像：
   ```bash theme={null}
   fastboot flash uefi_a u-boot.mbn
   ```
3. 重启设备：
   ```bash theme={null}
   fastboot reboot
   ```

## 支持的 U-Boot 命令

下表列出了在受支持平台上可用的一些关键 U-Boot 命令。这些命令涵盖启动管理、环境管理、存储访问和硬件外设控制。可用命令可能因平台支持情况而异。

<Note>
  * 在 QCS6490 中，Watchdog 由 Hypervisor 使用；因此 Watchdog 命令在 QCS6490 上不起作用。
</Note>

| 命令                                | 描述                                              |
| --------------------------------- | ----------------------------------------------- |
| **启动**                            |                                                 |
| `run bootcmd`                     | 运行 `bootcmd` 中定义的默认启动命令序列                       |
| `bootefi bootmgr`                 | 根据 BootOrder/BootXXXX 变量加载并启动 EFI 负载            |
| `bootflow scan [-abeGl] [bdev]`   | 扫描有效的 bootflow（`-l` 列出，`-a` 全部，`-e` 错误，`-b` 启动） |
| `bootflow list [-e]`              | 列出已扫描的 bootflow（`-e` 包含错误）                      |
| `bootflow select [<num>\|<name>]` | 按编号或名称选择 bootflow                               |
| `bootflow info [-ds]`             | 显示当前 bootflow 的信息（`-d` 转储 bootflow）             |
| `bootflow boot`                   | 启动当前 bootflow                                   |
| `bootdev list [-p]`               | 列出所有可用的启动设备（`-p` 探测）                            |
| `bootdev info [-p]`               | 显示当前启动设备的信息（`-p` 探测）                            |
| **通用**                            |                                                 |
| `printenv`                        | 打印环境变量                                          |
| `saveenv`                         | 保存环境变量                                          |
| `version`                         | 打印监视器、编译器和链接器版本                                 |
| `run fastboot`                    | 进入 fastboot 模式并等待来自主机的 fastboot 命令请求            |
| `reset -edl`                      | 进入 EDL（紧急下载）模式                                  |
| **SCSI**                          |                                                 |
| `scsi scan`                       | 扫描 SCSI 总线                                      |
| `scsi info`                       | 显示可用的 SCSI 设备                                   |
| `scsi device [dev]`               | 显示或设置当前设备（`dev` 应为 0、1、2、3、4、5 等）               |
| `scsi part [dev]`                 | 打印一个或所有 SCSI 设备的分区表                             |
| `scsi read [addr] [blk#] [cnt]`   | 从块 `blk#` 开始读取 `cnt` 个块到内存地址 `addr`             |
| `scsi write [addr] [blk#] [cnt]`  | 从内存地址 `addr` 开始向块 `blk#` 写入 `cnt` 个块            |
| **MMC**                           |                                                 |
| `mmc list`                        | 列出可用的 MMC 设备                                    |
| `mmc info`                        | 显示当前 MMC 设备信息                                   |
| `mmc dev [dev]`                   | 显示或设置当前 MMC 设备                                  |
| `mmc part`                        | 打印当前 MMC 设备的分区表                                 |
| `mmc read [addr] [blk#] [cnt]`    | 从 MMC 的块 `blk#` 开始读取 `cnt` 个块到内存地址 `addr`       |
| `mmc write [addr] [blk#] [cnt]`   | 从内存地址 `addr` 开始向 MMC 的块 `blk#` 写入 `cnt` 个块      |
| **稳压器（Regulator）**                |                                                 |
| `regulator list`                  | 列出 UCLASS 稳压器设备                                 |
| `regulator dev [regulator-name]`  | 显示或设置当前操作的稳压器设备                                 |
| `regulator info`                  | 打印约束信息                                          |
| `regulator status [-a]`           | 打印工作状态（使用 `-a` 显示全部）                            |
| `regulator value [val] [-f]`      | 打印或设置电压值（单位 µV，使用 `-f` 强制）                      |
| `regulator enable`                | 启用稳压器输出                                         |
| `regulator disable`               | 禁用稳压器输出                                         |
| **看门狗（WDT）**                      |                                                 |
| `wdt list`                        | 列出可用的看门狗设备                                      |
| `wdt dev [devname]`               | 显示或设置当前看门狗设备                                    |
| `wdt start <timeout_ms>`          | 以指定的超时时间（毫秒）启动看门狗定时器                            |
| `wdt stop`                        | 停止看门狗定时器                                        |

## 另请参阅

* [使用 U-Boot 日志进行故障排查](./troubleshoot-using-uboot-log)
