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

# 内核问题故障排除

要排除内核问题,请使用以下方法:

## **由于选取了错误的 DTB 或未选取 DTB 导致的启动失败**

排除因 DTB 加载问题导致的启动失败时,请验证认证和 DTB 可用性,并按照步骤修复问题。

以下场景会导致启动失败:

* **认证失败**
  以下示例显示了因认证不正确而失败的日志:
  ```text theme={null}
  Platform Subtype : 0
  DtPlatformLoadDtb qcs6490-rb3gen2.dtb is loaded
  Platform Subtype : -2090817768
  DtPlatformLoadSign qcs6490-rb3gen2.sgn is loaded
  failed to authenticate image !
  ```
* **由于 DTB 不可用导致的失败**
  以下示例显示了因缺少 DTB 而失败的日志:
  ```text theme={null}
  DtPlatformLoadDtb qcs6490-rb3gen2.dtb is loading failed with Status = E
  DtPlatformDxeEntryPoint: no DTB blob could be loaded, defaulting to ACPI (Status == Not Found)
  ```
  要修复 DTB 不可用的问题,请执行以下操作:
  * 验证对应的 DTB 文件是否包含在打包的 `dtb.bin` 文件中。
  * 在主机开发机上本地挂载 `dtb.bin` 文件以进行以下验证:
    ```text theme={null}
    mount -t vfat dtb.bin /mnt/
    fdtdump /mnt/combined-dtb.bin | grep -i model
    ```
* **从内核日志验证已加载的 DTB**
  使用以下命令从内核日志验证启动时加载的 DTB:
  ```text theme={null}
  dmesg | grep -i model
  ```

## **串行控制台不工作**

要排除串行控制台日志故障,请在内核配置中启用特定驱动,并在内核启动参数中添加相关参数。

* 在内核配置文件中启用以下驱动:
  * `CONFIG_SERIAL_QCOM_GENI=y`
  * `CONFIG_SERIAL_QCOM_GENI_CONSOLE=y`
* 在内核启动参数中添加以下参数:
  ```text theme={null}
  console=ttyMSM0,115200n8
  ```
* 要获取内核的早期启动消息,请在内核启动参数中添加以下参数:
  ```text theme={null}
  earlycon
  ```

## **调试远程处理器故障**

要排除 remoteproc 故障,请捕获内核日志、使用匹配的固件签名文件,并验证设备中的固件位置。

* 确保所有匹配的子系统镜像均已无误刷写。
* 检查内核日志中是否存在错误。
  以下示例显示了一个内核日志样例:
  ```text theme={null}
  0x000000000A27652C |   5198.790423:   qcom_q6v5_pas 3000000.remoteproc: fatal error received: err_inject_crash.c:413:Crash injected via Diag
  0x000000000A276689 |   5198.801061:   remoteproc remoteproc2: crash detected in 3000000.remoteproc: type fatal error
  0x000000000A2767A1 |   5198.809602:   remoteproc remoteproc2: handling crash #1 in 3000000.remoteproc
  0x000000000A27688E |   5198.816837:   remoteproc remoteproc2: recovering 3000000.remoteproc
  0x000000000A276971 |   5198.823784:   qcom_q6v5_pas 8a00000.remoteproc: subsystem event rejected
  ```
* 禁用以下子系统重启功能,以确保 remoteproc 崩溃签名在内核日志中可见:
  ```text theme={null}
  echo disabled > /sys/kernel/debug/remoteproc/remoteprocN/recovery
  ```
* 确认 rootfs 文件系统的 `/lib/firmware/qcom/<SoC>` 中存在所有必需的固件文件。

## **调试配置或符号未反映到镜像中**

要调试配置或符号未反映到镜像中的内核配置更改问题,请按以下步骤操作:

1. 将调试配置驱动添加到 `kernel/configs/debug.config` 文件。
2. 在运行 `bitbake` 命令之前导出 `DEBUG_BUILD=1` 宏。

## **系统内存过低**

要调试系统可用内存耗尽的情况,请参阅 [Debugging linux kernel](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/Debugging%20linux%20kernel)。

## **在启动期间识别 DTB**

设备启动时,引导加载程序会验证以下 ID 并加载对应的 DTB 文件:

```text theme={null}
qcom,msm-id = <x z>;
qcom,board-id = <y y'>;
```

* x = SoC 的 ID
* z = SoC 修订版本的 ID(保留字段)
* y = CDP、MTP(硬件变体)和平台的 ID
* y' = 子类型的 ID(如缺失则假定为 0)

## **调试 RT 内核**

以下方法用于排除 RT 内核中的问题:

* 如何验证底层内核是实时内核?
  启动完成后,运行以下命令验证内核类型:
  ```text theme={null}
  uname -r
  6.6-rt15
  uname -v
  SMP PREEMPT_RT
  ```
* 如何使驱动符合 RT 要求?
  确保同步原语不会破坏 RT 假设。
  以下是可能破坏 RT 假设并导致意外系统行为的场景示例:
  ```text theme={null}
  /* Acquiring a preemptible lock in non preemptible context */
  preempt_disable( )
  ……
  spin_lock( )
  /* Acquiring a preemptible lock in non preemptible context /
  raw_spin_lock( )
  ……
  spin_lock( )
  /* Acquiring a non preemptible lock in preemptible context /
  local_lock_irq( )
     …..
  raw_spin_lock( )
  ```
* 调试 RT 内核配置
  以下是 RT 内核的调试配置:
  * `CONFIG_DEBUG_ATOMIC_SLEEP` - 检查原子区段内是否存在睡眠。
  * `CONFIG_PROVE_RAW_LOCK_NESTING` - 允许 `raw_spinlock` 与 spinlock 嵌套。确保不违反 `PREEMPT_RT` 内核的锁嵌套规则。
    调试期间,你可以从 RT 内核切换到非 RT 内核。要切换,请修改 `meta-qcom/ci/linux-qcom-rt-6.18.yml` 文件以更改 `linux-qcom-rt` 中的 virtual/kernel 设置,然后重新编译。
    要进行更改,请运行以下命令:
    ```text theme={null}
    - PREFERRED_PROVIDER_virtual/kernel = "linux-qcom-rt"
    + PREFERRED_PROVIDER_virtual/kernel = "linux-qcom"
    ```

有关 RT 内核锁原语的更多信息,请参阅 [Lock types and their rules—The Linux Kernel documentation](https://www.kernel.org/doc/html/latest/locking/locktypes.html)。

## **排除 virtio 问题**

使用以下方法排除 virtio 问题:

* 确保内核已使用所需配置编译。
* 验证 QEMU 命令行选项或 libvirt XML 配置。
* 检查系统日志中的错误。
* 使用可用的跟踪后端在 QEMU 命令行中为 virtio 启用跟踪。有关 KVM 跟踪的更多信息,请参阅 [KVM traces](https://docs.qualcomm.com/doc/80-80021-3/topic/virtualization.html?product=895724676033554725\&facet=Kernel\&version=2.0-rc2#kvm-traces)。
