RISC-V initializes, not QEMU (2023)

For reference, I wanted to check howqemuboots RISC-V Linux. loose after aguide, I describe how to create and boot a Linux environment targeting the 32-bit RISC-V architecture.

We need three things:

  • QEMUthe emulator
  • kernels make linux
  • Root file system with some binaries

I'm wearing a custom againriscv-gnu-toolchainI have previously built that targets the RV32IMA architecture. It's easier to target 64-bit machinesriscv64-linux-gnu-Cross compiler toolchain with thegcc-riscv64-linux-gnuUbuntu package, use a different one in this case$CCPREFIX. Unfortunately, the 32-bit toolchain was not available in my package repositories.

we will usebusy boxas the set of binary files that make up the bulk of the root file system.
Build attempts lead to: make[2]: /home/juraj/buildroot-2020.02/output/host/bin/riscv32-buildroot-linux-gnu-gcc: Command not found

(optional) tool chain

To build everything use theriscv-gnu-toolchainbuilt with

./ furnish--Prefix=/opt/riscv32--with-arch=rv32ima--com-abi=ilp32dmake linux

QEMU structure

Since Ubuntu 20 ships with a fairly old version of QEMU (4.2.1 vs 5.2.0 stable), I built it from source using the following commands:

git clone --profundidad 1 --branch v5.2.0 https://github.com/qemu/qemucd qemu./configure --target-list=riscv32-softmmu,riscv64-softmmumake -j $(nproc)sudo make install
(Video) Enabling RISC-V Development with QEMU

after that i finishedqemu-sistema-riscv32miqemu-sistema-riscv64binary

Note: I had to install additional build dependencieslibglib2.0-dev libpixman-1-devin my system

Construction core:

Building the Linux kernel is almost the same as inprevious post. if we leave them outvmlinuxaspire todo, the compilation results in an additional filearch/riscv/boot/ImageIt will be built.

build command:

git-clon--Depth1- She isv5.10 https://github.com/torvalds/linux.git linux-v5.10ExportRISCV=/opt/riscv32ExportFAR=$RUTA:$RISCV/ContainerExportCC PREFIX=riscv32-desconocido-linux-gnu-makeARCO=RiskCROSS_COMPILE=$CCPREFIXdefconfig# Configuration changesdo-J psnproz) ARCO=RiskCROSS_COMPILE=$CCPREFIX

Note: When I was playing around with the 64-bit version and trying to make the kernel build simpler, I noticed that I can't have a combination of non-FPU kernel and standard busy frame build because Linux has all processes will stop trying to use FPU instructionsdescribed in this edition.

Root file system with busybox

To do something in the resulting system we need aBeginScript, a shell and some binaries to play with. Busybox is a great tool for embedded Linux as it can meet these needs.

build a career

First we compile busybox to ourrisk32Meta:

Occupied box options:

(Video) Developing the RISC-V Hypervisor Extensions in QEMU - Alistair Francis, Western Digital

ExportCC PREFIX=riskv32-unknown-linux-gnu-CROSS_COMPILE=$CCPREFIXmake defconfigCROSS_COMPILE=$CCPREFIXmake menu settings# Here I enabled the static binary in Settings->Build optionsCROSS_COMPILE=$CCPREFIXdo-J psnproz)

create file system

We have two options:

  1. Create the busybox image manually and prepare oneext2Image that we will attach as a virtual disk
  2. Create a root file system withbuildroot- Watch theprevious postfor more details.

To prepare the ext2 file system manually Create the busybox image with:

ddcon=/dev/nullVon=busy-box.binbs=1Msay=32mkfs. ext2-Fbusy-box.binmkdirmntsudoarmsbucle busybox.bin mntCDmntsudo mkdir -PAGEbin, etc. dev lib proc sbin tmp usr usr/bin usr/lib usr/sbinsudo cp~/Busy-Box/bin-Busy-Boxsudo-ln -S../bin/busybox sbin/initsudo-ln -S../bin/busybox bin/schCD..sudoquantity quantity

Note: This was the onlyIt does not workon my WSL box, so I plugged in a Raspberry Pi as a dedicated imager.

The file system looks like this:

psBaum.|--bin| |-- busy field|`--sh -> ../bin/busybox|--dev|--etc|--lib|--lost+found[Failed to opendirectory]|--proc|--sbin|`--init -> ../bin/busybox|--tmp`--usr |-- container |-- library`--out
(Video) RISC-V Core Timer Interrupt Generation


to startext2Image version:

qemu-sistema-riscv32-nographic \ -Machinevirtue\ -Kernlinux-v5.10/arch/riscv/boot/Imagen\ -add "raíz=/dev/vda rw consola=ttyS0 earlycon=sbi keep_bootcon bootmem_debug" \ -lead archive=busybox.bin, Format=ugly id=hd0\ -DeviceVirtio blk device, drive=hd0

In this case, finish the "installation" of busybox after booting with:

```/bin/busybox –install -smount -t proc proc /proc

Para la versión `initramfs`:```shqemu-system-riscv32 -nographic \ -machine virt \ -kernel linux-v5.10/arch/riscv/boot/Image \ -append "console=ttyS0 earlycon=sbi keep_bootcon bootmem_debug "\

To make the message nicer, use:

Exportps1='$(whoami)@$(hostname):$(password)$ '
(Video) QEMU RV32I Installation & Setup

The initial departure

[ 0.000000][ T0] Version of Linux 5.10.0 (juraj@DESKTOP-26O5AT9) (riscv32-unknown-linux-gnu-gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35) #9 Saturday May 3 April 19 :59:26 CEST 2021[ 0.000000][ T0] OF: fdt: Omitir memoria range 0x80000000 - 0x80400000[ 0.000000][ T0] earlycon: sbi0 in the I/O port 0x0 (opciones '')[ 0.000000 ][ T0 ] printk: bootconsole [sbi0] enabled[ 0.000000][ T0] printk: debug: Ignorar el registrie de la console de activación.[ 0.000000][ T0] Zone ranges:[ 0.000000][ T0] Normal [mem 0x00000000080400000 -0x0000000087ffffff][ 0.000000] Móvel [T0] zona Start for each knot [0.000000] [T0] Early memory node areas [0.000000] [T0] Knot 0: [MEM 0x00000080400000-0x000087ffff] [0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000. 0 total pages: 31744 [0.000000] [T0] normal zone: 248 pages used for memmap [0.000000] [T0] normal zone: 0 reserved pages [0.000000] [T0] normal zone: 31744 pages, LIFO batch: 7 [ 0.000000] [T0] SBI v0.2 specification detected[ 0.000000][ T0] SBI implementation ID=0x1 version=0x9[ 0.000000][ T0] SBI v0.2 TIME extension detected[ 0.000000] [ T0] SBI v0.2 IPI extension detected [ 0.000000][ T0] SBI v0.2 RFENCE extension detected[ 0.000000][ T0] riscv: ISA extensions acdfimsu[ 0.000000][ T0] riscv: ELF functions acdfim[ 0.000000][ T0 ] pcpu-alloc : s0 r0 d32768 u32768 alloc = 1*32768[ 0.000000][ T0] pcpu-alloc: [0] 0[ 0.000000][ T0] Zone lists 1 built, mobility group enabled. Total pages: 31496[0.000000][T0] Kernel command line: root=/dev/vda rw console=ttyS0 earlycon=sbi keep_bootcon bootmem_debug[0.000000][T0] Dentry cache hash table entries: 16384 ( order: 4, 65536 bytes, lineal)[ 0.000000][T0] Inode cache hash table entries: 8192 (order: 3, 32768 bytes, lineal)[0.000000][T0] sort __ex_table...[0.000000][ T0] mem auto-init: stack: off , heap alloc:off, heap free:off[ 0.000000][T0] Memory: 104624K/126976K available (1769K kernel code, 8179K rwdata, 4096K rotata, 108K init, 196K bss, 22352K reserved, 0K cma-reserved)[0 , 000000 ][ T0] Design of the virtual memory of the kernel:[ 0.000000][ T0] Correction map: 0x9dc00000 - 0x9e000000 (4096 kB)[ 0.000000][T0] pci io: 0x9e000000 - 0x9F0000000:00T0:00MA0000:0 0.000F0:0 [0.000F0:16 MB] 009 0x9FFFFFF (15 MB) [0.000000] [T0] VAMALOC: 0xa0000000 - 0xBFFFFFF (511 MB) [0.000000] [T0] 0X000M 0XC7C00040 MB [0.12000] UB0] [0.00UB0] 4 -3.0UB0] MinObject s = 0, CPU = 1, Nodes = 1 [ 0.000 000][ T0] IR_NR S: 64, IR_nr: 64, preassigned IRQ: 0 [ 0.000000] [ T0] riscv-intc: 32 local interrupts assigned [ 0.000000] [ T0] plic: plic@c000000: hat 53 interrupts with 1 controller assigned to 2 contexts. [0.000000] [T0] RISCV_TIMER_INIT_DT: Register the clock source CPUID [0] Hartid [0.000000] [T0] Clock source: MASKE: 0xffffffffff MAX_CYCles: 0x710.6a, max_idle_ns: 440795202120 NS [0,0001 T6909][ ] Resolution 1 sends each 4398046511100ns[ 0.013650][ T0] Console: dummy device color 80x28[ 71 T-loop][ 71 Calibration delay (ignored) calculated according to the frequency of the timer. ] pid_max: default: 32768 minimum: 301[ 0.048164][ T0] assembly cache hash table entries: 1024 (order: 0, 4096 bytes, lineal)[ 0.055777][ T0] assembly cache hash Table entries Setup point cache: 1024 (sort: 0, 4096 bytes, linear)[ 0.102432][T1] devtmpfs: initialized[ 0.116366][T1] random: get_random_u32 called from Bucket_table_alloc.isra.0+0xf 4/0x12c with crng_init= 0 [ 0.117545][T1] clocksource: jiffies : mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns[ 0.137281][ T1] table entries hash futex: 256 (order: 0, 7168 bytes, linear) [ 0.5 ] Clocksource : Switched to Clocksource riscv][_clocksource[ 0.4 T51 51 ] Workset: timestamp_bits=30 max_order=15 Bucket_order=0[0.562703][T1] Serial: 8250/16550 controller, 4 ports, IRQ sharing disabled[0.581022][ T1 ] printk: console [ttyS0] out[0.588014][ T1 ] 10000000.uart: ttyS0 at MMIO 0x10000000 (irq = 2, baud_base = 230400) is a 16550A[0.598528][T1] printk: console [ttyS0] also known as enabled [0.598528][T1] printk: console [ttyS0] enabled[0.615181][T1] goldfish_rtc 101000.rtc: registered as rtc0[0.615181][T1] goldfish_rtc 101000.rtc: registered as rtc0[0.627517][T1] goldfish_rtc 101000 .rtc: configure the system clock on 2021-04-03T18:01:21 UTC (1617472881)[ 0.627517][ T1] goldfish_rtc 101000.rtc: configure the system clock on 2021- 04-03T18:01:21 UTC (1617472881) [ 0.647673 ][ T1] syscon-poweroff soc:poweroff: pm_power_off ya claimed (ptrval) sbi_shutdown[ 0.647673][ T1] syscon-poweroff soc:poweroff: pm_power_off ya claimed (ptrval) sbi_shutdown[ 0.664166][ T1] syscon -poweroff: soc:poweroff test fails with error -16 [0.664166] [T1] syscon-poweroff: soc:poweroff test fails with error -16 [0.678325] [T1] debug_vm_pgtable : [debug_vm_pgtable]: validation of the support architecture pages of the debugging table [ 0.678325] [T1] debug_vm_pgtable: [debug_vm_pgtable]: Validation of and helpers for architecture page tables[0.731573][T1] Free unused kernel memory: 108 KB [0.731573] [T1] Free unused kernel memory: 108 KB [0.742780] [T1] Run /init as initial process [0.742780] [T1] /init como Execute the initial process [0.750353] [ T1] with arguments:[ 0.750353][ T1] with arguments:[ 0.756067][ T1] /init[ 0.756067][ T1] /init[ 0.763349][ T1 ] bootmem_debug[ 0.763349][ T1 ] bootmem_debug[ 0.769977][ T1 ] with surroundings:[0.769977][T1] with surroundings:[0.776713][T1] HOME=/[0.776713][T1] HOME=/[ 0.782869][T1] TERM=linux[0.782869] [T1] TERM=linuxStarting syslogd: OKStarting klogd: OKExecuting sysctl: OKSaving random semilla: [2.076275][T47] random: dd: uninitialized urandom reading (512 bytes read)[2.076275 ][T47] random: dd: reading urandom not initialized (512 bytes read)OKStarting network: ip : socket: function not implementedip: socket: function not implementedFAILBienvenido a Buildrootbuildroot login: rootbuildro ot login: rootlogin[116]: root login to console# uname -aLinux buildroot 5.10.0 #10 Sa Apr 3 20:29:29 CEST 2021 riscv32 GNU/Linux# cat /proc/cpuinfoprocessor : 0hart : 0isa : rv32imafdcsummu : sv32

Running a real Linux distribution

QEMU documentation for your RISC-V platformAn examplewhen running Fedora Linux.

First you need to download the images and then run:

qemu-sistema-riscv64\ -nographic \ -Machinevirtue\ -smp4\ -METRO2G\ -KernFedora-Minimal-Rohleder-*-fw_payload-uboot-qemu-virt-mode.Elf\ -BIOSnone\ -Objectrng-random, filename=/dev/urandom,id=rng0\ -Devicevirtio-rng-device,rng=rng0\ -DeviceVirtio blk device, drive=hd0\ -lead archive=Fedora-Minimal-Rawhide-20200108.n.0-sda.raw, formato=ugly id=hd0\ -DeviceVirtio-Net Device, Netdev=user network\ -netdevBenutzer Identification=user network , hostfwd=TCP::10000-:22

The login prompt takes about a minute and a half to start on my i5 6300U.

Login as user "riscv" with password "fedora_rocks!"

I like Buildroot better

With buildroot, it's definitely easier to get comfortable with a working system. I built other tools likemicropythonto be able to play with the final result. The workflow for building the entire system on a ramdisk is also quite simple.


1. Message of Linus Torvalds to Risc-V
2. Initializing RISC-V: A Guided Tour for ARM Developers
3. You Can Learn RISC-V Assembly in 10 Minutes | Getting Started RISC-V Assembly on Linux Tutorial
(Low Level Learning)
4. QEMU #2: How to create a VM initialization script
(Pavol Elsig)
5. LLC 2022 - Free RISC-V Systems: Benefits and Status of QEMU, by Alistair Francis
(Lund Linux Conference)
6. Linux on RISC-V and the New OS-A Platform - Drew Fustini, BayLibre
(The Linux Foundation)


Top Articles
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated: 04/29/2023

Views: 5836

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.