V9.3.1 A Boot Test with a Deadline

MediumImplement25 minap_soc v1.5 · firmware · serverReview the topic

Write a boot test that runs unchanged after a back-door load and after a real boot from the SPI flash. It reports which boot it had and checks that its image arrived intact. It fails when the boot took longer than the bench allows.

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. A boot test that runs after both boots, with a deadline.

A boot test proves three things: the chip started where its strap says, the image arrived intact, and it arrived in time. Write one that works after both kinds of start. The back door loads SRAM before the first cycle. The front door is a real boot: the ROM's loader copies your image from the SPI flash, then jumps to it.

Print boot: sram when STRAPS bit 0 (BOOT) is 1, and boot: flash when it is 0. Then add the sixteen words of boot_table. If the sum is not 0x8888_8888, print boot: image bad and fail with code 2.

Read mcycle as the first thing in main: it counts the cycles since the core left reset. TB_ARG holds the bench's deadline. If your count is above it, print boot: late and fail with code 1. Otherwise print boot: in time and pass.

Full specification
BootBOOT strapFirst instructionBefore main
Back door10x8000_0000 in SRAMstart-up code only
Front door00x0000_0000: the boot ROM's loaderthe loader copies the image three bytes at a time over SPI, then start-up code

Recorded boot times of a small image: main at cycle 188 after a back-door load. After the flash boot it was 46,851 (258 SPI frames). Your image is larger or smaller, so your times differ. The deadlines of the cases are far from both.

STRAPS is at 0x1000_400C. In some cases the bench changes a word of your image by the back door before the first instruction.

ap_soc v1.5 ships no boot ROM program. For a front-door boot the bench puts a short loader of this site in the ROM. The V9.3 lab shows it. It stands in for the boot ROM a product would ship.

Given Files

Read-only files supplied by the bench.

tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif

hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"

/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
    return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
    *(volatile unsigned *)address = value;
}
#endif

#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif

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

A Back-Door Load
Input
Back-door load, deadline 2,000 cycles
Output
"boot: sram", "boot: in time"; pass

BOOT is 1, the table adds up, and main starts long before cycle 2,000.

Example 2

A Boot from the Flash
Input
Boot from the flash, deadline 1,000,000 cycles
Output
"boot: flash", "boot: in time"; pass

The loader copied the image before main; the count includes it and is still far below the deadline.

Example 3

The Same Boot, a Tight Deadline
Input
Boot from the flash, deadline 3,000 cycles
Output
"boot: flash", "boot: late"; fail code 1

The copy over SPI alone takes many thousands of cycles, so a deadline of 3,000 is missed.

Constraints and Contract

  • C firmware with the kit, SRAM layout; the same image for every case.
  • Print exactly the two lines the statement names, in that order.
  • Keep boot_table as given: the bench finds it by name.

Hints

Hint 1

Which register tells the program how it was started?

Hint 2

Read the cycle counter before anything else. Why does it matter where?

Hint 3

Why check the image after a boot at all? What could the loader get wrong?

What the grader checks: Each case runs your image once: by the back door, or by the boot ROM's loader from the flash. The console and the status word are compared. The grader cannot see whether you read mcycle first, only whether late boots fail and quick ones pass.

6 checks on ap_soc v1.5 · firmware · 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 CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

A Back-Door Load

Input
Back-door load, deadline 2,000 cycles
Expected output
"boot: sram", "boot: in time"; pass

BOOT is 1, the table adds up, and main starts long before cycle 2,000.

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

ap_soc v1.5 · firmware · server