AN-001 техническая заметка
Dual-bank bootloader: notes on a fail-safe update path
How an A/B image layout, a tiny boot-state record and a watchdog give you firmware updates that can't brick a device.
Перевода на русский пока нет — показан оригинал. (English)
A field update has exactly one job: never leave the device unbootable. The simplest design that reliably achieves that is two application slots and a bootloader that only trusts an image after it has proven itself.
Flash layout
0x0800_0000 ┌───────────────┐
│ Bootloader │ 32 KB, write-protected
0x0800_8000 ├───────────────┤
│ Boot state │ 2 sectors, wear-levelled
0x0801_0000 ├───────────────┤
│ Slot A │ 448 KB
0x0808_0000 ├───────────────┤
│ Slot B │ 448 KB
└───────────────┘
The trial-boot handshake
- The application downloads the new image into the inactive slot and verifies its signature.
- It writes
state = TRIAL, slot = B, attempts = 0and resets. - The bootloader increments
attempts, starts the watchdog and jumps to slot B. - The new firmware runs its self-test, then writes
state = CONFIRMED. - If the watchdog fires or
attempts > 3, the bootloader rolls back to slot A.
typedef struct {
uint32_t magic;
uint8_t active_slot;
uint8_t state; /* CONFIRMED, TRIAL */
uint8_t attempts;
uint8_t _rsvd;
uint32_t crc32;
} boot_state_t;
What I’d do differently
- Keep the boot-state record in two alternating sectors so a power cut mid-erase can’t lose it.
- Verify the image signature in the bootloader too, not just in the application.