V9.3.2 Prove the Boot Path

HardVerify30 minap_soc v1.5 · assembly · serverReview the topic

Write the boot self-test in assembly, the language of boot code. Loaded by the back door, it tests each piece the boot ROM's loader relies on. Those are the boot mode, the pads, the SPI controller and the flash. It passes on ap_soc and fails visibly on every faulty chip of a hidden set.

Hardware context: The boot path of ap_soc v1.5: the BOOT strap, the boot ROM's loader, the SPI pads and a flash model. An assembly self-test of the boot device.

A front-door boot is the honest test of a boot path, but its failure says little. When the flash stays silent, the loader copies nothing useful, the core runs garbage, and the run ends at the cycle limit. So boot verification also has a back-door half. A self-test checks each piece the loader relies on, and names the one that failed.

Write that self-test in assembly, as boot code is written. It is loaded by the back door, so STRAPS bit 0 must read 1. Route pads IO0 to IO5 to their serial functions (PINMUX 0xAAA). Ask the flash for its ID with command 0x9F; it must answer 0xC0FFEE. Then send 0x66 (back to byte 0) and 0x03, which returns the first three bytes, the first in bits 23 to 16.

TB_ARG holds the three bytes the bench put at the start of its flash. Compare. Write the pass word if every check holds, a fail word otherwise, and give every wait a limit. A faulty chip is caught when your test writes a fail word, or a check of the bench fails. A run that ends at the cycle limit is not caught.

Full specification
SPI registerAddressUse
DATA0x1000_5000Write: a command byte starts a frame of 8 clocks out and 24 back. Read: the 24 bits that came back
STATUS0x1000_5004Bit 1 DONE: the frame has ended; write 1 to clear it. Bit 0 BUSY
Flash commandAnswer
0x9F0xC0FFEE, its ID
0x66back to byte 0 (the answer is not data)
0x03the next three bytes, the first in bits 23 to 16
any other0xC0FFEE

The recorded reference took 515 cycles and three frames. A front-door boot of the same 192-byte program took 11,782 cycles and 65 frames of the loader (recorded). Three instructions are put in front of your program (TB_STATUS = 2, "main entered").

Given Files

Read-only files supplied by the bench.

defs.S
# defs.S: addresses and helpers of the smoke programs of ap_soc v1.5 (stage E4).
# check-soc-top.mjs puts this text in front of every program. Numbers: gen/ap_soc_regs.h.
.equ ROM,      0x00000000
.equ CLINT,    0x02000000
.equ PLIC,     0x0C000000
.equ UART,     0x10000000
.equ GPIO,     0x10001000
.equ TIMER,    0x10002000
.equ WDOG,     0x10003000
.equ SYSCTL,   0x10004000
.equ SPI,      0x10005000
.equ DMA,      0x10006000
.equ HOLE,     0x10007000
.equ PWRCTL,   0x10008000
.equ SRAM,     0x80000000
.equ TB_STATUS, 0x20
.equ TB_PUTC,   0x24
.equ TB_EVENT,  0x28
.equ TB_ARG,    0x2C

SPI · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000DATA7:0commandwonot storedWrite: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte.
0x000DATA23:0receivedroblockLast 24 bits received.
0x004STATUS0busyroblockFrame state. A frame is running, and chip select is low.
0x004STATUS1donew1cblockA frame has ended (new in v1.5).
0x008IRQ_ENABLE0donerw0x0regsLets DONE raise interrupt source 4 (new in v1.5). 1 enables the request.
ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.

Examples

Example 1

The Good Chip
Input
The bench's flash starts with 5A 3C 97
Output
pass, 3 SPI frames

STRAPS is 1. The flash answers its ID, then 0x5A3C97, the bench's first three bytes.

Example 2

Another Pattern
Input
The bench's flash starts with 0F E1 2B
Output
pass, 3 SPI frames

The same test with another flash: TB_ARG now holds 0x0FE12B. A test that compared with a constant fails here.

Example 3

A Silent Flash
Input
a hidden chip
Output
your fail word

A front-door boot of this chip ends at the cycle limit and explains nothing. The self-test asks the flash, waits with a limit, and fails with a code.

Constraints and Contract

  • Assembly for the SRAM layout, with the names of defs.S.
  • Two cases, each run on the good chip and on every hidden chip. The good chip must pass both.
  • The hidden set holds faults on the boot path between the pins of the SPI controller and the flash.

Hints

Hint 1

What does your test do if the flash never answers, or DONE never rises?

Hint 2

The flash sends the first byte first. Where does it land in DATA?

Hint 3

Which value tells you what the flash should hold? It changes from case to case.

What the grader checks: Each case runs on the good chip and on every hidden faulty chip. The good chip must pass both cases. Each faulty chip must end with a fail word or a bench check in every case. The bench's SPI monitor checks every frame on the pads. So one hidden fault is caught by any test that makes a frame. The other only your own checks can catch. The grader cannot see whether your waits have limits on these chips: give them limits anyway.

2 checks on ap_soc v1.5 · assembly · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 problems on this path

Report a problem with this page

Your code RISC-V assemblySaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

The Good Chip

Input
The bench's flash starts with 5A 3C 97
Expected output
pass, 3 SPI frames

STRAPS is 1. The flash answers its ID, then 0x5A3C97, the bench's first three bytes.

Run samples executes all 2 public checks. Check all tests runs 2 checks on the server.

ap_soc v1.5 · assembly · server