板子资源比较紧张,用qemu开发比较好,节约时间,也不用把文件拷来拷去,把这个过程在这里做一下记录。
1 compile qemu
./configure --target-list=riscv64-softmmu --disable-werror
make all
编译完成后我们可以在qemu source下的build下面找到qemu-system-riscv64
,这个是我们的目标文件。
2 compile uboot/opensbi/kernel
Repository | Type | Content | Compile Command |
---|---|---|---|
opensbi | opensbi | RISC-V Open Source Supervisor Binary Interface | make clean ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make PLATFORM=generic FW_PAYLOAD_PATH=…/u-boot/u-boot.bin -j$(nproc) |
uboot | U-Boot | Das U-Boot | make clean ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make qemu-riscv64_smode_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make all |
linux | Linux Kernel | Linux Kernel | make 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.bin
和 riscv64-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.bin
和 riscv64-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
===
未完待续