Written by Antmicro
The Zephyr RTOS most often powers MCUs with hundreds of supported platforms, taking the primary, user-facing role. But its versatility makes it a great fit for other, perhaps less obvious roles, both as a supporting OS in a heterogeneous setups and – as in the use case described below – as part of the boot flow of more capable devices.
Application processors like the FU740 found in the RISC-V-based HiFive Unmatched development board typically require a somewhat more involved boot flow than MCUs, where the main operating system like Linux is preceded by one or more bootloaders. These provide some useful features like easy boot medium selection, the ability to pass different boot arguments and root filesystems for the main OS or modify the loaded binaries.
While not a bootloader in and of itself, Zephyr is lightweight and packed with features, and given that it already supports HiFive Unmatched and many other application-class platforms (not only RISC-V, but also x86 and ARM64), using it as a versatile, permissively licensed bootloader feels like a natural choice. This presents interesting potential in scenarios like Over-the-Air updates with A/B images we describe in a previous blog, and seamlessly extends into scenarios where Zephyr acts as a hypervisor, e.g. in the automotive sector. There, a single computing platform can use an RTOS to run critical safety systems, and say, Android for infotainment.
To explore this potential, Antmicro is currently working on adding Zephyr as a Linux bootloader for the HiFive Unmatched platform, potentially followed by others in the future. This note describes the early stages of this R&D effort, focusing on its first completed milestone, revolving around adding support for the ext2 filesystem in Zephyr. The README file in this repository also includes all instructions you need to install the necessary dependencies, build the relevant binaries and run a demo.
Substituting the default boot process
The simplest boot process for HiFive Unleashed consists of the following stages:
- ZSBL (Zeroth Stage Boot Loader) – program in the ROM that determines (using MSEL pins) where to look for FSBL
- FSBL (First Stage Boot Loader) – initializes clocks, UART, DDR memory, and Ethernet, loads binaries needed in the next stage and jumps to it
- OpenSBI – provides a Supervisor Binary Interface for the OS to be started
- OS – Linux
The aim of this project is to substitute this process in order to use Zephyr in the roles of both FSBL and SBI, so that it can boot Linux on its own, and currently we are able to replace FSBL, with work on SBI support still ongoing.
DDR controller and ext2 filesystem support
The first milestone was to add support for the DDR memory in the Zephyr kernel which initializes the memory, since support for the clocks and UART for the board is already a part of Zephyr and support for Ethernet is not essential to running Linux. In order to do this, we added the missing drivers, which are already merged into mainline Zephyr.
After initializing the necessary hardware, the FSBL needs to load binaries in order to prepare the next boot stage. These binaries are loaded from an ext2 partition on an SD card, which naturally requires Zephyr to support the ext2 filesystem. The initial support is now in the process of being merged into Zephyr, which will allow us to mount ext2 filesystems from disks accessed via the `disk_access` interface. Thanks to this, in the current state, Zephyr FSBL is able to successfully load the original OpenSBI and then Linux.
Below you can see a log from a booting process using the Zephyr FSBL:
Next: Zephyr SBI
With the hardware initializing and binaries loading as intended, the project is now moving on to work on the next boot process stage. Our goal here is to implement a Zephyr SBI application which will be able to implement the Supervisor Binary Interface for Linux, working together with Zephyr FSBL to boot the OS by using Zephyr alone. This will allow the users to have more control over the entire boot process, taking advantage of the interactivity provided by Zephyr’s built in console.
Develop your Zephyr RTOS and RISC-V solutions with Antmicro
Through efforts like the one described in this note, Antmicro strives to bring closer the two open source ecosystems of RISC-V and Zephyr, for complete transparency of both hardware and software.
If you are interested in taking advantage of the features Zephyr offers or developing comprehensive software/hardware RISC-V-based solutions, reach out to us at contact@antmicro.com. You can also talk to us in person at our booth during the Zephyr Developer Summit, taking place on June 27-30 in Prague as part of the first-ever Embedded Open Source Summit (EOSS). Join Antmicro’s keynote as well as a joint talk with Silicon Labs to learn more about our recent developments in the Zephyr ecosystem.