QEMU with RISC-V

Using QEMU to emulate RISC-V hardware.

Setting up QEMU for RISC-V

I use Ubuntu on my workstation at home, so, the logical choice for emulating RSIC-V is to use QEMU. Below is the instructions of how I set this up.

Install QEMU with apt: sudo apt-get install opensbi qemu-system-misc u-boot-qemu

Download the RISC-V RISC-V preinstalled server image for RISC-V QEMU from Ubuntu 23.10.1

Unpack the image file: xz -dk ubuntu-23.10-preinstalled-server-riscv64.img.xz

To increase the image disk size: qemu-img resize -f raw ubuntu-23.10-preinstalled-server-riscv64.img +5G

Use u-boot-qemu to boot the virtual machine from the image you just downloaded:

qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 4 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -device virtio-rng-pci -drive file=ubuntu-23.10-preinstalled-server-riscv64.img,format=raw,if=virtio

The virtual Ubuntu 23.10 RISC-V instance will now boot. The default username and password are both set to ubuntu

Once logged in we need to update the OS: sudo apt update followed by sudo apt full-upgrade

using sudo apt install we need to install some tools. I will install vim, htop, plocate, linux-tools-common, cmake, gfortran and build-essential

Mission Accomplished

And there we have it, you now have a functining RISC-V LINUX computer to start playing with.