> ## 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<sup>®</sup> Linux 启动系统使用两个已刷写的镜像来启动内核:`efi.bin`(ESP 分区)和 `dtb.bin`(DTB 分区)。

## 镜像构成

Yocto 构建将内核产物打包为可刷写的镜像:

* **`efi.bin`** 是 EFI 系统分区(ESP)镜像。包含 systemd-boot(启动管理器)和打包为 UKI type-2 镜像的内核,该镜像捆绑了内核、initramfs,以及可选的设备树。刷写到 `efi` 分区。
* **`dtb.bin`** 是 DTB 分区镜像。包含所有编译后的设备树 blob(DTB)。刷写到 `dtb_a` 分区。

**表:内核构建产物**

| 镜像        | 镜像名称                                     | 构建部署路径                                                          | 详情                                             |
| --------- | ---------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------- |
| 内核 ELF    | `vmlinux`                                | `build/tmp/deploy/images/<machine>/<image>-*.rootfs.qcomflash/` | 带调试符号的输出内核 ELF。                                |
| Initramfs | `initramfs-qcom-image-<machine>.cpio.gz` | `build/tmp/deploy/images/<machine>/`                            | CPIO 格式的 initramfs。                            |
| 内核镜像      | `Image`                                  | `build/tmp/deploy/images/<machine>/`                            | 原始内核二进制文件。systemd-boot 不支持压缩镜像。                |
| 内核模块      | `modules-<machine>.tgz`                  | `build/tmp/deploy/images/<machine>/`                            | 动态可加载内核模块(DLKM)。                               |
| 设备树 blob  | `<SoC>-<board>-<variant>.dtb`            | `build/tmp/deploy/images/<machine>/`                            | 单个设备树 blob。                                    |
| ESP 分区    | `efi.bin`                                | `build/tmp/deploy/images/<machine>/<image>-*.rootfs.qcomflash/` | 打包为 UKI type-2 镜像的 systemd-boot、内核和 initramfs。 |
| DTB 分区    | `dtb.bin`                                | `build/tmp/deploy/images/<machine>/<image>-*.rootfs.qcomflash/` | 打包在 FIT 镜像中的所有 DTBO。                           |

## 部署内核产物

如果你之前尚未刷写所有启动二进制文件,请先按照
[带固件的 BSP 镜像构建](https://dragonwingdocs.qualcomm.com/Key-Documents/Firmware-Guide/build-firmware)中的完整刷写说明操作。

对于后续仅涉及内核的更新,可以增量刷写 `efi.bin` 和 `dtb.bin`:

```bash theme={null}
# Navigate to the build output directory
cd build/tmp/deploy/images/<machine>/<image>-*.rootfs.qcomflash/

# Flash the ESP and DTB partition images
fastboot flash efi efi.bin
fastboot flash dtb_a dtb.bin
fastboot reboot
```

<Note>
  内核或 DTS 更改后,必须同时刷写 `efi.bin` 和 `dtb.bin`,以保持内核和设备树同步。
</Note>

## 验证正在运行的内核

设备重启后,确认正在运行的内核版本符合预期,且启动过程没有错误。

### 连接到设备

使用以下方法之一访问设备上的 shell:

* **串行控制台(UART)**,推荐用于早期启动检查。有关设置说明,请参阅[连接到你的目标设备](./connect-to-your-target)。
* **ADB shell**,在设备完全启动后使用:

```bash theme={null}
adb shell
```

* **SSH**,使用设备 IP 地址通过网络连接:

```bash theme={null}
ssh root@<device-ip>
```

### 检查内核版本

```bash theme={null}
# Short version string
uname -r

# Full version, architecture, and build timestamp
uname -a

# Detailed version including compiler
cat /proc/version
```

`uname -r` 的输出应反映你构建并刷写的内核版本(例如 LTS 系列的 `6.18.x` 字符串)。

### 检查启动健康状况

检查内核环形缓冲区,查找早期启动中的错误或警告:

```bash theme={null}
# Print the first 50 lines of kernel messages
dmesg | head -50

# Filter for errors and warnings only
dmesg --level=err,warn
```

在使用 systemd 的系统上,也可以通过以下命令查看当前启动的内核消息:

```bash theme={null}
journalctl -k -b
```

### 确认内核模块

验证预期的内核模块已成功加载:

```bash theme={null}
# List all loaded modules
lsmod

# Check if Qualcomm-specific modules are present
lsmod | grep qcom
```

要检查所需模块是否缺失,请在目标设备上运行以下命令,确认该模块已包含在内核配置中,且在配置更改后重新构建了镜像:

```bash theme={null}
zcat /proc/config.gz | grep CONFIG_<Module>
```

### 故障排除

如果内核版本与构建的版本不符,或设备无法启动:

* 重新运行 `fastboot flash` 命令并检查是否有 `OKAY` 响应,确认刷写过程没有错误。
* 确认 `efi.bin` 和 `dtb.bin` 已刷写到正确的分区(分别为 `efi` 和 `dtb_a`)。
* 有关启动失败和内核 panic 分析,请参阅
  [内核问题故障排除](./troubleshoot-kernel-issues)。
* 有关串行控制台日志捕获,请参阅
  [内核日志](./kernel-logging)。
