CC Blog • Design Solutions • Research & Design Hub

Experimenting with CHERI on the Sonata Board

Figure 1 An overview of the Sonata Board
Written by Colin O'Flynn

The CHERI extension for RISC-V provides a promising way of designing fundamentally secure systems. I introduced this back in November 2023, but at the time there was no easy hardware to work with. This article introduces the open-source hardware (OSHW) Sonata board, which lets you experiment with CHERIoT on a more user-friendly platform.

  • What is CHERI and how does CHERIoT differ?
  • How does the Sonata boardenable CHERIoT development?
  • What hardware features make the Sonata board unique?
  • How do compartments improve memory safety in embedded systems?
  • How do you build and load CHERIoT examples onto the Sonata board?
  • RISC-V
  • CHERI
  • CHERIoT
  • FPGA
  • Ibex core

  • CHERI Alliance | https://cheri-alliance.org 
  • Sonata | www.sunburst-project.org

Back in my November 2023 article in Issue #400 of Circuit Cellar I introduced you to the CHERI and CHERIoT architecture, which I presented as a promising way of securing your existing C/C++ code with minimal effort. At the time, I lamented that it was difficult to “get started” with CHERIoT, as it required you to build your own soft-core processor.

Since then, the Sunburst Project has released a board with prebuilt FPGA images, called the Sonata Board. While it’s still not as cheap as a simple microcontroller development kit, it has a similar development flow, only requiring you to compile code for the target. The project provides reference code, and the physical platform can be expanded with a variety of add-on boards (shields).

In this article, I’ll quickly remind you of what CHERIoT is, before showing you how you could use this with the physical system. The physical board is something I helped design, but the real effort behind Sonata is the FPGA work and the reference platform, which was developed by a team at lowRISC. The physical board is fully open-source, so you can build your own or modify it for specific tasks as you see fit.

What’s CHERI All About?

CHERI (Capability Hardware Enhanced RISC Instructions) is a computer architecture that brings fine-grained memory safety and isolation to hardware. It works by associating capabilities (pointers with bounds and permissions) to every memory reference, preventing programs from accessing memory they shouldn’t and enabling strong compartmentalization. In practice, this mitigates vulnerabilities such as buffer overflows and use-after-free bugs that account for a large share of security issues in C/C++ software.

CHERIoT (Capability Hardware Extension to RISC-V for Internet of Things) is a variant of CHERI designed for microcontrollers and small embedded systems. CHERIoT builds on CHERI and RISC-V to define a new 32-bit ISA and a microcontroller-focused RTOS that provides object-level spatial memory safety, deterministic use-after-free protection, and lightweight compartmentalization directly in the C/C++ programming model. If you want more details of this implementation, refer to the resources of this article, or my article in Issue #400 of Circuit Cellar.

What is Sonata?

At its heart, Sonata runs the CHERIoT Ibex core—a 32-bit RISC-V CPU core (Ibex) extended to support CHERI capabilities. Ibex is a small, efficient open-source core widely used in embedded designs, and the CHERIoT modifications add hardware support for CHERI’s tagged pointers, bounds-checking, and compartmentalization features. The system is designed to feel like a “normal” microcontroller but with built-in enforcement of memory safety and isolation. The Sonata SoC (implemented on the Sonata board’s FPGA) includes this CHERIoT-enabled CPU along with a suite of typical microcontroller peripherals and system components.

The Sonata board is shown in Figure 1. This looks like a normal sort of microcontroller development board, with the typical headers you might find on development boards. This board can fit a variety of off-the-shelf expansion boards including Arduino Shields, Raspberry Pi Hats, and others.

Figure 1 An overview of the Sonata Board
Figure 1
An overview of the Sonata Board

A block diagram of the board is shown in Figure 2, which illustrates the combination of FPGA-implemented microcontroller blocks along with the physical support circuitry on the board. Besides the Ibex core, which I already mentioned, it has a number of other peripherals worth discussing.

Figure 2
This diagram shows the various blocks on the Sonata Board, some of which are implemented inside the FPGA in a soft-core microcontroller.
Figure 2
This diagram shows the various blocks on the Sonata Board, some of which are implemented inside the FPGA in a soft-core microcontroller.

First, the system contains several types of memory. To start with, it includes 128KB on-chip SRAM with CHERI tag support (used for both instructions and data). Sonata also provides an external 8MB HyperRAM chip; the design allows executing code directly from HyperRAM with an instruction cache, which is useful for larger programs, though the external memory is slower. This HyperRAM can be thought of like flash memory in a typical microcontroller, larger but a little slower than accessing the SRAM.

Special features for the memory tag support are also needed. A hardware revoker unit is included to clear tags from memory as needed (for example, when memory is freed) to ensure deterministic use-after-free protection by preventing stale capabilities from being reused.

Besides these memories, more common microcontroller peripherals are also included. This includes multiple UARTs, SPI and I2C controllers, GPIOs, a timer, a PLIC interrupt controller, and even a USB device interface. Some of these SPI controllers are dedicated to specific board functions such as the LCD and Ethernet, but the soft-core nature of the FPGA means you can always adjust that if you want!

There’s also support for analog input via an ADC and PWM via dedicated controllers. All these peripherals are integrated into the CHERI-aware bus fabric, meaning their memory-mapped registers can be accessed through capabilities. In CHERIoT, device registers are typically exposed to software compartments via MMIO capabilities—a compartment’s import table will include only the device regions it should access. This allows hardware access to be controlled at the compartment level. For example, only a trusted driver compartment holds the capability for a certain GPIO port. This sort of security compartmentalization allows you to perform fundamental security improvements such as ensuring that compromised code from one interface cannot access another interface. Unlike with a OS or RTOS, this is enforced in hardware, and the granularity is such that even an exploit into privileged (or secure mode) code cannot bypass these protections.

Compared to some of the existing security solutions that have only, for example, a secure/privileged and a non-secure/user mode, the higher level of granularity in CHERIoT makes it natural to design compartments around individual subsystems or peripherals.

To feel like a “real” microcontroller, the Sonata system provides typical pin multiplexor logic as well. This allows you to reroute peripherals between various pins. One unique feature is dedicated CHERI exception LEDs that illuminate when a security violation (like a capability fault) occurs. This provides immediate visual feedback if, say, a compartment tries to access memory out of bounds. These are great for teaching or educational environments, where you might be triggering those sorts of exceptions on purpose.

Booting Sonata

With the board in front of you, what would be the next step? One difference from a normal development board is you can update the “microcontroller” itself, since that is just a FPGA bitstream.

You can download a “bitstream,” which is the prebuilt microcontroller setup. One feature of the Sonata system is it can store up to three bitstreams onboard, which allow you to switch between different “cores” if you want. For now I’d download and install the 1.1 release of Sonata (the most recent at the time of writing this article).

This download takes the form of a .uf2 file, which is a generic file format image. Programming the board just requires me to drag it onto the USB drive which appears when plugging in the Sonata board, as in Figure 3. The “slot” number should match the switch position I plan on using. In the future I could have different bitstreams if I wanted, which can be helpful if for example you want one version with a lot of SPI peripherals.

Figure 3
A simple drag-and-drop interface allows you to program the board from any computer.
Figure 3
A simple drag-and-drop interface allows you to program the board from any computer.

This same drag-and-drop interface can also be used for programming software that we’ll build. Under the hood this is handled by a RP2040 (Raspberry Pi Pico), which decodes the UF2 file format and writes it into SPI flash memories on the board. Of course, all of this firmware is open-source if you’d like to implement it on your own board.

If you want a little more control over programming (or debugging), the board also has a FTDI chip, which provides JTAG and serial interfaces. You can use the JTAG interface to debug both the FPGA and the microcontroller core, but that is beyond the scope of what I can cover in a short intro article.

Toolchain Setup

To build for the Sonata board, you’ll need a CHERIoT-enabled toolchain. This includes a compiler that understands the CHERIoT extensions, as well as the CHERIoT RTOS libraries. The two quick methods of getting this setup are to install them locally using Nix, or to use a VS Code “dev container” available with the CHERIoT-RTOS project.

I decided to proceed with the local install. I’m on Windows and following the “Getting Started” guide successfully had a toolchain running on WSL on Windows (see the link in additional materials). Be sure to carefully follow the requirements for Windows, including how to download Nix and additional WSL settings required. My first attempting of using a default Nix install, and not based on the link in the guide, caused myself problems!

From here, the process of checking out the required software and building all the examples is given in Listing 1. If this is successful you’ll end up with a bunch of UF2 files in a “build” directory. Each of those files is one of the built examples.

Listing 1
To set up and build the software repository, these few lines should “just work”.

git clone --branch v1.0 --recurse-submodule \    https://github.com/lowRISC/sonata-software.gitcd sonata-softwarenix developxmake -P examples

You might notice the filenames have a suffix of “slot1”, “slot2”, or “slot3”. For example, one of the LEDs and LCD demo filenames is leds_and_lcd.slot2.uf2 .

This is because the board has several “slots” you can load the software into, just like with the bitstream. Currently there are three slots, you can select which one to boot from with the little selector switch (see Figure 4).

Figure 4
Here I can select various software binaries to run. Be sure it matches the slot number you programmed.
Figure 4
Here I can select various software binaries to run. Be sure it matches the slot number you programmed.

To program it I can just drag-and-drop the associated UF2 file onto the SONATA drive that we used for programming the bitstream. The UF2 file format specifies within the file whether it’s a bitstream (for the FPGA) or software.

With examples built, we can now look at how you can use some of the features of CHERIoT.

Hardware Access Control

I’m going to follow the Hardware Access Control tutorial from the Sonata Software repository, again check the resources for the full link. This is a great tutorial as it demonstrates how you can easily add very fine-grained access control to your code with minimal effort.

Start by looking at the code in Listing 2, which is part of the C++ code for one thread in a simple “blinky” demo (which blinks some LEDs). On line 1 we are requesting the LED with index 7, so getting LED7 on the Sonata board. This LED is “acquired” on line 5 in the code with the acquire_led() call. So far this looks like a typical HAL (Hardware Abstraction Layer) provided by a board vendor.

Listing 2
One thread in the blinky demo.

1 : static constexpr uint32_t LedIdx = 7;2 : 3 : void __cheri_compartment(“blinky_dynamic”) start_blinking()4 : {5 :   auto ledOpt = acquire_led(LedIdx);6 :   Debug::Assert(ledOpt.has_value(), “LED {} couldn’t be acquired”, LedIdx);7 :   auto led = ledOpt.value();8 :9 :   while (true)10:   {11:     bool success = toggle_led(led);12:     Debug::Assert(success, “Failed to toggle an LED”);13:     thread_millisecond_wait(500);14:   }15: }

The first obvious sign of something different is however on Line 3. You’ll notice that a special compiler directive is being used, which defines a __cheri_compartment() name. These compartments can be used to provide granular access control. The rest of the code is normal C/C++, and you can see that it simple blinks the given LED on lines 9 through 13. Note that I’ve cut the headers out of this file to save space, you can see the full source code in the linked tutorial.

We need something to “conflict” with this thread to have any sort of interesting demos and understand what the code is doing. That is provided in Listing 3, which is another thread that is also blinking some LEDs. In this case it’s trying to “walk” through the LEDs being blinked in sequence. The conflict happens because the for() lop on Line 15 will eventually try to toggle LED7, the exact same LED that we were toggling in Listing 2!

Listing 3
The second thread in the blinky demo.

1 : static constexpr uint32_t NumLeds = 8;2 : 3 : void __cheri_compartment(“led_walk_dynamic”) start_walking()4 : {5 :   std::vector<LedHandle *> leds;6 :   for (uint8_t num = 0; num < NumLeds; ++num)7 :   {8 :     auto led = acquire_led(num);9 :     Debug::Assert(led.has_value(), “LED {} couldn’t be acquired”, num);10:     leds.push_back(led.value());11:   };12:13:   while (true)14:   {15:     for (auto led : leds)16:     {17:       bool success = toggle_led(led);18:       Debug::Assert(success, “Failed to toggle an LED”);19:       thread_millisecond_wait(500);20:     }21:   }22: }

The code in Listing 2 and Listing 3 have taken advantage of another CHERIoT feature; the call to acquire_led() from one thread will block the other thread from using it. In this case it’s a question of which thread was initialized first, that thread ends up acquiring access to the LED.

In this example, it’s actually Listing 3 that is called first, as its priority is set higher in the configuration. On Line 8 of Listing 3 we call acquire_led() in a loop, which acquires all the first eight LEDs. A later attempt to use the same LED from the other compartment is blocked by CHERI via the acquire_led() function call.

Of course, you might accuse me of trying to sell you old technology as something new: you could surely accomplish the same thing with an RTOS mutex (or lock), so why the fuss about CHERI? The reason is that a RTOS mutex is enforced only by the RTOS, a vulnerability may still allow an attacker to directly access the resource. An attacker who achieves a secure mode exploit is going to skip the call to acquire_led() and attempt to write directly to the GPIO peripheral memory space.

It’s this attack that can be blocked by CHERIoT. The memory space for the GPIO can be restricted to only be accessible through the acquire_led() interface. This is an incredibly powerful defense as it does not just rely only on a “secure” and “non-secure” mode as many current security protections assume. The problem with these is it can be difficult to guarantee all “secure” code is bug-free, as when you only have two levels of access an attacker who manages to find an exploit in the “secure mode” code can suddenly access all other systems. With CHERIoT we just need to make the individual drivers bug-free. Someone who wants to access a specific subsystem would need to find an exploit in the code within that compartment, not any other compartment.

Such exploits become challenging to avoid when you consider that many microcontrollers also involve vendor-provided libraries. It is common to have certain features, especially wireless stacks, to be provided by vendors in binary-only format. If those vendor libraries run in a privileged mode, an attacker who finds an exploit in a vendor stack can compromise any products using that stack. With CHERI’s compartmentalization, such attacks are blocked.

If you’re interested in more details of how you could use CHERIoT, be sure to check out the Sonata Software documentation and exercises (linked in the additional materials). This is a great set of exercises and examples from the lowRISC team to show you how to use CHERIoT on the Sonata board, and includes various examples of using features like I2C, the LCD, GPIO, and more.

CHERI Futures Ahead

If this article interested you, you can see more information on the “Sonata System” documentation (see additional material). All the steps I’ve included in this article are from the “Sonata Software” getting started guide, also in the resources.

Besides these specific getting started guides, I also want to point to a number of resources available on CHERIoT.org, including the “CHERIoT Programmer’s Guide” by David Chisnall. It includes some topical posts about the CHERIoT security model, including a comparison of recent embedded security flaws that could have been prevented with CHERIoT.

If you’re interested in CHERIoT you might look at the CHERI Alliance, which is driving adoption of this technology across industry and academia. It’s exciting to see the many resources available for CHERIoT work, and even the state of all these examples from when my last article on the issue was published in November 2023. Hopefully you find this interesting, and even if you don’t run the examples yourself it’s a technology to keep an eye on for the future. 

RESOURCES
CHERI Alliance | https://cheri-alliance.org
Sonata | www.sunburst-project.org

SOURCES
Sonata System Documentation: https://lowrisc.github.io/sonata-system/index.html
Sonata Software Getting Started: https://lowrisc.github.io/sonata-software/doc/getting-started.html
Sonata Software Hardware Access Control Tutorial: https://lowrisc.github.io/sonata-software/exercises/hardware_access_control/index.html
CHERIoT Programmer’s Guide: https://cheriot.org/book/

Code and Supporting Files

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • MAY 2025 #418 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.

— ADVERTISMENT—

—Advertise Here—


Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
Website | + posts

Colin O’Flynn has been building and breaking electronic devices for many years. He is an assistant professor at Dalhousie University, and also CTO of NewAE Technology both based in Halifax, NS, Canada. Some of his work is posted on his website (see link above).

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2026 KCK Media Corp.

Experimenting with CHERI on the Sonata Board

by Colin O'Flynn time to read: 12 min