Porting RIOT OS to the NOEL-V RISC-V soft core, and verifying post-quantum signatures on it
For my engineering thesis I ported RIOT, an open-source real-time operating system for IoT devices, to NOEL-V, a RISC-V processor that lives inside an FPGA. On top of the port I built a small network server that verifies post-quantum digital signatures (ML-DSA, the new NIST standard). Most of the port is now part of upstream RIOT.
This post walks through what that involved: the platform, the 64-bit pitfalls, a DMA Ethernet driver that has to manage the CPU cache by hand, a few bugs that only appeared on the second board, and what a 40 MHz soft core can do with a lattice-based signature.
The platform
RIOT runs on more than 300 boards, mostly small microcontrollers. It has a complete IPv6 network stack (GNRC), a real-time scheduler and a strict upstream review process.
NOEL-V is an open RISC-V processor from Frontgrade Gaisler, part of the GRLIB VHDL library. It is a soft core: it is not a chip you buy, but a hardware description that you synthesize into an FPGA together with the rest of the system (bus, memory controller, UART, GPIO, Ethernet). It is designed with space applications in mind. Before this work RIOT had no NOEL-V support, and its RISC-V code only knew 32-bit cores.
Figure 1. Simplified NOEL-V system: the CPU, memory and interrupt/timer blocks sit on the fast AHB bus; slow peripherals hang off APB behind a bridge. The GRETH Ethernet controller uses AHB for DMA and APB for its registers. Based on the GRLIB documentation.
I targeted two boards on purpose, because they differ in exactly the ways that test a port:
| ZedBoard | Arty A7-100T | |
|---|---|---|
| FPGA | Xilinx Zynq-7020 | Xilinx Artix-7 100T |
| Processor | NOEL-V, 64-bit | NOEL-V, 32-bit |
| Clock | 40 MHz | 40 MHz |
| RAM used by RIOT | 120 MB | 248 MB |
| FPGA design | my own build from GRLIB | Gaisler's prebuilt bitstream (NOEL-ARTYA7) |
| Ethernet PHY | external PMOD module | on-board |
What the port consists of
Figure 2. RIOT on NOEL-V. Green: written for this port; yellow: existing code extended for 64-bit; white: existing RIOT code.
In total it is about 3,200 lines in four pull requests:
- 64-bit support in the shared RISC-V code (
cpu/riscv_common), so that any rv64 core can use it, not only NOEL-V. cpu/noelv: the CPU module with UART, GPIO and power-management drivers. Interrupts (PLIC) and the timer (ACLINT) reuse the existing shared RISC-V drivers; NOEL-V only provides addresses and clock configuration.drivers/greth: a driver for the GRETH Ethernet MAC, the largest single piece.- Board definitions for ZedBoard and Arty A7.
Lessons from going 64-bit
The 64-bit changes were small in line count (+252/−173 across 12 files) but sit in the most unforgiving code an OS has: the trap entry, context switching, startup and the linker script. A mistake there produces a crash or silent memory corruption. Four examples:
The interrupt flag moved. RISC-V stores the cause of every trap in the mcause register. The most significant bit says interrupt or exception, the low bits give the cause code. RIOT checked bit 31, because every RISC-V core it supported was 32-bit:
-#define MCAUSE_INT 0x80000000
-#define MCAUSE_CAUSE 0x7FFFFFFF
+/* The interrupt bit is the MSB of mcause, i.e. XLEN dependent. */
+#define MCAUSE_INT (1UL << (__riscv_xlen - 1))
+#define MCAUSE_CAUSE (MCAUSE_INT - 1)
On rv64 a timer interrupt reads mcause = 0x8000000000000007. Bit 31 is zero, so RIOT treated it as exception 7 (a store access fault) and panicked on the very first timer tick.
Bigger thread context. On every context switch RIOT saves 32 register slots on the thread's stack. On rv64 each slot is 8 bytes, so the frame grows from 128 B to 256 B, and every call frame grows too. Default stack sizes for rv64 had to double, otherwise stacks would silently overflow into neighbouring memory.
The timer was 42 times too fast. RIOT converts milliseconds into ticks of the mtime counter using a configured frequency. The port initially assumed 1 MHz. In GRLIB, however, mtime runs at half the CPU clock, which was 41.75 MHz at the time. A 500 ms sleep lasted 12 ms. The fix derives the value instead of hard-coding it: RTC_FREQ = CLOCK_CORECLOCK / 2.
A GPIO race, found in code review rather than by tests. Changing one output pin means read-modify-write of the whole 32-bit output register. If an interrupt changes another pin between the read and the write, its change is overwritten. The driver now does the read-modify-write with interrupts disabled. My supervisor spotted this one.
The first 64-bit embedded board in RIOT's CI also turned up 17 build failures with 7 root causes in shared code: C11 atomics that assumed 4-byte long, semihosting casting pointers to 32-bit integers, %d used for size_t, and similar. None of these were new bugs; they had always been there and simply never met a 64-bit target.
Getting the FPGA design to 40 MHz
On the ZedBoard I build the FPGA design myself. Early on the processor crashed at random. The cause turned out to be a chain of four independent problems in the hardware project.
The quantity to watch is WNS, the worst negative slack. It tells you by how much the slowest signal path misses (negative) or meets (positive) the clock period.
Figure 3. Worst negative slack in successive iterations. Clock period 25 ns (10 ns for the old design); failing paths: 34,217 → 449 → 11 → 0. Based on Vivado timing reports.
The last 11 failing paths all started at a single debug-trigger register in the CPU with a large fan-out. Vivado's post-route physical optimization replicated that register and closed timing with +0.022 ns to spare. After that: dozens of runs without a single crash.
An Ethernet driver that manages the cache by hand
GRETH does not hand frames to the CPU byte by byte. It writes them straight into RAM over the bus (DMA) using a ring of descriptors. Each descriptor holds a buffer address and a control word whose enable bit says who owns it: the controller (free slot) or the CPU (a frame is waiting).
Figure 4. Receiving frames through the descriptor ring.
The catch is that the CPU reads memory through its data cache and the DMA engine does not. On these designs the cacheability of RAM is fixed by the FPGA configuration, and RIOT runs in machine mode without page tables, so there is no software switch to make the buffers uncached. The driver therefore keeps the cache and the RAM in sync explicitly with the RISC-V Zicbom instructions:
cbo.flushbefore transmitting, so that the controller reads the bytes the CPU just wrote;cbo.invalbefore reading a received frame, so that the CPU does not see a stale cached copy.
A few other details mattered more than expected: IPv6 neighbour discovery uses multicast, so the MAC has to run in promiscuous mode; and the controller's DMA addresses are 32-bit, so on the 64-bit board the driver asserts that all rings and buffers sit below 4 GiB.
The second board finds the bugs
The driver worked on the ZedBoard. On the Arty, the very same code revealed four bugs, each hidden behind the previous one:
| Bug | Symptom | Fix |
|---|---|---|
| 4 GiB address check shifted a 32-bit value by 32 | build failure on 32-bit | widen to 64 bits before shifting |
| Status bits left over from the previous run | phantom empty frame, assertion | clear the status at init |
| Buffer not aligned to a cache line | cbo.inval discarded part of a neighbouring thread's stack | align buffers to 32 bytes |
| A descriptor with an error was never returned | reception stopped after exactly 5 frames | recycle such descriptors |
The cache-line one is my favourite: invalidation works on whole 32-byte lines, and the receive buffer started in the middle of a line that it shared with another thread's stack. On the ZedBoard the linker had placed the buffer on a 32-byte boundary by pure luck.
Results
| Test | ZedBoard (64-bit) | Arty A7 (32-bit) |
|---|---|---|
| ping loss | 0 % (60/60) | 0 % (90/90) |
| ping round-trip time | 0.64–0.90 ms | 0.65–0.89 ms |
| UDP send, 1400 B payload | 10.5–11.5 Mbit/s | ~11.5 Mbit/s |
| UDP receive | ~4 Mbit/s | 9.4 Mbit/s (10 Mbit/s link) |
| shell, GPIO, timers | OK | OK |
Sending is limited by the 40 MHz CPU. Receiving on the ZedBoard is limited by the 8-descriptor ring: at 100 Mbit/s frames arrive far faster than the CPU can take them, the ring overflows, and the stack wastes time on packets it later drops. On the Arty, at 10 Mbit/s, frames arrive slowly enough that the board takes every single one.
Upstreaming
Figure 5. Timeline of the pull requests in 2026.
- #22547
cpu/riscv_common: add rv64 support, merged on 13 August - #22548
cpu/noelv: add support for Gaisler NOEL-V on ZedBoard, merged on 18 August - #22766
drivers/greth: fix RX stalls and 32-bit build, merged on 26 September - #22767
boards/arty-a7-noelv, in review
The merged code is part of the upcoming RIOT 2026.10 release. At the time of writing it is at release candidate 3. Every PR went through several review rounds, including code style and documentation.
A post-quantum signature server
A large enough quantum computer could break today's RSA and ECDSA signatures. In August 2024 NIST standardized a replacement, ML-DSA (FIPS 204), based on module lattices. I used its smallest variant, ML-DSA-44. It only needs integer arithmetic, which matters on the Arty's NOEL-V without a floating-point unit, but its keys and signatures are much bigger than what we are used to:
| ML-DSA-44 | ECDSA P-256 | |
|---|---|---|
| Public key | 1312 B | 64 B |
| Signature | 2420 B | 64 B |
The implementation comes from PQClean, a collection of clean, portable C implementations of post-quantum schemes. I added it to RIOT as a package: RIOT's build system downloads it at a pinned commit and compiles it with the firmware, and only a thin wrapper lives in the RIOT tree. Two small adaptations were needed: PQClean's sha3_* functions collide with RIOT's own hash module and get renamed at build time, and its randombytes() is backed by RIOT's random module.
The server is a RIOT example application. The public key is compiled into the firmware; the board listens on TCP port 7777 over IPv6.
Figure 6. The exchange between the client and the board.
A request is a 12-byte header followed by the message (up to 1024 bytes in the default configuration) and the 2420-byte signature. The board answers with a status (OK, bad signature, bad request or unsupported) and the time the verification took. TCP rather than UDP, because a request does not fit into one Ethernet frame. The board only verifies: signing needs the private key and good randomness, and NOEL-V has no hardware random number generator, so signing stays on the PC.
Results on the Arty A7 (32-bit, 40 MHz, built with -Os):
| Operation | Time |
|---|---|
| Key generation | 48.8 ms |
| Signing | 110–707 ms (238 ms on average) |
| Verification, standalone | 51.9 ms |
| Verification inside the server | 59.6 ms |
| Full request as seen by the client | 71 ms |
Signing varies so much because ML-DSA uses rejection sampling: a candidate signature that could leak information about the private key is thrown away and a new one is computed, about 4.25 attempts on average. Verification has no such loop and always takes the same time. For comparison, the same C code verifies a signature in about 0.12 ms on a desktop.
All 20 valid signatures in the test run were accepted, and every tampered signature and malformed request was rejected. On the PC, signatures produced by OpenSSL 3.5's independent ML-DSA implementation verify with the same PQClean code.
Things I tripped over
- Large frames vanish at 100 Mbit/s on the Arty. In Gaisler's prebuilt design the controller's DMA cannot drain its receive FIFO into DDR3 fast enough. Frames longer than about 260 bytes overflow inside the controller, and the network stack never even sees them. My first tests in September used 56-byte pings, so this stayed hidden for a while. The workaround is a new driver option that makes the PHY advertise only 10BASE-T, after which frames of every size arrive without loss. A real fix would need a different FPGA design.
- Bytes leaking from one TCP connection into the next. In RIOT's
gnrc_tcp, a listening socket kept unread data in its receive buffer after a connection closed, and the next client's data came after those stale bytes. One malformed request made every following request fail. The server now drains the connection before closing it. As it turned out, the same bug had just been fixed independently upstream in #22749; my branch was simply older than that fix.
What's next
- Getting the Arty A7 board merged.
- Faster verification: building with
-O2, using the ZedBoard core's bit-manipulation extension for Keccak, or adding a Keccak or NTT accelerator to the FPGA design, which is exactly the kind of thing a soft core makes possible. - ML-DSA-65 and ML-DSA-87: the protocol already has an algorithm field for that.
- Measuring the server on the 64-bit ZedBoard as well.
The PQClean package and the server example are not part of upstream RIOT.
Links
- RIOT: https://github.com/RIOT-OS/RIOT, documentation at https://doc.riot-os.org
- NOEL-V: https://www.gaisler.com/products/noel-v
- GRLIB IP Library and IP Core User's Manuals, version 2025.2, Frontgrade Gaisler
- PQClean: https://github.com/PQClean/PQClean
- FIPS 204, Module-Lattice-Based Digital Signature Standard: https://csrc.nist.gov/pubs/fips/204/final
Guestbook · 0 entries
No entries yet. Be the first to sign the guestbook!