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.

The Boot Path, from Power to MainThe BOOT strap, sampled once at power-up, picks the boot ROM and its loader, or SRAM loaded by the back door.
  • Clock / reset
  • Pads
  • Memory
  • Peripheral
  • External
  • Processor
  • Control
  • Data
The Boot Path, From Power to mainThe BOOT strap, sampled once at power-up, picks the boot ROM and its loader, or SRAM loaded by the back door. clock reset Power-up POR, PLL lock pads BOOT strap sampled once memory Boot ROM the loader peripheral SPI and pads IO2 to IO5 external SPI flash the image memory SRAM 0x8000_0000 processor Start-up code,main the program onceBOOT = 0commandsframescopies bytesBOOT = 1: back doorjump
  1. clock reset Power-upPOR, PLL lock
    • once → BOOT strap
  2. pads BOOT strapsampled once
    • BOOT = 0 → Boot ROM
    • BOOT = 1: back door → SRAM
  3. memory Boot ROMthe loader
    • commands → SPI and pads
    • copies bytes → SRAM
  4. peripheral SPI and padsIO2 to IO5
    • frames → SPI flash
  5. external SPI flashthe image
  6. memory SRAM0x8000_0000
    • jump → Start-up code, main
  7. processor Start-up code, mainthe program
  1. The strap

    The chip samples BOOT once, after power-up, and keeps it through every warm reset.

  2. The front door

    BOOT = 0 starts the ROM. Its loader reads the flash over the SPI pads, three bytes a frame, and writes SRAM.

  3. The back door

    BOOT = 1 starts at SRAM, which the bench loaded before the first cycle. No loader, no SPI, no flash.

  4. 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.

Five questions this page answers
Question
1What decides where a chip starts after power-up?
2What does a back-door load prove, and what does it skip?
3How long does a front-door boot of ap_soc take, and why?
4How do you measure boot time from a recording?
5What 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

New words on this page
WordMeaning
Boot modeWhere the first instruction comes from. On ap_soc the BOOT strap picks the boot ROM (0) or SRAM (1).
StrapA 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 vectorThe address of the first instruction: 0x0000_0000 for BOOT = 0, 0x8000_0000 for BOOT = 1.
Boot loaderCode in the boot ROM that copies the program from a boot device into memory, then jumps to it.
Front-door bootA real boot: the loader reads the image over the pads from a model of the flash.
Back-door loadThe bench writes the image into SRAM before the first cycle; no loader runs.
Boot timeCycles 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?

Four measured boots from the flash
ImageFramesmcycle at mainCycles per frame
769 bytes25846,851181.6
2,276 bytes760137,723181.2
4,276 bytes1,427258,441181.1
7,776 bytes2,593469,505181.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.

The fitted line, worked
ImageFramesCycles to main (line)Live, at 80,000 cycles a second
1,024 bytes34362,235777 ms
4,096 bytes1,367247,5793,094 ms
8,192 bytes2,732494,6446,183 ms
16,384 bytes (projected)5,463988,95512,361 ms
65,536 bytes (projected)21,8473,954,45949,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

  1. 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.

  2. 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.

  3. Rule 3: Check where the chip started.

    Read the strap as the chip sampled it (STRAPS), and compare with the boot the bench made.

  4. 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.

  5. 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.

  6. 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.

The console line of each boot (cycle numbers are the bench's).
back door:  CONSOLE 709: main at cycle 000000bc straps 00000001
front door: CONSOLE 47372: main at cycle 0000b703 straps 00000000
The two boots, measured
Back doorFront door
STRAPS10
mcycle at main18846,851
Cycles of the whole run74147,404
SPI frames0258
Live time, projected at 80,000 cycles a second9 ms593 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.

The boot ROM loader of the bench (tools/soc-flash-boot.mjs), as assembled for the lab; LENGTH is the image's size.
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)
ret

Why 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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has two boot modes and a loader of a page.

  1. Many boot devices

    Large chips boot from flash, eMMC, USB, a host link or the network, each a mode to boot for real.

  2. Secure boot

    The ROM checks a signature before it jumps. Boot verification then tests good images, bad signatures and every refusal path.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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

Predict the outputThe line is asked about a 32 KiB image. What does it print?
// The cost of a front-door boot of ap_soc v1.5, from a straight line fitted through four measured boots of
// images up to about 7,800 bytes: 181 cycles of clk_sys a SPI frame, 152 cycles for everything else.
// One frame rewinds the flash; each other frame brings three bytes. Beyond 8192 bytes the line is a projection:
// a chip run on this site takes images of up to 8192 bytes, so no larger boot was measured. Live times assume 80,000 cycles
// a second, the planning figure for the site's server.
module tb;
  localparam int PER_FRAME = 181, FIXED = 152;
  int frames, cycles;
  task automatic show(input int bytes);
    frames = (bytes + 2) / 3 + 1;
    cycles = FIXED + frames * PER_FRAME;
    if (bytes > 8192) $display("%6d bytes: %5d frames, about %8d cycles to main, %0d ms live (projected)", bytes, frames, cycles, cycles / 80);
    else $display("%6d bytes: %5d frames, about %8d cycles to main, %0d ms live", bytes, frames, cycles, cycles / 80);
  endtask
  initial begin
    show(32768);
  end
endmodule
ConceptWhat does a back-door load skip?
ConceptHow did the lab measure boot time?
ConceptWhy does ap_soc keep the sampled strap through warm resets?
ConceptA front-door boot hangs before main. What explains the failure?

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.

Practice

Report a problem with this page