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

Installing Pre-requisites

Following command can be executed to install all software necessary for this tutorial:

sudo apt install build-essential libncurses-dev rsync git ninja-build libglib2.0-dev libpixman-1-dev bison flex libssl-dev 

Prepare a working directory:

mkdir && cd

This will be considered as the root working directory for this tutorial.

Installing Toolchain

Buildroot is a software package that can generate necessary tools for cross compiling code base for embedded Linux. This tutorial will use version v2022.05.2.

# Download the file

# Extract from compressed file
tar xf buildroot-2022.05.2.tar.gz

tar parameters:

  • x = Extract files
  • f = Use archive file
cd buildroot-2022.05.2

# To generate toolchain configuration file
make menuconfig

Select the following options:

  1. Target options
    1. Target Architecture > RISCV
    2. Target Architecture Size > 64-bit
  2. Toolchain
    1. C library > musl
    2. Kernel Headers > Linux 5.17.x kernel headers
    3. Binutils Version > binutils 2.38
    4. GCC compiler Version > gcc 11.x

Exit and save the configuration. Build the toolchain:

make sdk -j$(nproc)
  • -j$(nproc) = $(nproc) will expand to number of available processing units, -j flag will paralellize build utilizing the output indicated by $(nproc)

The output is the file output/images/riscv64-buildroot-linux-musl_sdk-buildroot.tar.gz. Extract it:

# Create a toolchain directory for toolchain extraction
cd ..
mkdir toolchain && cd toolchain

tar xf ../buildroot-2022.05.2/output/images/riscv64-buildroot-linux-musl_sdk-buildroot.tar.gz

All the important binaries are now in riscv64-buildroot-linux-musl_sdk-buildroot/bin directory. The RISC-V compier is riscv64-linux-gcc. Fix the hardcoded paths by running the script:


Place the binaries in system path:

# Go to the working directory
cd ..

# Create a script to update system path
gedit &

Write the following in the file:

export PATH=~/$PATH

Update environment variable by running the script using source & test:

riscv64-linux-gcc --version

It presented the version as follows:

riscv64-linux-gcc.br_real (Buildroot 2022.05.2) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

This confirms that the necessary toolchain has been installed and added to the system path.

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