Running U-Boot & Linux Kernel in QEMU



The build system of Linux kernel for RISC-V requires one more environment variable. Let's set it first. From the root working directory, run the following commands:

echo "export ARCH=riscv" >>

Build Linux Kernel

Let's download and build Linux kernel from source code. Linux v5.19.10 will be used for this tutorial. Run the following from the root working directory:

# Download the compressed file that contains Linux source code

# Extract and enter into directory
tar xf linux-5.19.10.tar.xz
cd linux-5.19.10/

Linux kernel will be built for RISC-V architecture. The default configurations for several targets can be obtained by the command below:

make help | grep defconfig --color=always

The default configutation, defconfig, is good enough so let's build it:

# Generate .config file
make defconfig

make -j$(nproc)

Did it Compile for RISC-V?

Search the .config file for the presence of RISC-V:

grep --color=always -ni 'riscv' .config
  • --color=always = Make the foreground color different for search terms
  • n = Mention line number
  • i = Ignore case
  • 'riscv' = Pattern to search for
  • .config = Name of the file to search

Observe that the RISC-V configuration option is enabled:


This happens because of the environment variable ARCH is set to riscv. It is used when the .config file was generated. The details can be found by opening the Makefile:

gedit ./Makefile &

and searching for ARCH and CROSS_COMPILE.

Output Files

List the output files:

ls arch/riscv/boot -lSh
  • l = List details
  • S = Sort by file size in descending order
  • h = Print the sizes in easily readable format (using K/M/G for Kilo/Mega/Giga when appropriate)

The files Image and Image.gz are the build files. Image.gz is the compressed form of Image.

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