User Tools

Site Tools


riscv-qemu-debian

Install QEMU on your system. Follow the instructions at the official QEMU site^.

1) go to Debian Quick Image Baker pre-baked imageshttps://people.debian.org/~gio/dqib/ — 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 
   ssh_user_ed25519_key 
   ssh_user_rsa_key 

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.

  fw_jump.elf
  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 Interfacehttps://github.com/riscv-software-src/opensbi/tree/master 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 · GitHubhttps://github.com/Apress/RISC-V-Assembly-Language-Programming/tree/main/Chapter%201/QEMU

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.

You can see those two files are referenced in the QEMU command below.

Note: There cannot be any spaces after the line-continuation-character (\).

I've broken the command up over lines so you can see each argument which is passed to the QEMU executable. There is a separate EXE for each QEMU platform (riscv64, x86_64, etc.)

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: BAT

$ apt install build-essential

You can check that the Assembler (as) and the linker (ld) are installed after that, by doing the following which will give you the versions of each exe. BAT

$ as –version

$ ld –version

riscv-qemu-debian.txt · Last modified: 2025/02/03 17:40 by me