S9.6.1 Refuse the Tampered Image

MediumImplement30 minIcarus Verilog · serverReview the topic

Build the gate that reads a firmware image word by word and checks its magic, length, version and tag. ap_soc boots only when every check passes.

Hardware context: ap_soc boot image gate and life-cycle debug gate. Secure boot and production debug lock

The S9.6 lab checked an image with a plain sum that anyone can recompute. Your gate mixes a key from one-time memory, otp_key, into the tag. Adding one to the tag no longer fixes up a change.

This tag is a teaching model, not a cryptographic signature. Its mixing is linear, so one genuine image and its tag are enough to forge a changed copy. The image layout, the tag and the reason codes are ap_soc design choices.

Signals in the Timeline

SignalWidthRole
sample10input of each check
Full specification
WordFieldRule
0magicMust be 32'h4150_5342
1versionUnsigned; must be at least otp_min_version
2lengthPayload words; must be 1 to 8 and equal the number of payload words received
3tagMust equal the computed tag
4 onwardpayloadCovered by the tag

The tag starts at otp_key. For version, then length, then each payload word in order: t = {t[26:0], t[31:27]} ^ word. The magic and tag words are not mixed in.

A word is accepted at a rising edge of clk with in_valid = 1. Gap cycles (in_valid = 0) change nothing. The word with in_last = 1 is the last one. At that edge, set done = 1 and report the first failing check. The order is magic (reason 1), length (2), version (3), tag (4). With no failure, reason = 0 and boot_ok = 1.

A stream that ends inside the header fails the length check unless its magic word is wrong. Before the last word, done, boot_ok and reason stay 0. After done, hold every output until reset and ignore further words.

rst_n is a synchronous active-low reset. otp_key and otp_min_version are stable from reset onward.

Examples

Example 1

Genuine Image
Input
A genuine version 3 image with four payload words
Output
reason = 0, boot_ok = 1, done = 1, changed_after_done = 0, early = 0

Every check passes, so done and boot_ok rise together at the last word.

Example 2

One Payload Word Changed
Input
The same image with the debug flag word flipped to 1
Output
reason = 4, boot_ok = 0, done = 1, changed_after_done = 0, early = 0

Only the tag check fails: reason 4. The stored tag no longer matches the changed payload.

Example 3

Old Image
Input
A genuine version 2 image when the floor is 3
Output
reason = 3, boot_ok = 0, done = 1, changed_after_done = 0, early = 0

The tag is genuine, but version 2 is below the floor of 3: reason 3.

Constraints and Contract

  • Implement module boot_gate. The graded outputs are done, boot_ok and reason.
  • Use only your ports. Force, release, defparam, bind and hierarchical names are refused.

Hints

Hint 1

Keep the header words in registers, but decide with the values that include the word on the wires.

Hint 2

The tag never mixes in words 0 and 3.

Hint 3

Write the four checks as one priority chain.

What the grader checks: Genuine images of every length and single-bit changes to the header, key and payload. Also the version floor bit by bit, length limits, short streams, priorities and gaps.

291 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

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

Genuine Image

Input
A genuine version 3 image with four payload words
Expected output
reason = 0, boot_ok = 1, done = 1, changed_after_done = 0, early = 0

Every check passes, so done and boot_ok rise together at the last word.

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

Icarus Verilog · server