Phase 4 of 4 · Study weeks 13-16
Ship it: bootloader, update and operations
This phase makes the product updatable in the field without a service visit, and lets you prove it with power cuts.
Topics every week
- Week 138 h
- Flash internals: banks, 2 KB pages, doubleword programming, ECC, option bytes, read-while-write
- a flash driver
- two-slot linker layout
Hand inA flash driver with tests, and a memory-map diagram with the two slot addresses
- Week 148 h
- Bootloader and image format: header (magic, version, length, CRC-32, board id), slot choice, jumping to an app (stack pointer,
VTOR, peripheral reset), append-only metadata log, trial boot and confirm
Hand inA bootloader that picks slot A or B, with both images built by CMake at their own addresses
- Bootloader and image format: header (magic, version, length, CRC-32, board id), slot choice, jumping to an app (stack pointer,
- Week 158 h
- Update protocol over serial: chunks, acknowledgements, restart from the last good chunk
- writing the idle slot while the loop runs
- the power-cut harness (relay, GPIO markers, analyzer)
Hand inA host update tool and the board-triggered cut harness, with the first five cuts logged
- Week 168 h
- Checkpoint 4: the 20 cuts, the soak, rollback, reproducible build
- ADRs
- the update-strategy memo (own bootloader against MCUboot against ST's secure-update packages)
Hand inCheckpoint 4 and the memo
Practice projects
- Flash fault lab: program an already-written doubleword, cut power during a page program, and read the damaged word back. Done when you have recorded what the controller flags and what the data does in each case, and the boot scan survives it.
- Boot-time budget: measure power-up to first loop sample. Done when the number is reported and you name the largest contributor.
- Rollback drill: ship an image that boots and then hangs. Done when three boots later the previous version runs and the log says why.
GitHub repos to study
| Repo | What to read | Week |
|---|---|---|
| mcu-tools/mcuboot | docs/design.md: slots, image header, swap and its power-fail handling (v2.5.0) | 14 to 16 |
| STMicroelectronics/STM32CubeG4 | Examples/FLASH/FLASH_DualBoot and FLASH_EraseProgram | 13, 14 |
| zephyrproject-rtos/zephyr | boards/st/nucleo_g474re and the MCUboot integration docs | 16 |
| memfault/interrupt | _posts: the bootloader-from-scratch and MCUboot overview posts | 14, 16 |
Milestone checkpoint
Done when the Checkpoint 4 row passes. Evidence: the 20-row cut table with phase markers, soak report, rollback log, the byte-identical build check, the boot state diagram, ADR-5 (own two-slot bootloader with one image per bank and a log page per bank; rejecting a software bank swap with FB_MODE or BFB2 for the core path because the threads you can find report inconsistent behaviour and it makes the running address depend on the bank, rejecting a plain copy of the new image over the old one because a cut mid-copy destroys the only good image, and rejecting MCUboot for the core path because its integration is a second project; the memo weighs them again), and for Senior and above ADR-6 (signing, key handling, readout protection, and the bootloader size a signature library needs) and ADR-7 (FreeRTOS against Zephyr).
Check yourself
Answer each question in your head first, then open it to check.
Why does the update write the idle slot and never the running one?
A cut then leaves the running slot intact. Whatever happens to the idle slot, the old image still boots.What states does a trial boot have, and which transitions need a flash write?
New, trial and confirmed, plus failed. Each change appends a record, so no word is ever rewritten.Why is an append-only log safer than rewriting one status word?
Flash words are write-once between erases, and a cut mid-rewrite leaves a value that is neither old nor new. A new record either exists completely or is ignored by its CRC.What does a CRC not protect against that a signature does?
A deliberate change: anyone can recompute a CRC. A signature needs the private key.A unit boots, passes the CRC and then hangs. What recovers it, and what does the bootloader record?
After three boot attempts without a confirm, the bootloader marks the slot failed, boots the other slot and records the reason.