Over-the-Air Firmware Updates: Designing Them In From Day One
Connected products ship with bugs and face vulnerabilities discovered after launch. Over-the-air update is how both are dealt with, and it is one of the few features that cannot be added later, because it determines how flash memory is divided and how the device boots. A failed update must never leave a device unusable. This article covers the architecture that makes updates safe.
At a glance
- 2 slots
- An A/B layout keeps the running firmware intact while the new image is written to the other slot.
- 2x
- A dual-slot design needs flash for two full images plus the bootloader.
- SHA-256
- A cryptographic hash verifies that the image arrived complete and unaltered.
- Signature
- A digital signature proves the image came from you. A hash alone does not.
The problem
The naive approach overwrites the running firmware in place. If power fails or the download is corrupted part-way through, the device is left with half an image and no way to recover without physical access.
Updates are also an attack surface. A device that accepts any image it is offered can be taken over by anyone who can reach it, so the device must verify who produced the image before running it.
An update is safe only if the device can always boot something. Design for the failure, not the success.
Sizing the flash
With two slots, the application can be at most roughly half of the flash left after the bootloader and any data storage. On a 1 MB device with a 32 KB bootloader and 64 KB of storage, each slot is about 464 KB. Check that your firmware fits, with room to grow, before the part is chosen.
Where flash is too small for two slots, alternatives include an external flash chip to stage the image, or compressed and differential updates. Each adds complexity that should be weighed against a larger part.
What good looks like
Fix the memory map: bootloader, two application slots, and persistent data that must survive an update.
Implement verification in the bootloader: check the signature and hash before marking a new image as bootable.
Add rollback: the new image must confirm that it started correctly, or the bootloader returns to the previous one.
| Region | Size | Purpose |
|---|---|---|
| Bootloader | 32 KB | Verifies and selects the image to run |
| Slot A | 464 KB | Currently running application |
| Slot B | 464 KB | Receives the new image |
| Persistent data | 64 KB | Settings and state that survive updates |
| Total | 1,024 KB |
A safe update, step by step
- Download: Write the image to the spare slot
- Verify: Check hash and signature
- Swap: Mark the new slot for boot
- Confirm: New image reports it is healthy
- Or roll back: Bootloader restores the old image
What it changes
Recoverability
An interrupted or bad update leaves the device running its previous firmware.
Security
Only images signed with your key will run, whatever the transport.
Fleet Control
Fixes and features reach devices in the field without a service visit.
Longevity
Security updates can continue for the supported life of the product.
Where to go next
Protect the signing key. If it is lost you cannot update your devices; if it is stolen, someone else can.
Roll updates out in stages and monitor the results, so a faulty release reaches a few devices rather than all of them.
Problems this prevents
- Devices bricked by an interrupted update
- Firmware accepted without verifying its source
- Flash too small for a second image
- No way back from a bad release
Discuss your project
Email support@aavico.com or use Get in Touch when the website finishes loading.