Updates over the air
On this page
You do not throw away your old phone before the new one has made a call. If the new one fails, you go back to the old one. An update over the air (OTA) changes the firmware of a device through its own network link, and a careful device does the same: it keeps the old firmware until the new firmware has proven that it works.
See it
A pump controller at a remote site downloads new firmware into its second slot and restarts into it. The new firmware has a fault: it cannot connect to the network. What is the controller doing ten minutes later?
Press Next step four times. The arrow is the boot pointer: it names the slot that starts after a restart. The slot with the thick border is running. At every step, one slot holds firmware that is known to work.
The idea
Firmware is the program inside a device. An update over the air sends new firmware through the link the device already has: Wi-Fi, a mobile network or a radio.
The danger is the moment of change. A device that erased its only program, and then lost the download, would be dead until someone visited. So the memory holds two slots. The running firmware stays in one, and the new firmware is written into the other.
A small record, the boot pointer, names the slot to start. The bootloader, the first program to run after a restart, reads it. The pointer moves only after the whole new image has been checked.
The new firmware starts on trial. It runs a self-test, and it marks itself valid only when the test passes. If the test fails, or the firmware stops and a watchdog timer restarts the device, the bootloader goes back to the old slot. This is rollback.
Rollback protects against a faulty update, not against a false one: a device must also refuse firmware that does not carry your signature. The lesson on OTA updates and secure boot builds both.
One worked number
A device has 4 MB of flash memory, which is 4,096 KB. The first 64 KB hold the bootloader and some small records. The rest is divided equally among three copies of the firmware: one loaded at the factory, and the two slots for updates. How large can the firmware be? And with the two slots only?
Show the worked solution, 3 steps
- Find the space for firmware
4,096 KB − 64 KB = 4,032 KB.
- Divide by the three copies
4,032 KB ÷ 3 = 1,344 KB, about a third of the chip. This is the price of a safe update.
- Try two copies only
4,032 KB ÷ 2 = 2,016 KB. The firmware may be larger, but the device loses the factory copy, which no update can damage.
The mistake to avoid
Check yourself
An update is sent to 300 devices that have two slots and rollback. On 12 of them the new firmware fails its self-test. How many devices still work, and which version do they run?
The power fails when half of the new firmware has been written into the second slot. What does the device run when power returns?
New firmware starts and reads its sensor correctly, but a fault stops it from connecting to the network. Its self-test checks only the sensor. What happens?
Where you meet it
- A pump controller at a remote boreholeA wrong alarm limit is corrected on the same day, and nobody travels.
- Monitors in many buildingsA new version goes to a few devices first. If those go back to the old version, the others never receive it.
- A gateway at a solar plantIt records and reports during the download, because the old firmware runs until the restart.
- The new firmware is written into a second slot. The running firmware is not touched.
- The boot pointer moves only after the whole image has been checked.
- The new firmware starts on trial and must pass its own self-test, or the device goes back.
- The self-test must check the link that the next update needs.
Discussion
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
My notes on this page
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.