โšก Embedded Security

Black-Box BAR0 Page-Fault MMIO Traps & Differential NVRAM Fuzzing on ARMv7 (Part 3)

How did open-source Linux wireless projects like nouveau (NVIDIA GPUs), ath9k, and b43 (Broadcom SoftMAC Wi-Fi) figure out exact initialization sequences for undocumented silicon without violating clean-room rules by copying vendor C code? They treated the hardware bus itself as an observable protocol. By interposing a transparent Memory-Mapped I/O (MMIO) bus tracer between the reference binary and the PCIe BAR0 register aperture, you record what the silicon actually requires โ€” and by mutating one volatile NVRAM key at a time, every mysterious magic bitfield reveals its exact physical meaning.

Three-panel technical blueprint showing BCMA PCI config 0x80 BAR0 core windowing, ARMv7 Data Abort page-fault MMIO trapping, and differential RAM-only NVRAM bitmask attribution
Figure 3.1 โ€” Left: Switching BCMA_PCI_BAR0_WIN (0x80) onto D11 core 0x18001000. Center: ARMv7 Data Abort MMIO tracing and RMW folding. Right: Single-variable RAM NVRAM diffing.

1. The Classic Broadcom Trap: BCMA_PCI_BAR0_WIN (PCI Config 0x80)

Suppose you write a minimal Linux pci_driver for PCI ID 14e4:43a0 (BCM4360), call pci_iomap(pdev, 0, 0) to map BAR0, and immediately execute ioread16(bar0 + 0x03E0) expecting to read B43_MMIO_PHY_VER (0x0B01 = AC-PHY type 11, rev 1). Instead, you read 0x0000 or an unrelated ChipCommon ID register! Why?

Inside a Broadcom wireless ASIC, there is not just one register block โ€” there is an entire on-chip AMBA AXI backplane managed by Linux's bcma subsystem, hosting multiple independent IP cores at 4 KiB physical intervals:

BCMA Core Name Core ID AXI Backplane Base Agent / Wrapper Base Primary Role on BCM4360
ChipCommon 0x800 0x18000000 0x18100000 Chip ID (0x4360 rev 3), PLL clocks, PMU, SROM OTP
IEEE 802.11 (D11) 0x812 0x18001000 0x18101000 D11 rev 42 MAC, 64-bit DMA rings, SHM, indirect AC-PHY & Radio 2069
PCIe Gen2 0x820 0x18002000 0x18102000 PCIe link state, MSI/legacy IRQ routing, host bridge DMA

The PCIe BAR0 aperture exposed to the host CPU is a movable window controlled by 32-bit PCI configuration register BCMA_PCI_BAR0_WIN (0x80). At cold reset, 0x80 defaults to 0x18000000 (ChipCommon). Until either drivers/bcma or your probe routine writes 0x18001000 into PCI config 0x80 โ€” and enables the D11 core clocks via its agent wrapper (BCMA_IOCTL / BCMA_RESET_CTL at 0x18101408 / 0x18101800) โ€” reading BAR0 + 0x03E0 never touches the wireless core at all!

2. Building a Black-Box MMIO Tracer on ARMv7 Linux

On x86_64 workstations, the Linux kernel includes built-in mmiotrace (CONFIG_MMIOTRACE) inside ftrace, which marks PCIe PTEs non-present, logs every faulting instruction via single-step trap flags, and replays the I/O. Embedded ARMv7 router kernels (especially 2.6.36.4 or 4.4) ship without mmiotrace. How did community researchers capture complete R7000 BCM4360 initialization traces on physical hardware?

They used ARMv7's native Data Abort fault hook (hook_fault_code() in arch/arm/mm/fault.c):

  1. Shadow Virtual Address Allocation: When the reference driver calls ioremap_nocache(phys_bar0, size), a tiny interposer kernel module performs the real ioremap() privately at real_va, allocates a separate unmapped virtual range shadow_va (via get_vm_area() without backing PTEs), and returns shadow_va to the driver.
  2. Catching Translation Faults: Every time the driver executes a 16-bit or 32-bit load/store (ldrh, strh, ldr, str) inside [shadow_va, shadow_va + size), the Cortex-A9 MMU raises a synchronous Data Abort (section/page translation fault, FSR codes 0x05 / 0x07).
  3. Instruction Decoding & Replay: Inside the fault callback, if the faulting address far falls within shadow_va, the handler computes offset = far - shadow_va, inspects the ARM/Thumb-2 instruction at regs->ARM_pc to identify the source/destination general-purpose register Rt and access width (8/16/32-bit), performs the real readw/writew/readl/writel against real_va + offset, writes the result into regs->uregs[Rt] (on reads) + logs (op, core_win, offset, val) to a lockless relay ring buffer, and advances regs->ARM_pc by 4 bytes (ARM) or 2/4 bytes (Thumb-2) to resume execution seamlessly!

3. Folding Indirect Register Pairs & Posted-Write Flushes

Raw BAR0 MMIO logs contain hundreds of thousands of low-level bus cycles because the thousands of internal 16-bit AC-PHY and Radio 2069 registers do not fit directly inside the 4 KiB D11 core window. Instead, D11 exposes indirect address/data portals:

  • AC-PHY Portal: Write 16-bit register address to B43_MMIO_PHY_CONTROL (0x03FC), then read or write the 16-bit value at B43_MMIO_PHY_DATA (0x03FE).
  • Radio 2069 Portal: Write radio register address (ORed with read bit on reads) to B43_MMIO_RADIO24_CONTROL (0x03D8), then read/write B43_MMIO_RADIO24_DATA (0x03DA).
  • PCIe Posted-Write Flush Reads: Because PCIe memory writes are posted (asynchronous), hardware drivers frequently perform a dummy read of B43_MMIO_PHY_VER (RD 0x03E0) immediately after a time-critical PHY write before calling udelay(), forcing the PCIe root complex to drain pending writes to silicon.

To turn noisy bus captures into clean specification notes, a semantic trace folder collapses raw cycles into high-level operations โ€” especially Read-Modify-Write (PHY.MOD) sequences:

# Raw BAR0 Capture:
WR 0x03fc 0x0810    # Select AC-PHY register 0x0810
RD 0x03fe 0x1000    # Read current value (0x1000)
WR 0x03fc 0x0810    # Re-select AC-PHY register 0x0810
WR 0x03fe 0x100c    # Write modified value (0x100c)
RD 0x03e0 0x0b01    # Dummy flush read (discarded)

# Folded Semantic Operation:
PHY.MOD reg=0x0810 old=0x1000 new=0x100c changed_mask=0x000c

4. Differential RAM-Only NVRAM Perturbation (SROM Rev 11)

Look at that folded line above: why did the driver set bits 0x000C in PHY register 0x0810? On a Nighthawk R7000, the factory board_data flash partition populates SROM revision 11 NVRAM variables for both PCIe slots (pci/1/1/... for 2.4 GHz and pci/2/1/... for 5 GHz), including external LNA gains (rxgains2gelnagaina0=3), FEM control indices (femctrl=3), and PA polynomial coefficients (pa2ga0, pa5ga0).

Instead of spending a week reverse engineering NVRAM string-parsing math in assembly, you can run a 60-second controlled single-variable experiment purely in volatile RAM:

  1. Capture Trace A with stock RAM NVRAM (pci/1/1/rxgains2gelnagaina0=3): PHY 0x0810 ends with 0x100C (binary ...0001100).
  2. Run nvram set pci/1/1/rxgains2gelnagaina0=6 (NEVER run nvram commit!), bounce the interface while tracing, and capture Trace B: PHY 0x0810 ends with 0x1018 (binary ...0011000), while every other PHY register in the 50,000-line trace remains byte-for-byte identical!
  3. Compare 3 << 2 == 0x0C vs. 6 << 2 == 0x18 (0x100C ^ 0x1018 == 0x0014): you have proved empirically that Core 0's 2.4 GHz eLNA gain occupies bits [4:2] of AC-PHY register 0x0810!

Even better, negative differential tests save you from writing dead code: unsetting pci/1/1/tssifloor2g in RAM and observing zero register diffs proves that PHY 0x0724 receives a constant 0x03FF sentinel during temperature sensing regardless of NVRAM.

5. Your Turn โ€” Hands-On Lab 03 Checkpoints (Zero Spoilers)

Open labs/03-mmio-trapping-and-nvram-fuzzing.md, inspect the three trace captures in labs/fixtures/sample_mmio_trace.txt, and implement both functions in labs/starter/lab03_mmio_fold_skeleton.py:

  1. Implement fold_phy_ops(raw_lines): Track the active PHY address written to 0x03FC, discard posted-write flush reads on 0x03E0, emit ('PHY.RD', reg, val) on reads of 0x03FE, and fold back-to-back read+write pairs targeting the exact same PHY register into ('PHY.MOD', reg, old_val, new_val, old_val ^ new_val).
  2. Implement diff_final_phy_state(ops_a, ops_b): Compute the final written value of every touched PHY register across two folded traces and return only registers whose final hardware state changed.
  3. Verify with the Grader: Execute python3 labs/verify_labs.py --lab 3 โ€” note that the grader also tests cross-register edge cases (reading register A then writing register B must not falsely collapse into PHY.MOD!).

Continue to Part 4 of the Series

Once you understand how hardware register specifications and calibration tables are derived cleanly, continue to Part 4: Clean-Room Linux 6.12 mac80211, BCMA Windowing & B43D Firmware Loaders to architect a mainline GPL-2.0 kernel driver and fuzz-test its binary firmware parser in userspace C.

Robert Baindourov

Written & Architected by Robert Baindourov

Senior IoT Firmware & Edge-Cloud Solutions Architect with 17+ years total experience (15+ years professional architecture). Specializing in bare-metal C/C++, FreeRTOS, Zephyr OS, Embedded Rust, hardware secure elements (ATECC608, TPM 2.0), and high-throughput cloud telemetry pipelines (AWS IoT Core, EMQX, Node.js). Based in Los Angeles, CA.