Secure Boot, Life Cycle and Debug Lock
A chip runs whatever program it finds, unless something checks the program first. The check must be one that an attacker cannot change, cannot repeat and cannot go around through the debug port.
You Will Be Able To
- Explain why the first check lives in ROM, and why it comes before the jump.
- Show why a plain sum cannot stop a deliberate change, and what a version floor adds.
- Read a table of life-cycle states, and say what a damaged state must do.
- Lesson
- S9.6
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
A forum post shows your board printing the message of somebody else. Nobody opened the chip. They wrote a new program into its flash, and the chip ran it.
Between reset and the first instruction of that program, the chip had one chance to refuse.
Before You Start
You need The Boot Flow: the Boot ROM at the reset address, the loader, the image, and the handover as the last step.
You need The Debug Module on the Bus: the debug lock, and the debug key that opens it.
You need Security Architecture: a key that is written, used and never read, and the debugger as a route.
| Question | |
|---|---|
| 1 | Why must the first check of an image be done by code in ROM? |
| 2 | Why does a plain sum stored in the image not stop an attacker? |
| 3 | What does a version floor refuse that a correct tag lets through? |
| 4 | What does the life-cycle state decide, and what happens when its code is damaged? |
| 5 | The version floor is 2 in place of 3. What is the last row of the lab? |
The Idea: Check First, with Something the Attacker Lacks
The loader in the Boot ROM copies an image into memory and jumps to it. It does that for any image. So whoever can write the flash decides what the chip runs. Secure boot adds one step before the jump: check the image, and refuse it if the check fails.
The check needs a checker that can be trusted. If the checker sat in memory that can be rewritten, the attacker would rewrite the checker first. So it sits in the ROM, which nobody can change after the chip is made. That starting point is the root of trust.
Next, the check itself. The attacker knows how it works, because the method is no secret. So the check must need something that the attacker does not have. And the values it compares against must live outside the image, where the attacker cannot write.
One door is still open: the debug port. A debugger that can halt the processor and write memory needs no image at all. So the chip keeps a life-cycle state. It says where the chip is in its life, from the tester to the customer. That state decides whether the debug lock may open.
New Words
| Word | Meaning |
|---|---|
| Secure boot flow | A boot flow in which each program is checked before the jump to it. Secure boot for short. |
| Root of trust | The first checker. Everything later relies on it, so it must be impossible to change. Here it is the code in the Boot ROM. |
| Header of an image | A few words in front of the program. Here: a mark, the version, the length and the tag. |
| Image tag | A number in the header that depends on the content of the image. The loader works it out again and compares. |
| Plain sum | A tag made by adding up the words. Anybody can work it out. |
| Signature of an image | A tag that only the holder of a secret key can make. The chip can check it without holding that secret. |
| One-time memory | Memory in which a bit can be written once and never erased. Engineers also say fuses. |
| Version floor | The lowest version that the chip still accepts. It is kept in one-time memory and can only go up. |
| Rollback | Loading an old image, correctly made, that has a known fault. |
| Life-cycle state | A code in one-time memory that says where the chip is in its life. |
| TEST, DEV, PROD | Three life-cycle states: on the tester of the factory, with the developers, and in the product. |
| RMA | Return merchandise authorization: the state of a part that came back to its maker to be examined. |
| Fail closed | When something is damaged or unknown, every door closes. |
One Picture: The Chain of Trust
- Memory
- Processor
- Root of trust
The ROM is the first code to run, and nothing can rewrite it. Every later check rests on it.
- Reference values
One-time memory holds what the ROM compares against: the lowest version allowed and, in a real design, key material.
- Check before run
The ROM checks the image tag and version before it executes a single image instruction.
- Hand over
Only a passing image gets the jump. A failing one never runs.
Read the diagram as text
- Boot ROM: fixed in silicon
- One-time memory: min version, keys
- Firmware image: in SRAM, checked
- Application: runs only if checked
- One-time memory → Boot ROM: reference values
- Boot ROM → Firmware image: check tag, version
- Firmware image → Application: jump
Architecture drawing. ap_soc has a two-link chain. S10.15 draws a longer chain for large SoCs.
The Smallest Example, Worked by Hand
No simulator yet. An image has a header and two words of program. The second program word is a flag: 1 would open the debug port. The tag is a plain sum of the version, the length and the program words. The version floor of the chip is 3.
| Image | Version | Length | Program words | Tag in the header | Sum worked out | Verdict |
|---|---|---|---|---|---|---|
| Genuine | 3 | 2 | 5 and 0 | 10 | 3 + 2 + 5 + 0 = 10 | Jump |
| Flag changed to 1 | 3 | 2 | 5 and 1 | 10 | 11 | Refuse: the tag does not match |
| Flag changed, and the tag too | 3 | 2 | 5 and 1 | 11 | 11 | Jump |
| An old genuine image | 2 | 2 | 5 and 0 | 9 | 9 | Refuse: version 2 is below the floor |
Read the second row. One word was changed, and the sum no longer matches. So far the check works.
Read the third row. The attacker changed the tag as well, by adding 1. The sum matches again, and the changed image runs. A plain sum finds an accident. It does not stop anybody who can do an addition.
Read the fourth row. Nothing in this image was changed. It is a real release, version 2, which had a fault that version 3 repaired. Its tag is perfect. Only the floor refuses it.
The Rules
Rule 1: The first check is done by code that cannot be changed.
On
ap_socthat is the Boot ROM at the reset address.Rule 2: Check first, jump last.
An image that fails never runs one instruction. Each later program checks the next one in the same way.
Rule 3: A check must need something that the attacker does not have.
A plain sum needs nothing. A signature needs a secret that never leaves its maker.
Rule 4: The values to compare against live outside the image.
In the ROM or in one-time memory. The image is the thing being checked.
Rule 5: A version floor refuses an old image, even with a correct tag.
The floor is in one-time memory, and it only goes up.
Rule 6: The life-cycle state decides which doors may open, and any unknown code closes them all.
The debug lock opens only where the table of states allows it.
| State | Code | JTAG port | Halt and bus access by the debugger | Test mode | Keys usable |
|---|---|---|---|---|---|
| TEST | 3C | Open | Open | Open | No |
| DEV | 5A | Open | Open | Closed | Yes |
| PROD | 96 | Open | Only after the debug lock opens | Closed | Only while the debug lock is closed |
| RMA | C3 | Open | Open | Open | No |
| Any other code | none | Closed | Closed | Closed | No |
The codes are bytes in hex. These states, codes and doors are choices of ap_soc.
Read the row of PROD. The JTAG port stays open, because a debugger needs a way in to show its debug key. Halt and bus access open only after that. While they are open, the keys cannot be used.
Read the row of RMA. A part that failed at a customer comes back to be examined. Debug and test are open again, as on the tester. The keys are not usable, so the secrets of the customer stay closed.
Now the codes. Any two of the four differ in at least four bits. One flipped bit can never turn PROD into DEV. It gives a code that is not in the table, and rule 6 closes every door.
Sources for These Rules
The Boot ROM at address 0: the memory map of ap_soc. The loader and the handover: the lesson on the boot flow.
Rules 1 to 5 are general practice. Our reference library holds no standard for secure boot, and no source that states them. Rows of the lab show rules 2, 3 and 5.
Rule 6, the four states, their codes and their doors are choices of ap_soc. The names TEST, DEV, PROD and RMA are in common use. No standard for them is in the library.
That real chips check a signature, and hold only what is needed to check one, is general practice and not checked against a source.
Now Run It
The lab at the end of this page checks four images, as the hand example did. No processor runs here. A task of the test code does the steps that the program in the ROM would do. An array stands for SRAM.
genuine version=3 tag=100000de computed=100000de min=3 -> JUMP 80000010
tampered version=3 tag=100000de computed=100000df min=3 -> REFUSE tag
fixed-up version=3 tag=100000df computed=100000df min=3 -> JUMP 80000010
rollback version=2 tag=100000dd computed=100000dd min=3 -> REFUSE versionRule 2 at work, in the second row. The flag was changed, and the sum that the loader worked out moved from 100000de to 100000df. The verdict refuses it and names the tag. The changed image never ran.
Rule 3, in the third row. The attacker added 1 to the tag. Both numbers read 100000df, and the image gets the jump.
Rules 4 and 5, in the fourth row. The tag matches, and the image is still refused, because version 2 is below min=3. The floor was read from one-time memory, not from the image.
The address of the jump is 80000010. This image has a header of four words, so its first instruction is the fifth word of SRAM. The plain image of the boot flow lesson had no header and began at 80000000.
This lab leaves things out. Its tag is a plain sum, to show why a sum is not enough. It holds no key and no signature. The life-cycle states are not in this lab: you build their gate in the practice problem "Life Cycle and the Debug Port".
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| The first checker in ROM | A checker in flash, which can be repaired later | Nobody can replace it. A fault in it is in every chip for ever. |
| A floor in one-time memory | A list of bad versions in the image | The attacker cannot lower it. Each step up uses bits that never come back. |
| The JTAG port open in PROD | The port closed for good | The maker can still open debug with the debug key. The lock and the key must be sound. |
| Codes four bits apart | A code of two bits | A disturbed bit gives an unknown code, not another state. The decoder compares eight bits. |
The practice problem "Refuse the Tampered Image" goes one step past the plain sum. Its tag mixes in a key from one-time memory. It is still a teaching model. Its mixing is simple enough that one genuine image and its tag let a changed copy be made.
The Trap: One Bit Away from a Development Part
A chip kept its life-cycle state in two bits: 00 for the tester, 01 for developers, 10 for the product. The decoder was tiny, and the review passed it.
Then someone disturbed the supply at the moment the state was read. One bit flipped, and a product part read 00. Every debug and test door opened, on a chip in the hands of a customer.
The fault is in the code book. With two bits, every damaged value is another valid state. With codes that are four bits apart, a damaged value is no state at all, and the chip fails closed.
The second trap is to believe a tag. A correct signature says that the maker made this image. It does not say that the image is the newest one. Only the floor says that.
At Scale
This section looks ahead. One image and one ROM become several stages and several keys. The items are general practice, given as illustration.
The chain grows
The ROM checks a first loader, which checks trusted firmware, which checks the operating system. A later lesson draws that chain.
The root cannot be repaired
A fault in ROM code ships in every part. So that code is kept small, and every way of refusing is tested.
Floors run out
Each step of the floor uses bits of one-time memory. The number of steps is planned before the chip is made.
One way only
A part moves from TEST to DEV to PROD, and perhaps to RMA. Each move is written once. A move back would make a product part a development part.
Try It
Run the four images. Find the row in which a changed image still gets the jump.
Raise the version floor to 4 before the first check. It is a variable named otp_min_version. Which rows still jump?
Change the tampered image so that the attacker also adds one to the version word. Which check refuses it first?
Names Printed by the Lab
| Name | Meaning |
|---|---|
| genuine, tampered, fixed-up, rollback | The four images that the lab checks, one after another. |
| version | The version word in the header of the image. |
| tag | The tag word in the header: the sum that the maker of the image wrote there. |
| computed | The sum that the loader works out from the image itself. |
| min | The version floor, read from one-time memory. |
| JUMP, REFUSE | The verdict. JUMP shows the address of the first instruction. REFUSE names the check that failed. |
genuine version=3 tag=100000de computed=100000de min=3 -> JUMP 80000010 tampered version=3 tag=100000de computed=100000df min=3 -> REFUSE tag fixed-up version=3 tag=100000df computed=100000df min=3 -> JUMP 80000010 rollback version=2 tag=100000dd computed=100000dd min=3 -> REFUSE versionRead included file: boot_rom.svh
// The S9.6 boot ROM model. ap_rv32 is built later in the track, so this task runs the steps the
// ROM program will run. The image layout and the checks are ap_soc design choices:
// word 0 magic "APSB" word 1 version word 2 payload length in words word 3 tag
// words 4 onward: the payload, which starts at IMAGE + 0x10
// The tag here is a plain 32-bit sum of version, length and payload. It stands in for a signature
// and holds no secret. otp_min_version models the anti-rollback counter in one-time memory.
localparam logic [31:0] IMAGE = 32'h8000_0000, MAGIC = 32'h4150_5342;
logic [31:0] sram [0:15];
logic [31:0] otp_min_version = 3;
task automatic rom_boot_check(input string name);
logic [31:0] sum;
string verdict;
sum = sram[1] + sram[2];
for (int i = 0; i < sram[2] && i < 12; i++)
sum = sum + sram[4 + i];
if (sram[0] != MAGIC) verdict = "REFUSE magic";
else if (sum != sram[3]) verdict = "REFUSE tag";
else if (sram[1] < otp_min_version) verdict = "REFUSE version";
else verdict = $sformatf("JUMP %08h", IMAGE + 32'h10);
$display("%s version=%0d tag=%08h computed=%08h min=%0d -> %s",
name, sram[1], sram[3], sum, otp_min_version, verdict);
endtask
Check Yourself
Common Mistakes
Wrong Trust a plain sum that is stored in the image.
Whoever changes the image can work the sum out again.
Fix Use a check that needs a secret, and keep the reference values outside the image.
Wrong Treat a correct tag as proof that the image is the newest.
An old genuine image has a correct tag too.
Fix Compare its version with a floor in one-time memory.
Wrong Decode the life-cycle state from a few bits.
One flipped bit then turns a product part into a development part.
Fix Compare the whole code, and close every door on any other value.
Remember
- The first check is done by code that nobody can change, and it comes before the jump.
- A check must need something that the attacker does not have. A plain sum needs nothing.
- A version floor in one-time memory refuses old genuine images.
- The life-cycle state decides which doors may open, and a damaged state closes them all.