Run Debian RISC-V In QEMU: Virtual Environment For Assembly development

After a lot of research, I’ve discovered the simplest way to get a QEMU RISC-V Linux image running. This one will run Debian and it is far smaller than the Ubuntu one too so it will consume less memory on your main Linux (where you run QEMU).

Here are the simple steps:
1) go to Debian Quick Image Baker pre-baked images[^] — this contains all the latest build images for QEMU virtualization (including a RISC-V build.

2) When you get there, look for the link labeled: “Images for riscv64-virt” — clicking that link (Images for riscv64-virt[^]) will instantly begin the download of a (zip) file which is named very oddly, like a hash value (2baed3d2ab30e7a4ff39c7e587c8b16dce3885afb2dc047dae555a8bc13e is the current name).

3) Once you download it, you can unzip the contents to its own folder to keep everything organized.

The contents of that file are:
* image.qcow2 — image file
* initrd – linux stuff
* kernel – linux kernel
* readme.txt – readme provides command line for QEMU
* ssh_user_ecdsa_key — stuff I don’t know
* ssh_user_ed25519_key — don’t know
* ssh_user_rsa_key — don’t know.

The readme contains the QEMU command that you can use to start virtual environment.

The readme contains the QEMU command that you can use to start virtual environment.

We Need Two Additional Files

We actually need two additional files which are the bios and the kernel files for RISC-V Linux.

  1. fw_jump.elf
  2. uboot.elf

These files are part of the Open Source Supervisor Binary Interface.

For more information you can learn about them at :

GitHub – riscv-software-src/opensbi: RISC-V Open Source Supervisor Binary Interface[^]

Download uboot.elf & fw_jump.elf

You can actually download those two files and place them anywhere you want on your local computer.

RISC-V-Assembly-Language-Programming/Chapter 1/QEMU at main · Apress/RISC-V-Assembly-Language-Programming · GitHub[^]

Make sure that when you download each file that you download the RAW file.  GitHub does a weird thing and will download them as odd text files if you don’t use the RAW option.

Download To Your Local Machine

Just make sure you reference the full path to them (wherever you placed them on your machine) when you run the QEMU command below.

qemu-system-riscv64 -machine 'virt' \
-cpu 'rv64' \
-m 1G -device virtio-blk-device,drive=hd \
-drive file=image.qcow2,if=none,id=hd \
-device virtio-net-device,netdev=net \
-netdev user,id=net,hostfwd=tcp::2222-:22 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-object rng-random,filename=/dev/urandom,id=rng \
-device virtio-rng-device,rng=rng \
-nographic \
-append "root=LABEL=rootfs console=ttyS0"

Once you start the virtual environment login using :
root (username) and root (pwd)

Now you can install the build_essential packages so you can write assembly and link.
You are root so no need for sudo:
$ apt install build_essential

Once you do that. You can open up the nano editor and write your asm and go through the rest of the samples in the book (RISC-V Assembly Language Programming: Unlock the Power of the RISC-V Instruction Set[^]).

Leave a Reply

Your email address will not be published. Required fields are marked *