Adding RISC-V 64-bit Support to Buildroot

Background

I have been working on adding RISC-V 64-bit architecture support to Buildroot.

Buildroot is an embedded Linux build system that generates complete system images from source for a wide range of boards and processors. Buildroot uses makefiles and is configured using the kernel kconfig language. If you have ever configured and built a Linux kernel from source you will find the interface very familiar.

Status of RISC-V Software

As with any embedded Linux system there are a number of choices to be made regarding which component ‘parts’ to use; tool chain, C library, bootloader, kernel, … etc. Sometimes these choices are made for you based on existing platform or feature support, sometimes choice is down to personal preference and sometimes the choice is partially dictated by which components or versions ‘play nicely’ together. In the case of RISC-V a number of the component parts are still evolving and have not yet been upstreamed, so this seriously restricts the range of options to choose from.

Support for RISC-V has been available in gcc since version 7.1, so the Buildroot default 7.x or 8.x gcc versions can be used without any modification. However GNU binutils needs to be 2.30 or greater in order for the kernel to build correctly.

Buildroot offers support for three C libraries (uclibc-ng, musl and glibc), however only glibc is available upstream with RISC-V support…so no choice to be made here.

RISC-V kernels currently use the Berkeley Boot Loader (BBL) to load and boot the image. The kernel vmlinux file needs to be merged with the BBL code during the BBL build process. BBL is not currently available under Buildroot, so I added it as a bootloader package.

The RISC-V architecture has been supported in the mainline kernel from v4.15 onwards, however the upstream kernels won’t yet boot under QEMU. The latest updates in the riscv-linux repository to support QEMU are expected to be included in the 4.19 mainline kernel release. Buildroot offers flexible options for building custom kernels, so configuring a build from the riscv-linux git repository was straightforward. Building the riscv-linux-4.15 branch worked without any problems. I also added the ability for Buildroot to build tool chains against custom kernel headers. This allows a tool chain to be built without having to build a kernel.

Buildroot Modifications

The modifications made to Buildroot fall into three areas:

1. Add RISC-V configuration options

These changes allow the user to select and configure the appropriate RISC-V settings which are then used to set the correct internal Buildroot build variables.

2. Add riscv-pk (BBL) package

The RISC-V PK (Proxy Kernel) package was added as a bootloader to provide BBL. When selected, this will build a bootable ‘bbl’ image using the kernel vmlinux file as a payload.

3. Add a QEMU default configuration

A default configuration was added that will build a bootable system for riscv64 on a QEMU virtual machine. This configuration has been tested under QEMU version 2.12.1.

A patch set has been submitted to the Buildroot mailing listIn the meantime, a fully patched version based on Buildroot 2018.08-rc1 is available from the riscv-start branch of the RISC-V repository on GitHub.

Using Buildroot for RISC-V

Check the Buildroot system requirements to ensure that you have the necessary host packages installed.

Get the riscv-buildroot repository

cd ~
git clone https://github.com/riscv/riscv-buildroot
cd riscv-buildroot
git checkout riscv-start

Set the default configuration

make qemu_riscv64_virt_defconfig

Configure any additional options or packages (if required)

make menuconfig

Build the system

make

Boot the image under QEMU

qemu-system-riscv64 -M virt -kernel output/images/bbl -append "root=/dev/vda ro console=ttyS0" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic

 

QEMU boot text
Booting under QEMU

The login username is ‘root’ with no password.

Summary

RISC-V 64-bit support has been added to Buildroot and can be evaluated with QEMU by following the instructions above. The system can also be used to build a standalone tool chain for other development work.

Please get in touch if you have any questions regarding RISC-V support for Buildroot, or if you would like to know more about our range of Embedded OS services and world-class compiler technology.