Hardware interview practice
Validate a compact secure-boot manifest
A boot ROM reads a fixed 16-byte manifest before starting a firmware image. Write C code that parses and validates the manifest before publishing fields.
Starting point
Question code
int parse_manifest(const uint8_t raw[16],
uint32_t flash_size,
uint32_t *entry, uint32_t *image_len);
// LE: magic[0:3], entry[4:7], len[8:11], reserved[12:13], sum[14:15]Reviewed example
Work through one case
Input
A 16-byte BCM1 manifest has entry=0x1000, len=0x2000, zero reserved bytes, a correct seven-word checksum, and flash_size=0x10000.Expected output
parse_manifest returns 0, entry=0x1000, and image_len=0x2000.Magic, reserved fields, checksum, and the non-wrapping interval [0x1000,0x3000) all validate before either output is written.
What to cover
Requirements
- Require raw, entry, and image_len; require magic bytes 'B','C','M','1' and reserved bytes zero; return -1 and preserve outputs otherwise.
- Interpret entry, len, and checksum as little-endian. The 16-bit sum of the first seven little-endian 16-bit words modulo 65536 must equal stored checksum.
- Require len>0, entry<flash_size, and len<=flash_size-entry without unsigned overflow.
- Only after every check, write entry and image_len and return 0.
