Running U-Boot & Linux Kernel in QEMU


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content


The CROSS_COMPILE environment variable needs to be defined to the prefix of the RISC-V gcc toolchain name that's added to the path. U-Boot build system will use this variable to correctly indentify the toolchain needed.

The script below will append the line at the end of and make it available. Execute the following from the root working directory:

echo "export CROSS_COMPILE=riscv64-linux-" >>

Build U-Boot

Download Source Code

This tutorial will use U-Boot v2023.07.02. From the root working directory, run the following in the terminal:

# Download U-Boot source
git clone

# Checkout required version
cd u-boot
git checkout v2023.07.02

Board Configuration Files

U-Boot needs to be built for the hardware on which it will run. U-Boot needs to know what's available in the hardware side (device tree) and how to use them (drivers). Each hardware configuration is different. U-Boot source tree has configuration file specific to each of the hardware that U-Boot supports. These files are also referred as board configuration file. Support for additional hardware can be made by creating separate board configuration file.

Find Architecture Specific Configuration Files

This part isn't mandatory if the board configuration file is known.

U-Boot stores board specific configuration files in the configs directory. Let's list available configuration files for RISC-V:

ls configs | grep riscv --color=always
  • --color=always = Make the foreground color different for search terms

This generates the following output:


A QEMU simulated board will be chosen, with RISC-V 64 bit architecture capable of running Linux. qemu-riscv64_smode_defconfig will serve the purpose of this tutorial. The S-Mode (supervisor mode) configuration is chosen so that it can load Linux kernel.


The command to build is:

# To generate .config file out of board configuration file
make qemu-riscv64_smode_defconfig

# To build U-Boot
make -j$(nproc)


The U-Boot binary is located at ./u-boot.bin.

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content