天天看點

QEMU 5.2 for RISC-V,啟動Linux Kernel的參數

BuildRoot 2020.02.10中的RISC-V 64的預設模拟器是QEMU4.2.0,其啟動參數可以在board/qemu/riscv64-vir/readme.txt中看到,内容如下:

Run Linux in emulation with:

qemu-system-riscv64 -M virt -kernel output/images/fw_jump.elf \
    -device loader,file=output/images/Image,addr=0x80200000 \
    -append "rootwait root=/dev/vda ro" \
    -drive file=output/images/rootfs.ext2,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -netdev user,id=net0 -device virtio-net-device,netdev=net0 \
    -nographic

The login prompt will appear in the terminal that started Qemu.

Tested with QEMU 3.1
           

經測試,BuildRoot自帶編譯輸出的QEMU 4.2.0,使用上述參數能夠正常輸出啟動log,運作正常。

但是目前QEMU官方最新的QEMU版本是QEMU 5.2.0,使用上述參數進行啟動,則無法正常啟動,QEMU會報錯。檢視QEMU官方ChangeLog可以看到,QEMU 5.2.0開始,模拟器内部內建了OpenSBI,是以上述啟動參數會無法正常工作。修改啟動參數如下,則QEMU可以正常啟動。

qemu-system-riscv64  -M virt  -kernel output/images/Image \
    -append "rootwait root=/dev/vda ro" \
    -drive file=output/images/rootfs.ext2,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -netdev user,id=net0 -device virtio-net-device,netdev=net0 \
    -nographic
           

經後續分析,QEMU 5.2.0使用BuildRoot編譯出的OpenSBI和Linux Kernel,運作方法如下:

qemu-system-riscv64 -M virt -bios output/images/fw_jump.bin \
    -kernel output/images/Image -append "rootwait root=/dev/vda ro" \
    -drive file=output/images/rootfs.ext2,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic
           

更新網卡,使用tap參數啟動:

qemu-system-riscv64 -M virt -nographic \
    -bios output/images/fw_jump.bin \
    -kernel output/images/Image -append "rootwait root=/dev/vda ro" \
    -drive file=output/images/rootfs.ext2,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -netdev tap,id=net0,ifname=qemutap,script=no,downscript=no \
    -device virtio-net-device,netdev=net0 
           

繼續閱讀