Boot Verification
Every chip test starts with a boot, and almost every one cheats: the bench loads the program by the back door. Boot verification is the test that does not cheat. It boots for real, measures how long that takes, and knows what each kind of boot proves.
You Will Be Able To
- Name the boot modes of a chip and what decides between them.
- Say what a back-door load proves and what only a front-door boot proves.
- Measure boot time from a recording, and plan the cost of front-door boots in a regression.
- Write boot checks that work after both kinds of boot.
- Lesson
- V9.3
- Time
- 28 min
- Runs on
- Your browser
- Check
- 5 questions
A back-door load skips the loader, the SPI pads and the flash. One small program reached main at cycle 188 that way, and at cycle 46,851 by the front door.
- Clock / reset
- Pads
- Memory
- Peripheral
- External
- Processor
- Control
- Data
- The strap
The chip samples BOOT once, after power-up, and keeps it through every warm reset.
- The front door
BOOT = 0 starts the ROM. Its loader reads the flash over the SPI pads, three bytes a frame, and writes SRAM.
- The back door
BOOT = 1 starts at SRAM, which the bench loaded before the first cycle. No loader, no SPI, no flash.
- Main
Either way the core reaches start-up code and main. Only the front door tested the path on the top row.
Read the diagram as text
- Power-up: POR, PLL lock
- BOOT strap: sampled once
- Boot ROM: the loader
- SPI and pads: IO2 to IO5
- SPI flash: the image
- SRAM: 0x8000_0000
- Start-up code, main: the program
- Power-up → BOOT strap: once
- BOOT strap → Boot ROM: BOOT = 0
- Boot ROM → SPI and pads: commands
- SPI and pads → SPI flash: frames
- Boot ROM → SRAM: copies bytes
- BOOT strap → SRAM: BOOT = 1: back door
- SRAM → Start-up code, main: jump
The strap and the reset vector live in ap_crg.sv. The chip ships no boot ROM program. For a front-door boot the bench puts the site's loader in the ROM (tools/soc-flash-boot.mjs). The flash model is soc_tb's (facts 27.12, plan §3.10 E19).
Before You Start
Read Back-Door Loading and Clocks, Resets and Straps From the Outside first. The boot flow itself is taught in The Boot Flow and Start-Up Code.
| Question | |
|---|---|
| 1 | What decides where a chip starts after power-up? |
| 2 | What does a back-door load prove, and what does it skip? |
| 3 | How long does a front-door boot of ap_soc take, and why? |
| 4 | How do you measure boot time from a recording? |
| 5 | What should a boot test check besides "main was reached"? |
The Idea: Boot for Real, Rarely
A boot is a chain: the power-up order, the strap, the reset vector and the boot ROM. Then come the loader, the pads, the flash, the copy into SRAM, start-up code and main. A back-door load skips most of it. That is right for nearly every test, because the chain costs thousands of cycles and tests the same thing each time.
But somebody must test the chain. Boot verification boots by the front door, in every boot mode, with the real loader and a model of the boot device. It checks that main is reached, that the image arrived intact, and that it arrived in time. Boot time is a requirement of the product, so it is measured, not guessed.
And when a front-door boot fails, it fails badly: nothing runs, so nothing reports. So boot verification has a back-door half too: tests of each piece the loader relies on, which can say what broke.
New Words
| Word | Meaning |
|---|---|
| Boot mode | Where the first instruction comes from. On ap_soc the BOOT strap picks the boot ROM (0) or SRAM (1). |
| Strap | A pin read once at power-up to set a mode. ap_soc samples BOOT when its PLL locks and keeps it through warm resets. |
| Reset vector | The address of the first instruction: 0x0000_0000 for BOOT = 0, 0x8000_0000 for BOOT = 1. |
| Boot loader | Code in the boot ROM that copies the program from a boot device into memory, then jumps to it. |
| Front-door boot | A real boot: the loader reads the image over the pads from a model of the flash. |
| Back-door load | The bench writes the image into SRAM before the first cycle; no loader runs. |
| Boot time | Cycles from the release of the core's reset to main. ap_soc's core clears mcycle at reset, so mcycle read first thing in main measures it. |
The Smallest Example: What a Frame Costs
The loader brings three bytes per SPI frame, after one frame that rewinds the flash. The lab's 769-byte image needed 258 frames and reached main at cycle 46,851. The same program was then padded to three larger sizes and booted again. Before you read the table: if each frame costs the same, what shape should the times make?
| Image | Frames | mcycle at main | Cycles per frame |
|---|---|---|---|
| 769 bytes | 258 | 46,851 | 181.6 |
| 2,276 bytes | 760 | 137,723 | 181.2 |
| 4,276 bytes | 1,427 | 258,441 | 181.1 |
| 7,776 bytes | 2,593 | 469,505 | 181.1 |
Recorded on ap_soc v1.5 (Verilator 5.052 2026-09-05). Each padded image ends with a known byte, which main printed back: the image arrived to its end.
A straight line. Fitted by least squares through the four boots, it is 152 cycles plus 181 cycles a frame. No measured boot is more than 8 cycles off it. The example below prints the line for other sizes.
| Image | Frames | Cycles to main (line) | Live, at 80,000 cycles a second |
|---|---|---|---|
| 1,024 bytes | 343 | 62,235 | 777 ms |
| 4,096 bytes | 1,367 | 247,579 | 3,094 ms |
| 8,192 bytes | 2,732 | 494,644 | 6,183 ms |
| 16,384 bytes (projected) | 5,463 | 988,955 | 12,361 ms |
| 65,536 bytes (projected) | 21,847 | 3,954,459 | 49,430 ms |
A chip run on this site takes images of up to 8,192 bytes, so rows above that are projections of the line, not measurements. The live speed is the plan's planning figure. Even so the point is plain: a front-door boot of a full 64 KiB image would cost close to a minute live. A regression boots for real a few times, never for every test.
The Rules
Rule 1: Boot every boot mode for real, at least once.
Each strap value starts a different chain. Only a front-door boot tests the loader, the pads and the boot device.
Rule 2: Use the back door for everything else.
On ap_soc a small image reached main 249 times later by the front door: about 46,663 cycles more.
Rule 3: Check where the chip started.
Read the strap as the chip sampled it (STRAPS), and compare with the boot the bench made.
Rule 4: Check that the image arrived intact.
A loader can copy the wrong length, the wrong bytes or the wrong place. Check the image's start and its end.
Rule 5: Measure boot time from the run itself.
mcycle read first thing in main counts from the core's reset; compare it with the product's budget.
Rule 6: Test the loader's pieces by the back door.
A front-door boot that hangs explains nothing. A back-door test of the strap, the pin mux, the SPI clock and the flash names the broken piece.
Sources for These Rules
The strap, sampled once, and the reset vector: ap_crg_boot.sv and ap_crg.sv; facts 11 and 27.11.
The front-door boot of the bench: args.bootFromFlash, the loader tools/soc-flash-boot.mjs and the 64 KiB flash image. See plan §3.10 E19 and the bench README.
mcycle counts the core's clock cycles (RV-PRIV 3.1.10). The specification leaves its value after reset arbitrary; ap_rv32 clears it at reset (ap_rv32_csr.sv). Checked here against the bench's cycle numbers.
Live speed: plan §6.2 ("plan on 80 thousand cycles a second") and facts 27.13.
The Lab: One Image, Two Boots
One small program prints mcycle, read as its first act, and STRAPS. The bench runs it twice: once loaded by the back door with BOOT = 1, once booted from the flash with BOOT = 0.
back door: CONSOLE 709: main at cycle 000000bc straps 00000001
front door: CONSOLE 47372: main at cycle 0000b703 straps 00000000| Back door | Front door | |
|---|---|---|
| STRAPS | 1 | 0 |
| mcycle at main | 188 | 46,851 |
| Cycles of the whole run | 741 | 47,404 |
| SPI frames | 0 | 258 |
| Live time, projected at 80,000 cycles a second | 9 ms | 593 ms |
Recorded on ap_soc v1.5 (Verilator 5.052 2026-09-05, riscv64-unknown-elf-gcc). The live row is a projection from the plan's figure, not a measurement.
Rule 5 at work: the front-door boot took 258 frames for 769 bytes. That is three bytes a frame, plus one frame to rewind the flash. The image arrived and ran the same; only STRAPS and the boot time differ. That is the cost the problem pages call "slow by design".
One thing the lab leaves out: ap_soc v1.5 has no boot ROM program of its own. Its ROM holds whatever image the bench loads. For a front-door boot the bench loads a short loader of this site. It stands in for the ROM a product would ship. It routes the SPI pads, rewinds the flash, then reads three bytes a frame and stores them one by one.
li s0, 0x10005000
li s1, 0x10004010
li t0, 0xaaa
sw t0, 0(s1)
li s2, 0x80000000
li s3, LENGTH
li a0, 0x66
jal ra, frame
copy:
li a0, 3
jal ra, frame
li t2, 16
byte_loop:
srl t0, a0, t2
sb t0, 0(s2)
addi s2, s2, 1
addi s3, s3, -1
beq s3, zero, enter
addi t2, t2, -8
bge t2, zero, byte_loop
j copy
enter:
sw zero, 0(s1)
li t0, 0x80000000
jalr zero, 0(t0)
frame:
li t1, 2
sw t1, 4(s0)
sw a0, 0(s0)
busy:
lw t0, 4(s0)
andi t0, t0, 2
beq t0, zero, busy
lw a0, 0(s0)
retWhy It Is Built This Way
Why sample the strap once, when the PLL locks? Because a strap pad may be shared with another function later, and a mode must not change under a running program. Warm resets keep the sampled value; only power-up reads the pad again.
Why can the SPI read not carry an address? ap_soc's SPI controller makes one frame: a command byte and 24 reply clocks. So the flash model keeps its own position: 0x66 rewinds it, 0x03 returns the next three bytes. A real flash takes an address; the loop of the loader is the same idea.
Traps
The first trap is a boot path that only the back door ever ran. Every test passes; the loader, the pin mux of the SPI pads and the flash timing never ran once. The first real boot is on a board, where nothing can be seen.
The second is a boot test that checks only that main was reached. A loader that copies a few bytes too few still reaches main, if the missing bytes are data the program reads late. Check the end of the image too.
The third is a front-door boot in every test. It is honest, and it makes the regression many times slower for no new information. Boot for real in a few tests; load by the back door in the rest.
At Scale
This section looks ahead. ap_soc has two boot modes and a loader of a page.
Many boot devices
Large chips boot from flash, eMMC, USB, a host link or the network, each a mode to boot for real.
Secure boot
The ROM checks a signature before it jumps. Boot verification then tests good images, bad signatures and every refusal path.
Faster front doors
Teams shorten the front door with smaller images, faster device models or a hybrid platform (V13). They still keep one full boot.
Try It
Run it: the line's cycles and live time for five image sizes, two of them beyond the measured range.
Which part of the cost grows with the image, and which does not?
Change PER_FRAME to half: what would a faster SPI clock save on a 64 KiB image?
1024 bytes: 343 frames, about 62235 cycles to main, 777 ms live 4096 bytes: 1367 frames, about 247579 cycles to main, 3094 ms live 8192 bytes: 2732 frames, about 494644 cycles to main, 6183 ms live 16384 bytes: 5463 frames, about 988955 cycles to main, 12361 ms live (projected) 65536 bytes: 21847 frames, about 3954459 cycles to main, 49430 ms live (projected)Check Yourself
Common Mistakes
Wrong Load every test by the back door, the boot test too.
The loader, the pads and the boot device never run in simulation.
Fix Boot by the front door, in every boot mode, at least once.
Wrong Pass a boot test once main is reached.
An image copied short or wrong can still reach main.
Fix Check where the chip started, the image's start and end, and the boot time.
Wrong Boot from the flash in every test.
It costs thousands of cycles each time and tests the same chain again.
Fix Keep front-door boots to a few tests and use the back door for the rest.
Remember
- The strap, sampled once at power-up, picks the boot: the ROM's loader from flash, or SRAM loaded by the back door.
- Only a front-door boot tests the loader, the pads and the boot device.
- A front-door boot is slow by design: three bytes a frame, about 181 cycles a frame here.
- A boot test checks the start, the image's integrity and the boot time; back-door tests of the pieces explain a hang.