A signed boot chain refuses a flipped bit, and an A/B update that waits for a confirm cannot brick, even when the power dies mid-write. Break each stage and cut the power yourself.
Press Power on, then flip one bit in the kernel and power on again. Next, close the fuse with an unsigned SPL. Then we build, piece by piece, the fuses, the signatures, the hash tree and the A/B update that never leaves a unit dead.
You need a rough idea of what a hash is (a short fingerprint of a file: change one bit and the fingerprint changes) and how a Linux board boots. We build the rest from zero.
Part of the Physical AI Systems track. Built from primary sources: the Linux kernel dm-verity and CVE documents, the U-Boot FIT and boot-count documents, the Trusted Firmware-A trusted board boot guide, the RAUC, SWUpdate, Mender and MCUboot docs, the UAPI TPM PCR registry and the NXP HABv4 application note as quoted in U-Boot’s own guide. Full list in the Field Guide.
SIGN THE IMAGE OF
FLIP ONE BIT IN
KEY HASH BURNED IN THE FUSES
A model, not real silicon. The stage order follows an i.MX style chain (ROM, SPL, U-Boot, kernel FIT, dm-verity rootfs). Whether a closed unit can ever be rescued depends on the vendor’s recovery path; the lesson’s point is that you cannot count on one.
Chapter 0
See why one command on a bench board can end a product, and learn the rehearsal that keeps it from happening
It is late. You have a board on the bench, a signed boot image on the flash, and a checklist. The last line says: close the fuse. You type one command. You reset the board. The serial console stays blank. It stays blank after the next reset, and the one after that.
Nothing is broken in the usual sense. The chip is fine. The flash is fine. But the chip now refuses to run what is on the flash, and it will refuse for the rest of its life. This chapter explains why, and how to make sure it happens to a spare board and not to a shipped product.
When power arrives, a processor needs some code to run. That first code lives in the chip itself, written at the factory. We call it the boot ROM. ROM means read-only memory: you cannot change it, and neither can an attacker. Think of it as the one door lock that came with the building.
The ROM does a small job. It finds the next program on the flash or the SD card, loads it, and jumps to it. On an NXP i.MX chip that next program is the SPL (secondary program loader), a tiny first stage of U-Boot. Chapter 1 follows the whole chain. For now we care about one question: should the ROM run whatever it finds?
If the ROM runs anything, an attacker who can write the flash owns the device. So the ROM can check a signature first. But a check needs something to check against: a key the attacker cannot replace. Flash can be rewritten, so the key cannot live there.
The answer is a fuse, also called eFuse or OTP (one-time programmable) memory. A fuse is a tiny element inside the chip. You can burn it from 0 to 1 once. You can never burn it back. Think of a paper seal on a jar: broken once, broken forever.
The vendor tells you to burn two kinds of fuses. The first holds a hash of your public key. A hash is a short fingerprint of a larger thing. On i.MX with HABv4 (High Assurance Boot), the fingerprint is the hash of a table of public keys, called the SRK table. The second is the closed bit, the fuse that turns checking from advice into law. On i.MX 6, U-Boot's secure boot guide closes the device by programming the SEC_CONFIG[1] bit, with the command fuse prog 0 6 0x00000002.
Before the closed bit is burned, the device is in open mode. The ROM still runs its checks, but it only writes down what it found. These notes are called HAB events. Then it boots anyway. After the closed bit is burned, the device is in closed mode, and a failed check stops the boot.
Open mode exists so you can practice. You can sign an image, run it, ask the board what events it saw, and fix mistakes while mistakes are still free. In U-Boot the command for that is hab_status. The next device is a rehearsal of exactly this.
Pick what is on the flash and what hash is in the fuses. Press hab_status to read the board’s events. Only close the fuse when the events are clean. Try closing early to see what happens.
IMAGE ON THE FLASH
HASH BURNED IN THE FUSES
A model. The console lines are paraphrased, not the exact text of any release. The rule it follows is the one in NXP’s HAB guide: open mode logs events and boots anyway, closed mode stops. Whether a closed unit has any rescue path depends on the chip and on what you tested before closing.
There are two ways. In the first, the image is unsigned or damaged when you close the fuse. The ROM now refuses it. You may still have a way to push a correctly signed image into the chip over USB, but only if you tested that path first.
In the second, you burned the wrong hash. A typo in the fuse table is permanent. No key you hold matches it, so no image you can make will pass. That board is finished. Forum threads from NXP's own community describe both stories, including one user whose board no longer boots after closing with a bad image and who found no recovery.
There is a trap even in open mode. A forum post quoting an early revision of NXP's application note AN4581 reports that on i.MX 6 the ROM skips checking the key table while the device is open, even when the key-hash fuses are set. So a clean hab_status does not prove your hash is right. The newer revision of the note does not repeat the warning, so check your chip's current document. The safe habit does not depend on the answer: tamper with a test image and confirm the board reports an event.
On real hardware. Use an NXP i.MX evaluation board that you can afford to lose (the 8M and 6 families both have HAB or AHAB). Repeat steps 2 and 3 above and record the two hab_status outputs side by side. Do not close it. A board that stays open for life is a good lab board. The Arm Cortex-M boards named in this track (STM32 Nucleo, nRF52840 DK, RP2040, micro:bit v2) have their own readout-protection and key schemes, so treat this procedure as a pattern, not a recipe for them.
The claim this lesson proves is a trade. An A/B update with a bootloader confirm reaches no state where the unit cannot boot, while a single-slot rewrite has a power-loss window that bricks it. Secure boot is the same idea applied to trust. Here is the path, and what the hero at the top plays:
Chapter 1
Follow trust from a fuse inside the chip up to the last file on the disk, and find the one link that decides how strong the whole chain is
A delivery robot sits in a depot overnight. Someone with a flash programmer and ten minutes opens the case and swaps the kernel on the board for one of their own. The next morning the robot drives out, running code you never wrote.
You cannot lock every case. So you change the question. The board should not ask “is the case closed?” It should ask “did you make this code?” before it runs a single instruction of it. Secure boot is a board that asks that question at every step.
Booting is not one step. It is a relay. The ROM starts the SPL. The SPL starts U-Boot. U-Boot starts the kernel. The kernel mounts the root filesystem and starts your programs. Each runner hands the baton to the next.
If only the ROM checks the SPL, the attacker leaves the SPL alone and swaps something later. So every runner must check the next one before handing over the baton. We call the result a chain of trust: each stage is trusted because the stage before it checked it, and the first stage is trusted because nothing can change it.
That first anchor is the root of trust. It has two parts: the ROM (code nobody can rewrite) and the key-hash fuses (data nobody can rewrite). Everything else borrows trust from them.
A link has the same shape every time. The earlier stage holds either a public key (which can check a signature but cannot make one) or a hash of the next image. It reads the next image from flash, computes its hash, and checks the signature on that hash. If the check passes, it jumps. If not, it stops.
The idea is the same on every board, but the names differ. NXP calls its scheme HAB on older i.MX chips and AHAB on newer ones. NVIDIA and TI document their own versions under their own names (this lesson did not open those manuals, so read them before you rely on details). On boards using Trusted Firmware-A, the chain has a published shape that is worth knowing.
Trusted Firmware-A (TF-A) is the Arm reference firmware for 64-bit Arm boards. Its trusted board boot guide names the stages BL1, BL2, BL31 and BL33. Here is who checks whom, from that guide:
Each image comes with two certificates. A key certificate vouches for a public key. A content certificate stores the hash of one boot loader image. So trust walks down a ladder of keys, and each rung ends in the hash of one image.
Past BL33, U-Boot checks a signed kernel bundle (Chapter 2). The kernel then verifies the root filesystem block by block (Chapter 3). Count the links on a typical i.MX style chain: ROM to SPL, SPL to U-Boot, U-Boot to kernel, kernel to rootfs. That is four links and five stages.
Now pull one link out. Suppose U-Boot loads the kernel without checking it. The attacker does not need to break any cryptography. They put their own kernel on the flash. U-Boot runs it, and the kernel then mounts a root filesystem they also supplied. Two stages are now outside the chain, and the checks on earlier stages bought nothing.
The rule is simple and cruel: a chain is as strong as its weakest link, and everything after that link is untrusted. The device below lets you break each link and count what falls out of the chain.
Choose which stage skips checking the one after it. Then drag the two sliders to try an old signed image against the version counter in the fuses.
STAGE THAT DOES NOT CHECK THE NEXT
A model. The rollback rule shown is the usual one: the bootloader accepts an image only if its version number is at least the counter, and raises the counter after a good boot. The version numbers are illustrative.
Signatures have a blind spot. Version 3 of your firmware has a known bug. You fix it in version 4 and sign that too. But version 3 still carries a perfectly valid signature. An attacker with the flash programmer puts version 3 back, and every check says yes.
The fix is an anti-rollback counter: a number stored where it can only go up, such as fuses or a protected counter inside the chip. Each image says which version it is. The check becomes: the signature is good and the image version is at least the counter. When version 4 boots well, the bootloader raises the counter to 4, and version 3 is dead for good.
Try it in the device. With the counter at 4, offer version 3 and the verdict flips to refused. The price is the same as the fuse: the counter never goes down, so a bad release that raised it cannot be undone by going back. Raise the counter only after the new version has proved itself, and never before (Chapter 5 builds exactly that handshake).
On real hardware. On an evaluation board in open mode, build an image with a deliberately wrong signature for one stage. Record which stage reports the event, and write down who checks the stage after it. The measurement is the list of “who checks whom” for your own board, read from its security manual, not guessed.
Chapter 2
Sign the pair, not the pieces, so that a real kernel cannot be paired with the wrong device tree
U-Boot has just started, and it trusts itself because the SPL checked it. Its job now is to load Linux. But Linux is not one file. It is a kernel image, a device tree (a data file that tells the kernel which chips and pins this board has) and sometimes a small starting filesystem. Which of these should U-Boot check, and how?
A hash function turns any file into a fixed-size fingerprint. The one used here is SHA-256, and its fingerprint is 32 bytes, written as 64 hex digits. Two facts matter. The same file always gives the same fingerprint. And changing even one bit gives a completely different one.
You can check it yourself. SHA-256 of the three letters “abc” starts with ba7816bf. SHA-256 of an empty file starts with e3b0c442. Every hash shown on this page is a real SHA-256 computed in your browser.
A hash alone does not help, because an attacker can compute a new hash for their own file. So the build system signs the hash with a private key. Only the build system holds it. The board holds the matching public key. The public key can check a signature but cannot make one. If the check passes, the hash came from someone who holds the private key.
U-Boot calls the packed file a FIT image, for flattened image tree. One FIT file holds several images, each as a named node, and one or more configurations. A configuration says which kernel goes with which device tree. The build tool is mkimage.
U-Boot's documentation describes the safer way. The images get hashes. The signature goes on the configuration node, and it covers the configuration, the images it names and the root structure. The signature is stored at /configurations/conf-1/signature-1/value.
Why does this matter? Picture a kernel for version 7 and a device tree for version 6, both genuinely signed by you, each valid alone. If signatures sit on individual images, an attacker mixes them freely, and every check passes. When the signature covers the configuration, the pair is one signed fact. Swap one half and the hash no longer matches. (That reasoning follows from what the configuration signature covers; the documentation states the coverage, and the mix-up example is ours.)
The next device shows both layouts under three attacks.
Choose how the FIT is signed. Then press an attack. The hashes are real SHA-256. Read which attacks the board catches.
A model. The two images are short strings (“kernel image v7” and so on), and signing is shown as a stored hash; real FITs use sha256 with rsa2048 or ecdsa. The layouts and the required rule follow U-Boot’s signature document.
This is the shape of the source file. The load addresses are illustrative. The properties algo, key-name-hint and sign-images are the ones U-Boot’s page uses.
fitImage.its (device tree source, addresses illustrative)images { kernel-1 { data = /incbin/("Image"); type = "kernel"; arch = "arm64"; os = "linux"; load = <0x40200000>; entry = <0x40200000>; hash-1 { algo = "sha256"; }; }; fdt-1 { data = /incbin/("board.dtb"); type = "flat_dt"; hash-1 { algo = "sha256"; }; }; }; configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; signature-1 { algo = "sha256,rsa2048"; key-name-hint = "dev"; sign-images = "fdt", "kernel"; }; }; };
The build then runs mkimage with -K (write the public key into U-Boot’s own device tree), -k (the folder holding the private key) and -r (as the U-Boot example uses it). The public key lands under a /signature node of U-Boot’s control device tree. That tree is part of the U-Boot image, so the SPL has already checked it (Chapter 1).
At boot the check runs in four moves, as U-Boot's page describes them. U-Boot reads the FIT. It takes the public key from its own control device tree. It extracts the signature from the configuration. Then it hashes the image data and checks that the signature matches the hash. If any move fails, the configuration is not valid, and a required key makes that fatal.
Here is the trap in U-Boot’s page. A key node may carry a required property. If it does, the key must verify for the image or configuration to count as valid. If it does not, the page says only required keys are normally checked. A FIT with its signature removed can then boot with no complaint.
The value “conf” forces verification of the selected configuration, and “image” forces verification of all images. Switch off “Key marked required” in the device, strip the signature, and watch an unsigned FIT go through.
Failure mode, as symptom, measurement and fix. Symptom: a tampered kernel boots on a unit you thought was locked. Measurement: on a bench board, strip the signature from a test FIT and boot it. Fix: mark the key required with “conf” and repeat the test until U-Boot refuses.
On real hardware. Build the FIT above for any board that runs U-Boot, with a development key. Boot it, then flip one byte of fitImage with a hex editor and boot again. U-Boot should refuse. The measurement is the console line it prints; record it, then strip the signature and confirm refusal there too. Do this on the same bench board you used in Chapter 0.
Chapter 3
Check a gigabyte of root filesystem without reading it all, by trusting one small hash at the top of a tree
The kernel is signed and checked. Now it mounts the root filesystem, perhaps one gigabyte of programs, libraries and settings. An attacker with a flash programmer can change a single library there and leave the kernel alone. Who checks the gigabyte?
The simple answer is to hash the whole image at boot and compare. That reads every byte before the first program starts. On a slow flash that is seconds of delay at every power-on, to check files you may never open.
dm-verity is a Linux kernel feature (dm stands for device mapper) that checks a block only when something reads it. The idea: cut the disk into blocks, give every block its own hash, and store those hashes in a second area. When a program reads block 7, the kernel hashes block 7 and compares it with the stored hash. A mismatch means the block changed.
One problem remains. The stored hashes live on the same flash, so the attacker can change them too. The fix is to hash the hashes. Group the block hashes, hash each group, and repeat until one hash is left. This shape is a hash tree, also called a Merkle tree.
The kernel's dm-verity document says each node is a cryptographic hash. A leaf hashes a data block on disk, and an intermediate node hashes a group of child nodes that fit in one hash block. Take the usual sizes: data blocks of 4,096 bytes, and SHA-256 hashes of 32 bytes. Then:
The tree stores 2,048 + 16 + 1 = 2,065 hash blocks. That is 2,065 times 4,096 = 8,458,240 bytes, about 0.79% of the image. Three levels sit under the root hash. Reading one data block therefore costs three extra hash-block reads and four hash checks. The check is small and does not grow with the image.
The kernel document says the digest parameter is the hex hash of the root hash block (and the salt), and that “this hash should be trusted as there is no other authenticity beyond this point.” Everything rests on this one value. So it must arrive by a path the attacker cannot change: inside the signed FIT (Chapter 2), either on the signed kernel command line or in a signed initial filesystem that sets up verity.
The setup command takes the sizes and the root hash. The kernel document's table line reads: version, data device, hash device, data block size, hash block size, number of data blocks, hash start block, algorithm, digest, salt. With the user tool the same job is two commands, shown below. The root filesystem must also be read-only, because verity cannot allow writes: a write would change a block and break its hash.
A toy tree with 8 blocks, joined in pairs. Pick a block, corrupt it, then read it and read a different one. Then let the attacker rewrite the stored hashes too.
WHEN VERITY FINDS A BAD BLOCK
A toy: fan-out 2 instead of 128, and the strings “block i of the root filesystem” instead of 4 KiB blocks. Hashes are real SHA-256 (first 4 hex digits drawn), joined as text. The policy names and their meaning are from the kernel dm-verity document.
Look at what the device teaches. A corrupt block is only found when that block is read. Reading block 0 while block 3 is bad passes cleanly. And when the attacker also rewrites every stored hash to match their change, the leaf-level checks all pass, but the top check fails, because the root hash they cannot change no longer matches.
The kernel offers three reactions. ignore_corruption logs the bad block and lets the read go on. restart_on_corruption restarts the system, and the document says it needs user-space support to avoid restart loops. panic_on_corruption panics the device. They cannot be combined.
Failure mode, as symptom, measurement and fix. Symptom: a program crashes weeks after the update, though boot was fine. Measurement: the kernel log names the corrupt block when the read happens, not at boot. Fix: choose the policy on purpose. A robot that must keep its brakes alive may prefer a restart into the other slot (Chapter 5) over a panic, and must never loop forever on a restart.
shell# build the tree; prints the Root hash: the one value you must protect veritysetup format rootfs.img rootfs.hash # at boot (initramfs): map the verified device, then mount it read-only veritysetup open rootfs.img vroot rootfs.hash $ROOT_HASH mount -o ro /dev/mapper/vroot /sysroot
On real hardware. You do not need a special board. On any Linux machine, make a small image file, run veritysetup format on it, open it, then flip one byte of the image and read the file back. Record the kernel log line and how long the read took. On a board, repeat with the root filesystem on its flash and note what your chosen policy does to the boot.
Chapter 4
Record what ran, in a log nobody can rewrite, and release a disk key only to a device in the right state
A robot is stolen from a loading dock. The thief cannot beat the signed boot chain, so they pull the flash chip and read it on a bench. The map of your customer's building, the camera calibration and the network credentials are all there in plain text.
Signed boot guards what runs. It does not hide what is stored. For that the data needs encryption, and encryption needs a key. Where does the key live? If it sits on the same flash, the thief reads it along with the data. This chapter shows a way to keep the key where it opens only for a device that booted the right software.
Verified boot is what Chapters 1 to 3 built. It stops the boot when a check fails. Measured boot is different. It does not stop anything. Each stage writes down a hash of the next stage before running it. The record is kept in a small chip, and later someone, or something, reads the record and decides what to do.
The chip is a TPM (trusted platform module): a small separate security chip, or a firmware version of one. Inside it are registers called PCRs, platform configuration registers. A PCR holds one hash. You cannot write a PCR directly. You can only extend it.
As the Linux kernel mailing list describes it, an extend takes a digest and sets the new value to the hash of the old value joined to that digest: PCR_new = hash(PCR_old | digest). Think of a sealed notebook that you can only add lines to, where each new page includes a fingerprint of everything before it.
Two things follow. First, order matters: extending A then B gives a different value than B then A. Second, nothing can be taken back. An attacker cannot rewind a PCR to hide what ran. The only way to the final value is to run the same stages in the same order.
The UAPI group lists how Linux systems use the registers. PCR 4 covers the boot loader, PCR 7 the Secure Boot state, PCR 11 the parts of a unified kernel image, PCR 12 the kernel command line, and PCR 15 the root filesystem volume key. That list is written for UEFI PCs. The same idea carries to embedded boards, but which PCR holds what is your board's choice, so confirm it for your own build.
Each rung extends the PCR with the hash of one stage. The disk key opens only if the last value equals the value it was sealed to. Update the kernel and watch the key stay locked.
KERNEL
A model. The PCR starts at 32 zero bytes (the lesson’s simplification) and every extend is a real SHA-256 of the old value joined to the SHA-256 of the stage’s name. Real stages are binary images, and a real TPM also keeps an event log.
A TPM can seal a secret: it stores the secret encrypted so that it releases it only when chosen PCRs hold chosen values. At the factory you boot a known-good unit, read the final PCR, and seal the disk key to that value. At every later boot the early user space asks the TPM to unseal the key, and then unlocks the encrypted partition with it.
Now see what protects you. A thief who boots the stolen board on a modified kernel gets a different PCR. The TPM refuses to unseal. A thief who moves the flash chip to another board gets nothing, because the TPM, not the flash, held the way to open the key. The disk data is encrypted, and the root filesystem is also verified (Chapter 3), so the two work together: one hides, one detects change.
Run the device. With kernel v7, the key opens. Switch to v8 and the final value changes, so the key stays locked. That is correct for a thief. It is a disaster for your own update. Every legitimate kernel update changes the PCR, and a fleet that unlocks its disk with a sealed key can lock itself out.
Failure mode, as symptom, measurement and fix. Symptom: after an update the unit boots, but the data partition will not unlock. Measurement: compare the PCR values read before and after the update on one test unit. Fix: plan re-sealing as part of the update: the new slot is tested, the unit boots it, and only then the key is sealed to the new state, while the old key still works for rollback. Another route is sealing to a policy signed by your own key, so any release you sign is acceptable. The systemd project’s signed PCR policy is an example of that route.
A last point about command lines. Turn on “Debug shell on the command line” and the PCR changes. A device that was told to start a shell will not unseal. That is the point of including the kernel command line in the measurements.
On real hardware. If your board has a TPM 2.0 module (a small add-on on many Linux boards), read the PCRs with the standard TPM tools before and after a kernel change and record the two values for one register. If your board has no TPM, the lesson still holds: you can model the same flow with a software TPM on a laptop. The Arm Cortex-M boards in this track have no TPM; their protected key storage is a different mechanism.
Chapter 5
Update a unit so that cutting the power at any instant leaves it able to boot, by writing the new software only where it is not running
A warehouse robot is on 20% battery when its update starts. Halfway through writing the new software, the battery dies. A technician carries it to a charger and presses the button. If the update wrote over the only copy of the system, the robot now holds half of an old system and half of a new one. It will never boot again.
Multiply that by a fleet of ten thousand units in the field, with flaky power and flaky networks, and a few units will be caught every week. The update design must make this event harmless, not rare.
The simple design keeps one copy of the system. To update it, the device overwrites that copy. For a few seconds the copy is neither old nor new. If power fails in that window, no valid system remains. This is the power-loss window. A recovery partition can narrow the damage, but then the recovery system is the thing you must never break.
The A/B design keeps two complete copies of the system, called slots. One slot runs. The other sits idle. An update is always written to the idle slot. The running slot is never touched while it runs. If the write is cut short, the idle slot is junk, but nobody was using it.
Writing the idle slot is not enough. At some moment the device must start using the new slot. That change has to be one instant, never a slow process. We call it the atomic switch: one small variable in the bootloader's storage, written in one operation. Before the write, the bootloader picks the old slot. After the write, it picks the new one. No cut can land in the middle of a single variable write, as long as the bootloader keeps a safe copy of its environment (check your build; U-Boot can keep a redundant copy).
A new slot can be written perfectly and still be broken. Perhaps a driver fails on this board, or the application crashes at start. So the switch alone is not enough. The bootloader must also be able to take it back. Here is the handshake.
U-Boot has its own native version. Its documentation describes bootcount, which counts boots; bootlimit, the allowed count; and upgrade_available, which guards the whole mechanism so it triggers only after an upgrade. When bootcount exceeds bootlimit, U-Boot runs altbootcmd instead of the normal boot command. Application code resets bootcount and upgrade_available to 0 after a good boot. If altbootcmd is not defined, U-Boot stops at an interactive prompt, which on a field unit is as dead as a brick.
Choose the design and the step where power dies, then press Run the update. The row of dots shows the result if power died at that step: green is a unit that boots, red is a brick.
A model of the logic, not of a flash chip. The flow follows RAUC’s variables (BOOT_ORDER, tries left, 3 attempts) and U-Boot’s boot-count idea. It assumes the one-variable write is atomic and that the old software confirms itself. Turn confirm off to see a rollback.
This is the claim of the whole lesson, shown by counting. The single-slot update has 8 steps where power can die. Power dying during any of the four block writes leaves the only slot half old and half new: 4 of 8 positions end in a brick. The A/B update has 10 steps. Writes go to the idle slot, and the switch comes after the check. Every one of the 10 positions leaves a slot that boots: 0 of 10 bricked.
The reason is an invariant, a statement that is true at every instant. At every moment, the slot the bootloader would choose is a complete, verified system. The write to the idle slot cannot break it, because the idle slot is not chosen. The switch is one write, so it is either before or after. After it, the new slot is chosen only after it was verified. The invariant holds at every step, so no cut can reach a bad state.
Now turn off “New software confirms.” The bootloader boots the new slot, spends a try, and gets no confirm. It tries again. After three tries it gives up and boots the old slot. The unit works, but the update never sticks. We call this a rollback loop. The unit is alive and the fleet is stuck on the old version.
Failure mode, as symptom, measurement and fix. Symptom: units reboot three times after an update and then return to the old version. Measurement: on the unit, read the slot states with rauc status and the boot counters. A good new slot with no confirm shows tries used up. Fix: confirm from the application after a health check. RAUC's own guide says to wait for the system to be fully started before marking it good. Confirm too early and a broken update sticks forever.
The same idea exists on microcontrollers. MCUboot's design document describes a test upgrade that swaps in the new image but reverts at the next boot unless the swap is made permanent. A confirmed image is marked in a trailer byte (0x01 means confirmed, 0xff not). Different chip, same handshake.
On real hardware. Use an nRF52840 DK with Zephyr and MCUboot. Upload an image as a test image, reset the board without confirming it, and watch it revert to the old image. The measurement is which version number the application prints after each reset. Then repeat with the confirm call added. For Linux units, do the same with RAUC in a QEMU image and pull the virtual power during the write.
Chapter 6
Choose an update tool by what it checks before it writes a single byte, and by how little it downloads
Chapter 5 gave you the handshake. It said nothing about the file that arrives over the network. A phone, a router or a robot in a depot downloads a bundle of new software from a server. Between the server and the flash, anyone on the path can change it. A compromised build server can do the same before it is even sent.
A device that writes whatever it receives has handed the attacker a free pass around every check in Chapters 1 to 4. The signed boot chain still checks what boots, but if the update tool lets an attacker write a new SPL, then the attacker writes the very thing the chain trusts. So the update tool is part of the chain.
Three open tools do this job on Linux. They differ in details, but each cuts the problem the same way. The device is told which software to install, in a package it must treat as untrusted until proven otherwise.
This lesson opened the RAUC, SWUpdate and Mender documents for the points above. It did not read the signing sections of SWUpdate or Mender in detail, so check those before you choose either for a signed fleet.
Look at the steps an updater runs: fetch, check the signature, check each block, write to the idle slot, set the trial, reboot. The important rule is that nothing touches the flash until the signature has passed. If the check comes after the write, a bad bundle has already been written, and possibly switched in.
Streaming makes this harder. A streamed update writes as the data arrives, so it cannot wait for the whole file. It must check each block as it comes. That is the same trick as dm-verity (Chapter 3): the signed manifest carries a root of hashes, and each block is checked against it before it is written. RAUC supports streaming, and its documentation notes that its bundle download size limit has no effect when streaming is on.
Choose who signed the bundle, damage it, and decide whether the updater verifies before it writes. Then drag the slider to see how much a delta update saves.
BUNDLE SIGNED BY
A model. The 200 MiB image and the 12% default are illustrative. The index size is exact arithmetic for RAUC’s block-hash-index method, which stores one SHA-256 (32 bytes) per 4 KiB block: 200 MiB is 51,200 blocks, so 1,638,400 bytes, about 1.56 MiB.
A full image of 200 MiB over a cellular link is slow and costly, and most of it is the same as last time. A delta update sends only the blocks that differ. RAUC's documented method is the block-hash-index. It builds an index that stores the SHA-256 for each 4 KiB block of the image. The device compares the index with the blocks already in its slot and fetches only blocks that differ. Together with streaming, the docs say, this reduces the amount of downloaded data.
Work the arithmetic for an illustrative image. 200 MiB divided by 4 KiB is 51,200 blocks. One 32-byte hash each is 51,200 times 32 = 1,638,400 bytes, about 1.56 MiB of index. If 12% of blocks changed, the device fetches 0.12 times 200 = 24 MiB plus the index, about 25.6 MiB. That is roughly one eighth of the full image. If every block changed, the delta saves nothing and costs the index on top.
Mender's documentation notes only the cost of the other way: when delta updates are not in use, you transfer a full root filesystem image each time. For how fleets decide when to send which update, see fleet connectivity and telemetry.
The updater writes and switches. The application confirms. This split is deliberate: only the running software knows whether the sensors, motors and network are healthy. Chapter 5 showed the cost of getting it wrong in either direction. RAUC's guide suggests a service that calls rauc status mark-good and waits for the services you care about to start first.
Failure mode, as symptom, measurement and fix. Symptom: an unsigned or wrongly signed bundle installs. Measurement: in your test lab, build a bundle with a throwaway key and try to install it on a development unit. It must be refused before any write. Fix: keep that refusal as an automatic test in your release pipeline, so a future change cannot remove it quietly.
On real hardware. Run RAUC (or Mender or SWUpdate) in a QEMU image or on any Linux board with two root partitions. Install a bundle signed with a test key, then a bundle signed with a different key, and record the refusal message and whether the idle partition changed. Compare the partition hash before and after the refused install. The two hashes must be identical.
Chapter 7
Keep a kernel safe for years after you ship it, without drowning in a patch stack nobody can merge
Two years after launch, a security report names a flaw in the Linux network stack. Your product has 4,000 units in the field. Each runs a kernel that came from a chip vendor, with the vendor's changes added on top. Someone asks the plain question: are we affected, and how fast can we fix it?
Everything in this lesson so far makes that question answerable. The secure boot chain means only your fix can run. The A/B update means you can ship the fix without risking a brick. This chapter is about the remaining problem: producing a fix for a kernel that is not the one the world is patching.
A CVE is a public number for one known security flaw. The kernel documentation says the kernel team can assign CVEs, and that this happens after a fix is available and applied to a stable kernel tree. It also says that deciding whether a given CVE applies to your system is your job, not theirs.
Triage is a short list of questions, in this order:
A backport takes a fix from a newer kernel and applies it to an older one. It is tempting: one small patch, one small risk. But the kernel documentation gives the opposite advice. It says it is best to take all released kernel changes and to avoid cherry-picked changes. A fix may span several commits. Some changes with no CVE may still matter.
So the healthy habit is to track the stable branch of your long-term kernel and update to its newest point release, not to pick patches one by one. That works if your own changes sit cleanly on top. It breaks if they do not, and that is the next problem.
A vendor kernel is a base kernel plus a stack of patches: drivers for the chip, board support, fixes. Every patch in the stack is code you must carry. When the base moves from one long-term release to the next, each patch has to be forward-ported: adapted to the new code around it. Some apply cleanly. Some conflict, and a person must resolve each conflict.
Long-term kernels do not last as long as products. The table on kernel.org lists projected end-of-life dates: 6.1 and 6.6 in December 2027, 6.12 and 6.18 in December 2028. The Yocto Project's 6.0 “Wrynose” release is a long-term series supported until April 2030, and it ships Linux 6.18. A product sold for ten years outlives any of them.
Pick the kernel you ship on. Set the year you ship and how many years you support the product. The red stretch is the time with no upstream fixes for your kernel.
The release and projected end-of-life dates are from kernel.org (end of life shown as the end of the named month); Yocto 6.0 to April 2030 is from the Yocto Project announcement. The work estimate is illustrative: one forward-port hop every 2 years, and 1 patch in 10 conflicting at each hop.
Take the default setting. You ship in 2027 on 6.12 and support the product for 8 years, to 2035. The kernel's projected end-of-life is December 2028, so about 1.9 years after launch the upstream fixes stop. The remaining 6.1 years are yours. With one forward-port every two years, that is 4 hops. At 120 patches and 1 conflict in 10, that is 120 times 4 times 0.1 = 48 conflicts, resolved by hand.
Now cut the stack to 30 patches by sending the rest upstream. The same arithmetic gives 12 conflicts. This is why upstream first is a cost rule, not a courtesy. A patch that lives in mainline is carried for you by every future release at no cost to you.
The stable kernel rules set the standard that your own patches should meet. The fix must already exist in mainline. It must not be bigger than 100 lines with context. It must be obviously correct and tested. Hold your own carried patches to the same bar: small, one purpose, with a link to the upstream commit or a note on why it cannot go upstream.
Failure mode, as symptom, measurement and fix. Symptom: a security fix takes weeks because the update tangles with your changes. Measurement: count the patches in your tree and the conflicts in your last forward-port. Fix: upstream what you can, delete what the base now does, and refuse new patches that have no plan for leaving the stack.
Finally, remember that the fix has to travel. A kernel update is the riskiest thing you ship, because a bad one can stop the unit. It goes through the path you built: signed, verified before the write, written to the idle slot, tried, and confirmed (Chapters 5 and 6).
On real hardware. Pick any board you own that runs a vendor kernel. Run the version command to find the base release, list the patches on top of the matching upstream tag with the version-control log, and record the count. That count is your starting number for the cost estimate above.
Chapter 8
Keep the numbers, the checklist and the state machine in one place, and go back to the hero with them in your head
You can now say, from memory, how a unit decides to trust its software and how it replaces that software without risk. A fuse and a ROM anchor the chain. Each stage checks the next. U-Boot checks a signed configuration. dm-verity checks each block when it is read. A TPM can hold the disk key until the state is right. An A/B update writes only to the idle slot and switches with one variable. The application confirms. The tool checks the bundle before it writes.
| What | Number | Why it matters |
|---|---|---|
| SHA-256 of “abc” | starts ba7816bf; 32 bytes in all | One flipped bit gives a wholly different hash |
| Hashes per 4,096-byte hash block | 4,096 / 32 = 128 | Sets the width of a dm-verity tree |
| Verity tree for 1 GiB | 262,144 blocks; 2,048 + 16 + 1 = 2,065 hash blocks; 8,458,240 bytes, about 0.79% | Cheap to store, 3 extra reads per check |
| Update cut points | single slot: 4 of 8 brick; A/B with confirm: 0 of 10 | The claim of the lesson |
| RAUC default boot attempts | 3 (when boot-attempts is not set) | How long a bad slot gets before fallback |
| RAUC block-hash-index | one SHA-256 per 4 KiB block; 200 MiB image gives 1.56 MiB of index | What a delta update must fetch first |
| Stable kernel patch rule | at most 100 lines with context; already in mainline | The bar for your own carried patches |
| Long-term kernel end of life (projected) | 6.1 and 6.6: Dec 2027; 6.12 and 6.18: Dec 2028 | Products outlive kernels |
| Yocto 6.0 “Wrynose” | long-term support to April 2030; ships Linux 6.18 | A base release with a known end date |
This is the A/B decision from Chapter 5 as a small model. The second function is the proof: it cuts the update at every step and asks whether the unit still boots. It is a sketch of the state machine, not a bootloader.
pythondef choose(slots, order, left): """the bootloader: first slot in the order that has tries left and a valid image""" for s in order: if left[s] > 0 and slots[s].valid: left[s] -= 1 # spend a try BEFORE booting return s return None # nothing bootable: a brick def update(slots, order, left, cut): for step in ("write B", "verify B", "switch"): if step == cut: return # power dies here if step == "write B": slots["B"].valid = True # only the IDLE slot changes if step == "switch": order[:] = ["B", "A"]; left["B"] = 3 # ONE write # prove it: every cut point still leaves a bootable unit for cut in (None, "write B", "verify B", "switch"): slots, order, left = fresh(), ["A", "B"], {"A": 3, "B": 0} update(slots, order, left, cut) assert choose(slots, order, left) is not None
c/* the application's side of the handshake: call it only after the health check passes */ void confirm_boot(void) { if (sensors_ok() && motors_ok() && network_ok()) system("rauc status mark-good"); /* resets the tries; the new slot is now permanent */ }
This lesson is the trust-and-update step of the embedded Linux track. It builds on the boot chain and the image build, and it sits beside the firmware lessons on interrupts and safety. Keep going with the Linux boot chain, building the image, from vector table to main (the microcontroller version of the first boot), fleet connectivity and telemetry, fail-safe and functional safety, real-time Linux and embedded Linux.
Now press Present or Teach and explain the chain and the update from memory: why each stage checks the next, what dm-verity catches and when, why an A/B update cannot brick, and what the application must prove before it confirms. Then go back to the hero, close the fuse with an unsigned SPL, and say out loud why that board is finished.