You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在QEMU启动交叉编译的RISCV二进制文件失败求助

AndesTech RISC-V架构QEMU启动内核Panic问题排查思路

已完成的交叉编译操作

  • 交叉编译OpenSBI,在~/opensbi/build/platform/andes/ae350/firmware/生成fw-dynamic.elf和.bin文件;
  • 编译集成BusyBox的根文件系统,通过脚本在~/rootfs/disk/dev/生成initramfs.devnodes;
  • 修改Linux内核.config,添加CONFIG_INITRAMFS_SOURCE="~/rootfs/disk/dev/initramfs.devnodes",编译得到~/linux5.4/arch/riscv/boot/Image;
  • 复制相关文件到U-Boot路径,执行make ae350_rv64_fastboot_defconfig && make ARCH_FLAGS="-march=rv64v5"生成u-boot.img;
  • 安装适配Andes的QEMU后,执行启动命令:
$ ./qemu-system-riscv64 -nographic -M andes_ae350 -cpu andes-ax45 -m 2G \
-kernel ~/linux-5.4/arch/riscv/boot/Image \
-bios ~/opensbi/build/platform/andes/ae350/firmware/fw_dynamic.elf \
-initrd ~/rootfs/disk/dev/initramfs.devnodes \
-append "root=/dev/vda rw console=ttyS0"

启动错误日志

启动触发内核Panic,关键日志如下:

[    0.223322] Segment Routing with IPv6
[    0.224621] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.227011] NET: Registered protocol family 17
[    0.227576] NET: Registered protocol family 15
[    0.231335] ALSA device list:
[    0.231823]   No soundcards found.
[    0.232985] Warning: unable to open an initial console.
[    0.234276] Failed to create /dev/root: -2
[    0.234868] VFS: Cannot open root device "vda" or unknown-block(0,0): error -2
[    0.234994] Please append a correct "root=" boot option; here are the available partitions:
[    0.235251] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    0.235527] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.220-21054-gf1d0d3f65278 #4
[    0.235702] Call Trace:
[    0.236096] [<ffffffe00003537c>] walk_stackframe+0x0/0xa8
[    0.236217] [<ffffffe00049e910>] show_stack+0x30/0x3c
[    0.236302] [<ffffffe0004a44ec>] dump_stack+0x6c/0x88
[    0.236385] [<ffffffe00049ebf8>] panic+0xe8/0x290
[    0.236531] [<ffffffe0000020bc>] 0xffffffe0000020bc
[    0.236612] [<ffffffe000002208>] 0xffffffe000002208
[    0.236691] [<ffffffe000002354>] 0xffffffe000002354
[    0.236772] [<ffffffe000001cfc>] 0xffffffe000001cfc
[    0.236857] [<ffffffe0004a46cc>] kernel_init+0x14/0xdc
[    0.236941] [<ffffffe000033e46>] ret_from_exception+0x0/0xc
[    0.237382] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

解决思路

  1. 修正initramfs使用逻辑

    • 你已经通过CONFIG_INITRAMFS_SOURCE将initramfs编译进内核,此时启动命令无需再用-initrd重复指定,两种方式二选一:
      • 保留内核内置initramfs:移除启动命令中的-initrd ~/rootfs/disk/dev/initramfs.devnodes,同时修改append参数为console=ttyS0 root=/dev/ram0 rw(或直接去掉root参数,让内核自动识别initramfs);
      • 使用外置initrd:清空内核配置中的CONFIG_INITRAMFS_SOURCE,确保开启CONFIG_BLK_DEV_INITRD=y,启动时append参数设为console=ttyS0 root=/dev/ram0 rw。
  2. 根设备配置校验

    • 当前启动命令指定root=/dev/vda,但未通过QEMU的-drive参数挂载虚拟磁盘,内核自然找不到该设备。若要使用磁盘根文件系统:
      • 创建ext4格式的磁盘镜像:dd if=/dev/zero of=rootfs.img bs=1M count=512 && mkfs.ext4 rootfs.img;
      • 启动命令添加磁盘挂载参数:-drive file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0;
      • 确保内核开启CONFIG_VIRTIO_BLK选项。
  3. 验证initramfs完整性

    • 用cpio -t < initramfs.devnodes查看initramfs内的文件列表,确认存在/init脚本(或BusyBox的init软链接)、/dev/console设备节点,否则会触发控制台无法打开的错误。
  4. 内核配置检查

    • 确认开启Andes AE350必需的驱动:CONFIG_SERIAL_8250=y(串口控制台)、CONFIG_BLK_DEV_RAM=y(ramdisk支持)、CONFIG_VIRTIO=y(若使用virtio设备);
    • 检查CONFIG_INITRAMFS_ROOT_GID和CONFIG_INITRAMFS_ROOT_UID设置,避免权限问题导致文件系统无法访问。
  5. 对齐U-Boot引导流程

    • 若使用U-Boot引导,应让QEMU加载u-boot.img而非直接加载内核,启动命令改为:
      ./qemu-system-riscv64 -nographic -M andes_ae350 -cpu andes-ax45 -m 2G -bios ~/opensbi/build/platform/andes/ae350/firmware/fw_dynamic.elf -kernel u-boot.img
      
    • 进入U-Boot命令行后,手动设置bootargs并引导内核、initrd,更符合官方指引的流程。

内容的提问来源于stack exchange,提问作者Pranay Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 05:42:14