跳到主要内容

验证与调试

平台层改动会影响启动、内存、IRQ、timer、console 和设备发现。验证应从最小编译检查开始,再逐步到 QEMU 或板卡 bring-up。

最小检查

平台模板或平台选择变更后,先运行:

cargo fmt --check
cargo metadata --locked --no-deps --format-version 1
cargo test -p axbuild --lib
cargo xtask clippy --package axbuild

外部平台应在自己的 workspace 和本地 ax-hal 增加对应 package / optional dependency / feature,然后再运行:

cargo check -p axplat-myplat --features irq,smp
AX_PLATFORM_CRATE=axplat_myplat cargo check -p ax-hal --features axplat-myplat,irq,smp

如果修改了具体平台 crate,还应对该 crate 运行 targeted clippy:

cargo xtask clippy --package axplat-myplat
cargo xtask clippy --package ax-hal

QEMU 验证

动态平台路径优先使用 cargo xtask

cargo xtask arceos test qemu --arch aarch64
cargo xtask starry test qemu --arch riscv64
cargo xtask axvisor test qemu --arch x86_64 --test-group normal

外部平台只有在补齐启动入口、链接脚本、console、timer、内存和 IRQ 后,才应宣称可启动 QEMU。

常见失败信号

现象优先检查
链接重复 __*If_* 符号是否同时链接了两个 ax-plat 实现 crate
没有任何串口输出入口符号、早期 console、地址转换、重定位窗口
清 BSS 后崩溃linker script、段地址、boot stack、保留内存范围
开 timer 后卡住timer IRQ 编号、ACK/EOI、one-shot 重编程顺序
设备找不到FDT/ACPI/PCI probe 是否注册,Static probe 是否执行
IRQ handler 不触发IRQ source resolver、domain、enable、affinity、controller EOI

调试建议

  • 先确认最后一个可靠输出点:固件入口、退出 UEFI、开启 MMU、进入 ax_plat::call_main()init_early()init_later()
  • 早期启动问题优先用物理地址标记或最小串口输出,不要依赖完整日志系统。
  • 检查最终链接镜像的符号和段布局,确认运行时地址而不只是编译期地址。
  • QEMU 可加 -d int,cpu_reset,guest_errors 或 debug stub,但临时调试参数不要留在提交中。