Cocoapuffs Boots Zircon Again: a Fuchsia Mirror, a Rust Userboot, and a Bus Bug

#FPGA#RISC-V#Zircon#Fuchsia#Rust#Cocoapuffs#auto

In July, Fuchsia’s Zircon kernel booted to userboot on Cocoapuffs, my homebrew RISC-V system-on-chip on an AMD Artix-7 FPGA. Then the Fuchsia checkout behind that boot was lost, together with the machine it lived on. None of the board patches were upstream.

This is the rebuild. On 2026-11-24 at 22:23 Pacific, the board booted current upstream Zircon to userboot again. That is the same point as in July, now with a userboot written in Rust, and with one hardware bug fewer. It is not Fuchsia running: the image has no boot filesystem, so userboot has nothing to start, and the kernel halts on purpose.

The boot

The screencast below is a replay of the captured serial log, not a live screen recording. The capture has a wall-clock time on every line. The 36-minute image upload plays in 15 seconds, and the boot plays at its recorded speed.

A replay of the serial console from 2026-11-24: the upload, OpenSBI, the boot shim, physboot, the Zircon kernel and userboot, ending at the expected halt.

The boot chain is the same as in July. SERV, a bit-serial RISC-V core, receives the image over the UART as Intel hex and writes it to DDR3. Then it releases the NOEL-V core, which runs a small stub in block RAM, OpenSBI 1.6, Fuchsia’s Linux-style RISC-V boot shim, physboot, the Zircon kernel, and finally userboot.

Here are the milestones from the log, trimmed. The bracketed numbers are seconds since the kernel started.

22:22:00 OpenSBI v1.6
22:22:00 Platform Name   : HDLFactory Cocoapuffs: FPGA Soft Core RISC-V Board
22:22:00 Boot HART Base ISA : rv64imafdcbhx
22:23:01 [00000.005] welcome to Zircon
22:23:03 [00003.272] Free memory after kernel init: 1049886720 bytes.
22:23:04 [00003.932] starting user space
22:23:07 [00005.583] userboot: entry point
22:23:15 [00009.483] userboot error: StorageBootFs item not found in ZBI
22:23:16 [00009.763] root-job: taking reboot action
22:23:16 HALT: spinning forever... (reason = 6)

The upload takes about 36 minutes at 115200 baud. From the OpenSBI banner to the halt takes 76 seconds. Physboot takes about a minute of that, mostly to unpack the kernel. The kernel then prints through a polled UART, which is slow.

A Fuchsia mirror, so it cannot be lost again

The July tree existed in one place. When that place was gone, the patches had to be rewritten from the July article and from memory of what they did. So the first job was a private mirror of everything a Fuchsia build needs.

  • Sources. The mirror holds shallow git copies of all 147 projects in the Fuchsia manifest, with history since 2026-10-01, branches and tags only. It does not use git clone --mirror, because that also downloads every Gerrit review patchset. The small jiri repository alone has 5,089 of those refs.
  • Pinned commits. Every commit that the manifest pins is fetched on its own and kept under its own ref, so the exact snapshot can always be checked out.
  • Prebuilts. The mirror also keeps the 173 prebuilt packages that the manifest pins, such as the toolchains.
  • Snapshots. Each dated snapshot holds an archive of every mirror, the prebuilts, the resolved manifest and a verified SHA256SUMS file. The mirrors take about 23 GB, and a snapshot about 30 GB. A second copy is kept off site.

The mirror runs in a small container with a 512 MB memory limit on a home storage box, and fetches straight from Google. It took several tries. The first four runs died on missing tools and on memory. In one later run, 16 of the 147 mirrors failed until git’s background cleanup was turned off.

The baseline is fuchsia.git 0b7b5b18eb62, from 2026-11-08. It was the newest revision on which all 12 riscv64 builders in Fuchsia’s CI were green on the same commit.

A small private patch repository sits on top. It holds the pinned upstream commits, one patch series per project, and a tool that makes a checkout straight from the mirrors and applies the patches, with no jiri and no network access to Google. Moving to a newer upstream means moving the pin, applying the series again and fixing what breaks. The RISC-V work stays a short series on top of upstream. These patches are private, and they are not upstreamed.

Eight patches on current upstream

Four patches redo the July work:

  1. The kernel stops its backtrace walk at a null frame pointer.
  2. The kernel writes each PLIC interrupt source’s own priority register.
  3. The boot shim finds the console interrupt through interrupts-extended in the device tree.
  4. A driver for Gaisler’s GRLIB APBUART, the UART on this SoC.

Four patches are new:

  1. The APBUART driver waits on the interrupt for an empty shift register. This one is written but not yet tested on the board. The interrupt-driven console still does not work on hardware, so the boot uses kernel.debug_uart_poll=true.
  2. The kernel sets the page table’s accessed bit again when a page faults after page aging cleared that bit. NOEL-V does not set the accessed bit in hardware; it raises a fault instead and leaves the update to software. Without this patch, the same access faulted forever.
  3. The Rust build turns off the vector extension when riscv64_enable_vector is false. The next section explains why.
  4. A build argument for the kernel’s default stack size, used while debugging.

More Rust, and no vector unit

In July, userboot, the first user process, was C++. Upstream has since rewritten it in Rust. So the first user-space code that this board runs is now Rust.

That brought a problem with the instruction set. The NOEL-V core implements rv64imafdc plus the B and H extensions, and OpenSBI reports it as rv64imafdcbhx. It has no vector extension. Fuchsia’s riscv64 target is RVA22 plus V. The build argument riscv64_enable_vector=false already existed, but it changed only the C and C++ flags.

The first build of userboot contained 3,770 vector instructions. Nearly all of them came from the prebuilt Rust standard library, which Fuchsia ships compiled with V. The fix has two parts.

  • The build flags. With riscv64_enable_vector=false, the build now passes the Rust target features -v, -zve32x, -zve32f, -zve64x, -zve64f, -zve64d, -zvl32b, -zvl64b and -zvl128b. Turning off v alone is not enough, because the Fuchsia Rust target turns on the Zve and Zvl features separately, and they stay on.
  • The standard library. The Rust standard library is rebuilt with the same features, and the build points at that toolchain.

After the fix, 65 vector instructions are left in userboot. All of them are in the prebuilt libunwind, which is C++, and this boot does not run that code. Userboot, in Rust and without V, then runs on the board and prints its own error message, the one at the end of the log above.

The bug hunt

With the Rust fix in place, the kernel died in a recursive panic soon after starting user space. Earlier, physboot had once lost its console pointer in a similar way.

The first suspect was the memory size: perhaps addresses wrapped around in RAM. They did not. The board has 1 GB of DDR3, and the kernel reports 1,049,886,720 bytes free.

The second suspect was atomics. The panic’s backtrace pointed into a lock-free gate in the UART code, built on atomic operations. A bare-metal stress test of the atomic instructions ran 4 million iterations on the board with 0 failures. Atomics were not the problem.

Then the backtrace itself turned out to be misleading. The return address on the stack followed a call to an assert-fail function that never returns. A return address after such a call points at whatever code the compiler placed next, here an unrelated cold block. Symbolizing the address as it was named the wrong function. Symbolizing ra - 1 instead named the right one.

With the right function, the first panic was a plain debug assert in the UART output code. A boolean on the stack, which says whether a newline is pending, held 0x6b. The code only ever stores 0 or 1 there. 0x6b is the letter k, and k was the character just written to the UART.

So a value written to the UART’s data register also showed up in a nearby stack slot. The physboot failure had the same shape: a UART control-register value had landed in a global pointer.

The test that found it

A bare-metal test, with no operating system, made the bug repeatable. It stores to the UART, which sits on the slow APB bus, and right after that stores to DDR3. It tries every spacing and alignment, evicts the cache, and reads the values back. On the old bitstream, 29,796 stores came back wrong.

The data cache had hidden the fault. The cache held the right value, and only the copy that reached DDR3 was wrong. The error showed only after the cache line was evicted and loaded again, which is why it looked random.

The cause: one missing signal

The cause was in the AHB-to-Wishbone bridge in front of the DDR3 controller. In its idle state, the bridge accepted a new transfer when hsel and htrans said so, without checking the bus’s hready signal. On AHB, a transfer starts only when the previous one has finished, and hready high says that it has.

When the previous transfer was a slow UART write that still held the bus, the bridge started early. It latched the write data lines while they still held the UART’s data. A 64-bit store goes out as two 32-bit beats, and the low beat got the stale word.

The fix is one condition: the idle state now also requires hready = '1' before it accepts a transfer. The change is that one condition in the bridge; the rest is a new testbench case.

Check Old bridge Fixed bridge
VHDL testbench (NVC): DDR3 write right after a slow write fails in 5 of the 6 wait-state variants, every one with a wait state passes
Simulated 256-word memory test not run passes
Place and route timing WNS 0.098 ns WNS 0.032 ns, TNS 0
Store test on the board 29,796 wrong stores 0
Zircon boot, same image recursive kernel panic boots to userboot, no panic

Both bitstreams ran the same boot image, with the same checksum.

Why did July work? The bridge had not changed since June, so the July bitstream had the same fault. The fault shows only when three things line up. A store to RAM goes out right behind a UART write, the cache line is evicted before the next store repairs it, and the stale value is then read where it matters. The July image, from sources five months older, with a C++ userboot and a different UART driver, most likely never lined them up. That is a guess: the July tree is gone and cannot be tested.

The fix is not yet in the public cocoapuffs-fpga repository. It will be there after the next sync.

What’s next

  • An image with a boot filesystem, to get past userboot.
  • The interrupt-driven console.
  • A libunwind built without V.

Feedback and technical corrections are welcome.