Running U-Boot & Linux Kernel in QEMU


The OpenSBI firmware that loads U-Boot in QEMU - all executables are ready now.

Let's create a script file for executing QEMU. From the root working directory, run the following:

cd qemu/
gedit &

Write the following in the

#! /usr/bin/bash

./build/qemu-system-riscv64 -smp 2 \
-m 1G \
-nographic \
-machine virt \
-bios ../opensbi/build/platform/generic/firmware/fw_payload.elf

Note that this is a multiline script. Each line should end with a backslash (\) for continuation.

Save & close the file. Meaning of the QEMU parameters are as follows:

  • smp = Number of processing units
  • m = Total memory
  • nographic = Graphics less environment
  • machine = Specify the machine QEMU will emulate, here QEMU virt machine for RISC-V will be used
  • bios = Path to the bios file

Make the script file executable:

chmod +x

The system can now be run by the following command:


By observing the console output, it can be seen that OpenSBI and U-Boot are loaded and being executed. Here's part of the output on the test machine that shows that U-Boot is running:

U-Boot 2022.10-dirty (Mar 14 2023 - 11:56:56 +0000)

CPU:   rv64imafdch_zicsr_zifencei_zihintpause_zba_zbb_zbc_zbs_sstc
Model: riscv-virtio,qemu
DRAM:  1 GiB
Core:  26 devices, 12 uclasses, devicetree: board
Flash: 32 MiB
Loading Environment from nowhere... OK
In:    [email protected]
Out:   [email protected]
Err:   [email protected]
Net:   No ethernet found.
Hit any key to stop autoboot:  0 

Device 0: unknown device
scanning bus for devices...

Device 0: unknown device
No ethernet found.
No ethernet found.

QEMU can be exited by pressing Ctrl+A followed by X.

A Little More on U-Boot

=> is the default U-Boot prompt. U-Boot is ready to take commands. Type help and press Enter to see available commands. Try some of the commands and see U-Boot's responses. U-Boot will see the hardware that's provided by QEMU. Some commands to try:

  • cpu detail = Print detailed CPU information.
  • bdinfo = Print board specific information.
  • fdt print / = Print complete flattened device tree, this will list all hardware with all properties available in the system. The / indicates start from the root of the tree.
  • fstypes = File system types that U-Boot's current build supports.

On the tutorial machine, the bdinfo command reveals the following details about the board that QEMU has supplied to U-Boot:

=> bdinfo
boot_params = 0x0000000000000000
DRAM bank   = 0x0000000000000000
-> start    = 0x0000000080000000
-> size     = 0x0000000040000000
flashstart  = 0x0000000020000000
flashsize   = 0x0000000002000000
flashoffset = 0x0000000000000000
baudrate    = 115200 bps
relocaddr   = 0x00000000bff58000
reloc off   = 0x000000003fd58000
Build       = 64-bit
current eth = unknown
ethaddr     = (not set)
IP addr     = <NULL>
fdt_blob    = 0x00000000bf7367d0
new_fdt     = 0x00000000bf7367d0
fdt_size    = 0x0000000000001620
 memory.cnt  = 0x1
 memory[0]	[0x80000000-0xbfffffff], 0x40000000 bytes flags: 0
 reserved.cnt  = 0x2
 reserved[0]	[0x80000000-0x8003ffff], 0x00040000 bytes flags: 0
 reserved[1]	[0xbf735380-0xbfffffff], 0x008cac80 bytes flags: 0
devicetree  = board

It can be found that the RAM start address and size are 0x80000000 and 0x40000000 (1 GB) respectively. This information is important as various data are needed to be placed within this address range.

Create your playground on
This playground was created on, our hands-on, knowledge-sharing platform for developers.
Go to