Updating firmware on a desk is easy. The same update on a charging station in a car park, or a sensor on a roof, is different: there is no cable, no engineer, and power can disappear halfway through. The question is not whether an update will fail one day, but what the device does next.
Do not overwrite what works
The basic idea is to keep two places for the application. The device runs from slot A and writes the new image into slot B. If the download stops, slot A has not been touched.
Espressif's ESP-IDF is a well documented example. Over-the-air updates need a partition table with at least two application slots, plus a small data partition that remembers which one to start. That data partition takes two flash sectors, so that losing power while it is being written does not leave the device without an answer.
Put the new version on trial
Copying an image correctly does not make it a good image. With rollback enabled, a new application starts in a pending state and gets one attempt. It has to run its own checks and confirm that it is healthy. If it resets before doing so, the bootloader goes back to the previous version.
What should the self-test look at? Only what the next update depends on:
Can the device reach the network and the update server?
Do the critical peripherals answer?
Can it read its configuration, including after a format change?
A self-test that checks everything will reject good versions. One that checks nothing will accept a version that can never be updated again.
Close the door behind a security fix
Rollback has a risk: someone could push an old version with a known weakness. Anti-rollback solves this with a security version stored in the chip. An image with a lower number is refused. Raise the number only for security fixes, because the step cannot be undone.
Before you ship: five questions
What happens if power is cut at any moment of the update?
Who confirms that the new version is healthy, and after how long?
Is the image verified before it is started, and not only after the download?
Can you stop a rollout after the first few devices?
Can a device that stayed offline for a year still update?
If one of them has no answer, it is better to find out on the desk.
Further reading
ESP-IDF programming guide: Over The Air Updates (OTA)
Our firmware development service



