[QEMU] Boot RISC-V with QEMU step by step

板子资源比较紧张,用qemu开发比较好,节约时间,也不用把文件拷来拷去,把这个过程在这里做一下记录。

1 compile qemu

./configure --target-list=riscv64-softmmu --disable-werror
make all

编译完成后我们可以在qemu source下的build下面找到qemu-system-riscv64,这个是我们的目标文件。

2 compile uboot/opensbi/kernel

RepositoryTypeContentCompile Command
opensbiopensbiRISC-V Open Source Supervisor Binary Interfacemake clean
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make PLATFORM=generic FW_PAYLOAD_PATH=…/u-boot/u-boot.bin -j$(nproc)
ubootU-BootDas U-Bootmake clean
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make qemu-riscv64_smode_defconfig
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make all
linuxLinux KernelLinux Kernelmake clean && make distclean
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make defconfig
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make all

3 boot with qemu

3.1 boot uboot with qemu

./build/qemu-system-riscv64 \
-M virt -nographic \
-bios output/images/fw_payload.elf

3.2 boot 64-bit Buildroot Images with qemu

Clone the Buildroot source code and cd into the directory.

git clone https://git.buildroot.net/buildroot

Generate the default config:

ARCH="riscv" CROSS_COMPILE="riscv64-linux-gnu-" make qemu_riscv64_virt_defconfig

Build the images

ARCH="riscv" CROSS_COMPILE="riscv64-linux-gnu-" make all

Boot the images:

./build/qemu-system-riscv64 \
-M virt -nographic \
-bios output/images/fw_jump.elf \
-kernel output/images/Image \
-append "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

3.3 boot Fedora with qemu

Download the Fedora prebuilt images from: https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/ You will want to download Fedora-Minimal-Rawhide-*-fw_payload-uboot-qemu-virt-smode.elf and Fedora-Minimal-Rawhide-*-sda.raw.xz images.

Decompress the rootFS:

unxz Fedora-Minimal-Rawhide-*-sda.raw.xz

Boot linux using RV64GC qemu:

./build/qemu-system-riscv64 \
-nographic \
-machine virt \
-smp 4 \
-m 2G \
-kernel ../Fedora-Minimal-Rawhide-*-fw_payload-uboot-qemu-virt-smode.elf \
-bios none \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-device,rng=rng0 \
-device virtio-blk-device,drive=hd0 \
-drive file=../Fedora-Minimal-Rawhide-*-sda.raw,format=raw,id=hd0 \
-device virtio-net-device,netdev=usernet \
-netdev user,id=usernet,hostfwd=tcp::10000-:22

3.4 boot Debian with qemu

Download the Debian prebuilt images from: Debian Sid You will want to download debian-riscv64-QemuVM-202002.tar.gz images.
uncompressed the tar package, you will get fw_payload.binriscv64-debianrootfs-qemu.qcow2.

./build/qemu-system-riscv64 \
-machine virt \
-nographic \
-smp 4 \
-m 4G \
-bios fw_payload.bin \
-device virtio-blk-device,drive=hd0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-device,rng=rng0 \
-drive file=riscv64-debianrootfs-qemu.qcow2,format=qcow2,id=hd0 \
-device virtio-net-device,netdev=usernet \
-netdev user,id=usernet,hostfwd=tcp::10000-:22

3.5 boot Ubuntu with qemu(调试中)

在这里,我们选择用一个ubuntu image作为我们的rootfs。
Ubuntu Focal
uncompressed the tar package, you will get fw_payload.binriscv64-UbuntuFocal-qemu.qcow2.

./build/qemu-system-riscv64 \
-machine virt \
-nographic \
-smp 4 \
-m 4G \
-bios fw_payload.bin \
-device virtio-blk-device,drive=hd0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-device,rng=rng0 \
-drive file=riscv64-UbuntuFocal-qemu.qcow2,format=qcow2,id=hd0 \
-device virtio-net-device,netdev=usernet \
-netdev user,id=usernet,hostfwd=tcp::10000-:22

===
未完待续

4 Reference:

  1. Documentation/Platforms/RISCV
  2. ‘virt’ Generic Virtual Platform (virt)
  3. SiFive HiFive Unleashed (sifive_u)
  4. Running U-Boot & Linux Kernel in QEMU
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山猫Show

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值