How to Build Secure OTA Firmware Updates That Never Brick Your Devices

How to Build Secure OTA Firmware Updates That Never Brick Your Devices

Shipping devices without a way to update them is risky. Shipping them with an update system that can fail is worse. A single bad release can leave a batch of devices stuck at boot, and the fix then involves customers mailing hardware back. OTA firmware updates, or firmware over the air as some teams call it, are one of the features that look simple in a demo and turn out to be the hardest thing to get right in a real product. A secure OTA design has to survive dead batteries, dropped connections, bad images and attackers. Here's how we build update systems that don't leave anyone with a bricked device.

1. Get the Bootloader and Flash Layout Right From Day One

Decide on the Bootloader Before You Ship Anything

The bootloader is the one piece of code you usually can't safely change in the field, so it has to be right in the very first build that leaves the factory. On Nordic and many other Cortex-M parts, we use MCUboot. On the ESP32, the ESP-IDF bootloader handles the same job. Whatever you use, turn on the features you'll need later now, especially rollback. Espressif's own documentation warns that app rollback has to be enabled in the first firmware shipped, because it can't be added afterwards by an update.

Use an A/B Partition Scheme

Never overwrite the only working copy of your firmware. An A/B partition layout, sometimes called dual-bank flash, keeps the running image in one slot and writes the new image into the other. The device only switches after the new image is complete and verified. If anything goes wrong halfway through, the old slot is still there. MCUboot supports this with swap mode, where images are exchanged and can be swapped back, and with simpler direct-execute modes. Yes, it costs flash. It's the cheapest insurance you'll ever buy.

Plan the Partition Table Carefully

Your partition table or flash layout defines where the bootloader, the application slots, settings and file storage live. Change it carelessly between versions and you can strand devices, a problem we've seen discussed in plenty of forum threads where an update image didn't match the old partition map. Leave headroom in each slot for future growth, since firmware always gets bigger, and treat the layout as a fixed contract once devices ship. If it must change, design a migration step and test it on real hardware first.

2. Make Every Update Trustworthy

Sign Every Image

Signed firmware is the foundation of IoT security for updates. With image signing, the build server signs each release with a private key, and the bootloader checks the signature with a public key stored in protected flash before it'll run anything. MCUboot supports ECDSA, RSA and Ed25519 signatures. Without signing, anyone who can reach your update channel can install their own code on your devices. With it, the device simply refuses anything you didn't sign.

Turn On Secure Boot and Anti-Rollback

Signing protects the update path. Secure boot extends that protection to every boot, so tampered code in flash gets rejected too. Pair it with rollback protection, also called anti-rollback, which uses a security counter so an attacker can't install an older, vulnerable version that's still correctly signed. Be careful how you use it, though. Once the counter goes up, older images are refused, so only bump it for real security fixes, not every routine release.

Protect Your Signing Keys

The private signing key is the most valuable secret in your whole product. If it leaks, every device you've shipped can be taken over, and if it's lost, you can never update them again. Good key management means keeping keys off developer laptops, ideally in an HSM or a locked-down signing service, with backups stored securely in more than one place. Use separate development and production keys, and make sure production devices only accept the production key.

3. Design for Failure, Because Failures Will Happen

Survive Power Loss During an Update

Batteries die and users pull plugs. A power loss during update must never leave the device unbootable. With an A/B layout and a bootloader that tracks swap progress, the device can always resume or fall back after the power returns. We test this deliberately by cutting power at random points during hundreds of update cycles, using a programmable supply or a relay. If you haven't tested it, assume it doesn't work. The dangerous cases are rare ones, such as a power cut during the final write of the swap status. A fault that appears once in four hundred updates sounds harmless until you multiply it across a fleet of fifty thousand devices. Usually only automated testing finds it.

Confirm New Images Before Making Them Permanent

A new image can pass the signature check and still be broken. Maybe it crashes after ten seconds, or it can't reach the network. Image confirmation solves this. The new firmware boots in a trial state, runs its self-tests, connects to the server, and only then marks itself as good. If it never confirms, the bootloader rolls back to the previous image on the next reset. Make the confirmation depend on things that prove the update channel still works, otherwise you'll confirm an image that can't receive the next fix.

Keep a Recovery Mode

Even with every safeguard in place, keep a last line of defence. A recovery mode might be a minimal image that can still receive an update, a button combination that starts serial or BLE DFU, or a factory image stored in protected flash. It might never be used. But when it's needed, it's the difference between a remote fix and a warehouse full of returned devices.

4. Roll Out Updates Like a Professional

Choose the Right Transport

How the update reaches the device shapes the whole design. Wi-Fi and cellular products usually download images from an update server over HTTPS. BLE products receive them from a phone app, using tools like Zephyr MCUmgr and nRF Connect SDK DFU on Nordic devices, or a custom service elsewhere. ESP32 OTA support is built into ESP-IDF for both. For slow or costly links, delta updates that send only the changes can shrink a transfer a lot, at the price of a more complex toolchain.

Use Staged Rollouts

Never push a new version to every device at once. A staged rollout sends it to a small group first, perhaps one percent of the fleet or your own test units, then widens it while you watch crash reports and connection rates. Good fleet management tools let you pause or stop a rollout the moment something looks wrong. Teams that skip this step tend to learn about bugs from their support inbox, all at the same time.

Version Everything and Test the Update Path Itself

Clear firmware versioning, using semantic version numbers that are embedded in the image and reported by every device, tells you exactly what's running in the field. Then test the update path, not just the new firmware. OTA testing should include updating from every version still in use, interrupting downloads, sending corrupted and wrongly signed images, and filling the flash. The update mechanism is code too, and it needs its own test plan.

How to Build Secure OTA Firmware Updates That Never Brick Your Devices

FAQ: Frequently Asked Questions

Q: What's the most common cause of devices bricked by OTA updates?

A: Single-slot designs that overwrite the running firmware, and updates that boot fine but break the connection needed to receive the next update. A/B slots plus image confirmation prevent both.

Q: Is MCUboot only for Zephyr?

A: No. MCUboot is an independent open-source bootloader used with Zephyr, Mynewt, bare-metal projects and others. It's simply best integrated in Zephyr and the nRF Connect SDK.

Q: Do we need secure boot for a consumer IoT product?

A: We strongly recommend signed updates at minimum. Security rules for connected products are tightening, including the EU Cyber Resilience Act, so building signing and secure boot in from the start is the safer path.

Q: Can OTA be added to devices that are already deployed?

A: Only if they already have a bootloader that can accept updates. If not, a hardware recall or local reflashing is usually the only route, which is why OTA must be planned before the first shipment.

Q: How much extra flash does an A/B update scheme need?

A: Roughly double the application size, plus a little space for the bootloader and swap status. If flash is tight, MCUboot can store the second image in external SPI flash instead.

Conclusion

Reliable over-the-air updates come down to a few decisions made early: the right bootloader, two image slots, signed images, confirmation with rollback, and careful rollouts. Get those right and updates become routine instead of nerve-racking. VelocityCreate's embedded firmware engineering team designs and tests OTA systems on Nordic, ESP32 and STM32 platforms, and we're happy to review yours before it reaches the field. Explore our Embedded Firmware Engineering work, read more technical notes, or book a technical call to talk it through with an engineer.

Leave a comment