実際にはM1 Mac上で構築したLima上のUbuntu 22.04 LTS上でのビルドの試行だけれども。QEMUでのLinuxブート環境が構築したくて、RISC-V Getting Started Guideをそのまま試してみることにした。
なんかうまく行かないので、QEMUのバージョンを2種類用意してみた。
- QEMU 7.0.0
QEMU emulator version 7.0.0 Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
カーネルを指定しても、ファイルシステムの読み込みの段階で失敗してしまう。何がおかしいのかなあ。
qemu-system-riscv64 -nographic -machine virt -kernel linux/arch/riscv/boot/Image -append "root=/dev/vda ro console=ttyS0" -drive file=busybox/busybox,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
... [ 0.266059] Key type dns_resolver registered [ 0.268047] debug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers [ 0.301143] List of all partitions: [ 0.301395] fe00 950 vda [ 0.301425] driver: virtio_blk [ 0.301739] No filesystem could mount root, tried: [ 0.301763] ext3 [ 0.302051] ext2 [ 0.302153] ext4 [ 0.302189] vfat [ 0.302534] msdos [ 0.302818] [ 0.302985] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,0) [ 0.303340] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.18.0-rc7-00181-geaea45fc0e7b #1 [ 0.303825] Hardware name: riscv-virtio,qemu (DT) [ 0.304008] Call Trace: [ 0.304341] [<ffffffff80004a28>] dump_backtrace+0x1c/0x24 [ 0.304483] [<ffffffff80640dda>] show_stack+0x2c/0x38 [ 0.304570] [<ffffffff80645df8>] dump_stack_lvl+0x40/0x58 [ 0.304653] [<ffffffff80645e24>] dump_stack+0x14/0x1c [ 0.304730] [<ffffffff806410e6>] panic+0x106/0x2b0 [ 0.304809] [<ffffffff80801462>] mount_block_root+0x202/0x21e [ 0.304927] [<ffffffff80801666>] mount_root+0x1e8/0x218 [ 0.305012] [<ffffffff808017d8>] prepare_namespace+0x142/0x184 [ 0.305089] [<ffffffff80800ffc>] kernel_init_freeable+0x1ee/0x20a [ 0.305236] [<ffffffff8064a20c>] kernel_init+0x1e/0x10a [ 0.305330] [<ffffffff800030b6>] ret_from_exception+0x0/0xc [ 0.305938] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,0) ]--- QEMU: Terminated
- QEMU 5.0.0
QEMU 5.0.0のときは、そもそも-bios
オプションがないと怒られてしまった。
QEMU emulator version 5.0.0 Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
$ qemu-system-riscv64 -nographic -machine virt -kernel linux/arch/riscv/boot/Image -append "root=/dev/vda ro console=ttyS0" -drive file=busybox/busybox,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
qemu-system-riscv64: warning: No -bios option specified. Not loading a firmware. qemu-system-riscv64: warning: This default will change in a future QEMU release. Please use the -bios option to avoid breakages when this happens. qemu-system-riscv64: warning: See QEMU's deprecation documentation for details. QEMU: Terminated
そこで、一応確認のためにOpenSBIをダウンロードしてビルドし、QEMUブート時に読み込んでみる。
make CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image
QEMU 5.0.0での試行だが、やはりまだうまく行かない。もう少し調べてみよう。
qemu-system-riscv64 -nographic -machine virt -bios opensbi/build/platform/generic/firmware/fw_payload.bin -drive file=busybox/busybox,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 [ 0.273957] Hardware name: riscv-virtio,qemu (DT) [ 0.274229] Call Trace: [ 0.274524] [<ffffffff80004a28>] dump_backtrace+0x1c/0x24 [ 0.274711] [<ffffffff80640dda>] show_stack+0x2c/0x38 [ 0.275024] [<ffffffff80645df8>] dump_stack_lvl+0x40/0x58 [ 0.275156] [<ffffffff80645e24>] dump_stack+0x14/0x1c [ 0.275289] [<ffffffff806410e6>] panic+0x106/0x2b0 [ 0.275465] [<ffffffff808013cc>] mount_block_root+0x16c/0x21e [ 0.275609] [<ffffffff80801666>] mount_root+0x1e8/0x218 [ 0.275963] [<ffffffff808017d8>] prepare_namespace+0x142/0x184 [ 0.276155] [<ffffffff80800ffc>] kernel_init_freeable+0x1ee/0x20a [ 0.276282] [<ffffffff8064a20c>] kernel_init+0x1e/0x10a [ 0.276417] [<ffffffff800030b6>] ret_from_exception+0x0/0xc [ 0.277147] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]--- QEMU: Terminated