IoT and Edge AI

Over-the-Air (OTA) Firmware Updates for IoT Devices

How OTA firmware updates work on IoT devices: A/B flash layouts, signing and secure boot, rollback, delta updates, ESP32 and MCUboot examples, and fleet rollout.

On this page
  1. What an OTA firmware update is
  2. Why OTA matters for IoT products
  3. The parts of an OTA system
  4. Flash layouts: A/B, single-slot and recovery
  5. Securing the update pipeline
  6. Rollback and health checks
  7. Delta updates and constrained networks
  8. Example: OTA on the ESP32 with ESP-IDF
  9. Example: MCUboot on Zephyr and other RTOSes
  10. OTA for embedded Linux devices
  11. Rolling out updates to a fleet
  12. Common failure modes and how to avoid them
  13. Pre-launch OTA checklist
  14. FAQ

What an OTA firmware update is

An over-the-air (OTA) firmware update replaces the software running on a deployed device through its network connection, with no cable or programmer and no one on site. You’ll also see it called FOTA (firmware over the air). For embedded Linux devices people often say SOTA (software over the air), since they may update a whole operating system image or individual packages.

On a microcontroller, an OTA update usually means:

  1. The device learns that a new firmware version is available.
  2. It downloads the new image and writes it to a spare area of flash.
  3. It checks that the image is complete and authentic.
  4. It reboots, and the bootloader starts the new image.
  5. The new firmware checks that it works and marks itself as good. Otherwise the device falls back to the previous version.

Each step sounds simple. Most of the engineering effort goes into making every step survive power loss, flaky networks, bad builds and attackers.

Why OTA matters for IoT products

  • Security patches. Connected devices are exposed to the internet for years. Vulnerabilities will be found in your code, your network stack or your TLS library, and you need a way to fix them.
  • Bug fixes. Field conditions turn up bugs that never appeared on the bench.
  • New features and models. Products can improve after launch. Devices running on-device machine learning can receive retrained models (see getting started with TensorFlow Lite for Microcontrollers).
  • Cost. Recalling devices or sending a technician to each one quickly becomes far more expensive than building OTA in from the start.
  • Regulation. Regulators increasingly expect manufacturers to support security updates. The EU Cyber Resilience Act, for example, includes obligations around handling vulnerabilities and providing security updates for products with digital elements. Check the current requirements for your markets.

OTA is also one of the riskiest features in a device. A broken update mechanism can disable a whole fleet at once, and a poorly secured one lets an attacker install their own firmware. Treat it as a core part of the design, not something to add just before launch.

The parts of an OTA system

A complete OTA system has pieces in the cloud and on the device. The IoT system architecture article covers where device management sits in the overall stack. These are the OTA-specific parts:

Build and signing

Your CI pipeline builds a release image, gives it a version number and signs it with a private key that never leaves a secure environment (ideally a hardware security module or a cloud key-management service). The output is the firmware binary plus metadata: version, target hardware, size, hash and signature.

Update server and fleet management

A server stores the images and decides which devices should get which version. It might be a simple HTTPS file host, a commercial device-management platform, or a cloud service such as AWS IoT Jobs or Azure Device Update. Useful features include device groups, staged rollouts, update status reporting and the ability to pause a rollout.

Transport to the device

Common options:

  • HTTPS download over Wi-Fi, Ethernet or cellular. This is the simplest choice and works well with CDNs.
  • MQTT to notify the device and report progress, often paired with an HTTPS download for the image itself (see how to use MQTT on the ESP32).
  • CoAP block-wise transfer on constrained IP networks.
  • Bluetooth LE, with a phone or gateway relaying the image.
  • LPWAN multicast and fragmentation, such as LoRaWAN FUOTA.

The link you chose for your product strongly affects what kind of OTA is practical. A 1 MB image is trivial over Wi-Fi but a serious undertaking over LoRa. The Wi-Fi vs Bluetooth LE vs LoRa vs Zigbee comparison covers those trade-offs.

The on-device update agent

This is code in your application that checks for updates, downloads the image in chunks, writes it to flash, verifies it and requests a reboot. It also reports status back to the server. It should resume interrupted downloads where possible and never overwrite the running image.

The bootloader

The bootloader is the small, rarely changed program that runs first after reset. In an OTA design it:

  • Decides which image to boot
  • Verifies the image’s signature before running it (secure boot)
  • Swaps or copies images if the layout requires it
  • Reverts to the previous image if the new one fails to confirm itself

Since the bootloader is your safety net, many teams never update it in the field, or do so only with extra safeguards.

Flash layouts: A/B, single-slot and recovery

Where the new image goes is one of the first design decisions, and it depends heavily on how much flash you have.

Layout How it works Pros Cons
Dual-bank / A/B Two application slots. The new image is written to the inactive slot, then the bootloader switches. Running image never touched; fast fallback; robust to power loss Needs roughly twice the application flash
Swap with scratch or move (e.g. MCUboot) New image is downloaded to a secondary slot, and the bootloader swaps it into the primary slot Can revert by swapping back; works when code must run from a fixed address Swap takes time and causes extra flash wear; still needs a second slot
Overwrite / single active slot Bootloader copies the new image over the old one Simpler; no swap logic No easy rollback once the copy finishes
External flash staging New image downloaded to external SPI flash, then copied into internal flash Saves internal flash Copy step must be power-safe; external flash should be protected or the image re-verified
Recovery image A minimal “recovery” firmware can always download a full image Small footprint for the main app Recovery firmware must be very reliable and kept up to date itself

If you can afford the flash, A/B with automatic rollback is the most forgiving design. Many modern Wi-Fi and BLE microcontrollers ship with enough flash to make it practical, and several chips support dual-bank operation in hardware.

Securing the update pipeline

An OTA mechanism is, by design, a way to run new code on your device. If an attacker can use it, they own the device. The cyber-physical security overview explains why this matters even more when devices control physical equipment.

Sign every image

Sign release images with an asymmetric key (ECDSA and Ed25519 are common choices, and RSA is also widely supported). The device holds only the public key, so extracting it from one device doesn’t let anyone sign firmware. Protect the private key carefully, and have a plan for rotating it if it is ever exposed.

TLS on the download protects the transfer. A signature protects the image itself, even if the server, CDN or a relay phone is compromised. You generally want both.

Verify in the bootloader (secure boot)

Checking the signature in the update agent is useful, but the real guarantee comes from the bootloader verifying the image on every boot, anchored in something an attacker can’t change: a key hash in one-time-programmable fuses, a ROM bootloader, or a secure element. Many microcontroller families offer a hardware secure boot feature for this. Enabling it usually involves irreversible fuse programming, so test the process on development boards first.

Encrypt if the firmware is sensitive

Signing proves authenticity, but it doesn’t hide your code. If the firmware contains valuable IP, or you want to make reverse engineering harder, encrypt images in transit and consider flash encryption at rest. Flash encryption also makes it harder to pull secrets such as device credentials off a stolen device.

Prevent rollback to vulnerable versions

If an attacker can install an older, correctly signed firmware with a known vulnerability, signing alone doesn’t help. Anti-rollback protection stores a minimum allowed security version (often in fuses or protected storage) and rejects anything older. Keep this “security version” separate from your normal version number, so you only raise it when a real vulnerability fix needs to stick.

Rollback and health checks

Even a correctly signed image can be broken: a bad configuration, a driver that hangs on one hardware revision, a network stack that can’t reconnect. Good OTA designs use a test-then-confirm pattern:

  1. After installing a new image, the bootloader boots it in a “pending” or “test” state.
  2. The new firmware runs a self-test: peripherals start, the main loop runs, and, most importantly, the device can still reach the update server.
  3. If the self-test passes, the firmware marks itself as confirmed.
  4. If the device resets before confirming (a crash, a watchdog reset, a power cut), the bootloader reverts to the previous image.

The connectivity check matters most. A device that boots fine but can no longer connect can’t receive the fix, so in practice it is bricked. Pair this with a hardware watchdog so a hang also triggers a reset and rollback.

Delta updates and constrained networks

Delta (differential) updates

A delta update sends only the differences between the old and new image. The device reconstructs the new image from its current firmware plus the patch. On cellular or LPWAN links, where data costs money or airtime is limited, this can shrink downloads dramatically, especially for small fixes.

Trade-offs:

  • The server must know exactly which version each device is running, and generate a patch for each version it needs to support.
  • The device needs RAM and flash working space to apply the patch, plus the code to do so.
  • The reconstructed image must still be verified against the signed full-image hash before it boots.

Several RTOS vendors, device-management platforms and open-source tools support delta updates for microcontrollers. Embedded Linux updaters often support them too. Measure the savings on your real release history before committing, because heavy compiler optimizations and link-order changes can make deltas larger than you’d expect.

Bluetooth LE DFU

BLE devices usually update through a phone app or a gateway that relays the image. Chip vendors provide device firmware update (DFU) protocols and mobile libraries, and Zephyr-based devices commonly use the MCUmgr/SMP protocol. Throughput is modest, so updates of a few hundred kilobytes can take noticeable time. The app should handle the user walking away mid-transfer.

LoRaWAN’s small payloads and duty-cycle limits make full-image unicast updates impractical for large fleets. The LoRa Alliance defines a FUOTA approach built on separate specifications for clock synchronization, remote multicast setup and fragmented data block transport, with forward error correction so devices can rebuild the image even if some fragments are lost. Even so, LPWAN updates take a long time and should be kept small. Delta updates and careful firmware size budgeting help a lot here. NB-IoT and LTE-M devices can usually download over IP, but data costs and power consumption still favor small images.

Example: OTA on the ESP32 with ESP-IDF

Espressif’s ESP-IDF has OTA support built in, and it’s a good platform for learning the pattern.

1. Use a partition table with two OTA slots. In menuconfig, choose a partition table option that includes two OTA app partitions (such as “Factory app, two OTA definitions”), or define your own CSV with ota_0, ota_1 and an otadata partition. The otadata partition records which slot to boot.

2. Download and install the update over HTTPS. The esp_https_ota component handles the download, writes the inactive slot and validates the image:

#include "esp_https_ota.h"
#include "esp_log.h"
#include "esp_system.h"

extern const char server_cert_pem_start[] asm("_binary_ca_cert_pem_start");

static const char *TAG = "ota";

void run_ota(const char *url)
{
    esp_http_client_config_t http_cfg = {
        .url = url,
        .cert_pem = server_cert_pem_start,   // verify the update server
        .timeout_ms = 10000,
    };
    esp_https_ota_config_t ota_cfg = {
        .http_config = &http_cfg,
    };

    ESP_LOGI(TAG, "Starting OTA from %s", url);
    esp_err_t err = esp_https_ota(&ota_cfg);
    if (err == ESP_OK) {
        ESP_LOGI(TAG, "OTA succeeded, restarting");
        esp_restart();
    } else {
        ESP_LOGE(TAG, "OTA failed: %s", esp_err_to_name(err));
    }
}

This matches the ESP-IDF v5 API. In v4.x, esp_https_ota() took the HTTP client config directly, so check the OTA examples (examples/system/ota) that ship with your installed version.

3. Enable rollback and confirm the new image. Turn on the bootloader’s app rollback option (CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE). A freshly installed image then boots in a pending-verify state, and your firmware must confirm it:

#include "esp_ota_ops.h"

void confirm_or_rollback(void)
{
    const esp_partition_t *running = esp_ota_get_running_partition();
    esp_ota_img_states_t state;

    if (esp_ota_get_state_partition(running, &state) == ESP_OK &&
        state == ESP_OTA_IMG_PENDING_VERIFY) {
        if (self_test_passed()) {          // your checks: Wi-Fi, server reachable, sensors OK
            esp_ota_mark_app_valid_cancel_rollback();
        } else {
            esp_ota_mark_app_invalid_rollback_and_reboot();
        }
    }
}

If the device reboots before confirming, the bootloader boots the previous slot instead.

4. Add signing and secure boot for production. ESP-IDF supports signed app images, hardware secure boot and flash encryption on supported chips. These involve one-time fuse settings, so follow Espressif’s documentation for your exact chip and test on spare boards first.

For quick experiments in the Arduino framework, the ArduinoOTA library offers push updates over the local network, and the HTTPUpdate library can pull an image from a URL. Both are handy during development. For deployed products, add authentication, image signing and rollback.

Example: MCUboot on Zephyr and other RTOSes

MCUboot is a widely used open-source secure bootloader for 32-bit microcontrollers. It’s the default bootloader choice in Zephyr and is also used with other RTOSes and bare-metal projects. In outline:

  • Flash is divided into the MCUboot partition, a primary slot and a secondary slot (plus scratch space in some modes).
  • Application images are signed with MCUboot’s imgtool (Zephyr’s build system can do this automatically). MCUboot checks the signature before booting.
  • The update agent writes a new image to the secondary slot and marks it for a test boot.
  • On reset, MCUboot swaps the images and boots the new one. If the application doesn’t confirm the image before the next reset, MCUboot swaps back.
  • MCUboot supports several upgrade strategies (swap-based, overwrite-only, direct execute-in-place and others), so you can match your flash layout and rollback needs.

In Zephyr, the MCUmgr subsystem provides an image-management protocol over serial, BLE and UDP. That makes it straightforward to push images during development and to build field update tools.

OTA for embedded Linux devices

Gateways and other Linux-based devices update differently, but the same principles apply. Established open-source tools include Mender, SWUpdate, RAUC and OSTree-based systems. Most support A/B root filesystems, signed update bundles and automatic rollback when the new system fails to boot. Updating individual packages with a normal package manager is simpler, but it’s harder to make atomic and reproducible across a fleet, so many products prefer whole-image updates.

Rolling out updates to a fleet

How you release matters as much as how the device installs:

  • Test on real hardware first, including every hardware revision still in the field, and test the update path from each version you still support, not just the previous one.
  • Use staged rollouts. Release to internal devices, then a small percentage of the fleet, then progressively more, watching crash rates, reconnection rates and rollbacks at each stage.
  • Be able to pause or stop a rollout instantly.
  • Report status. Devices should report download, install, confirm and rollback events, so you can see problems before customers do.
  • Respect the device’s situation. Avoid installing while a battery is low, during active operation, or at times users depend on the device. Let the application defer updates when it’s busy.
  • Spread the load. Thousands of devices downloading at the same moment can overload your server or cellular data plan. Add randomized delays.

Common failure modes and how to avoid them

Failure What happens Mitigation
Power loss during download Partial image in the inactive slot Never touch the running image; verify the hash before switching
Power loss during swap or copy Device left with no valid image Use a bootloader with power-fail-safe swap, or A/B with no copy step
Image boots but crashes Device stuck in a reset loop Test-then-confirm plus watchdog-triggered rollback
Image boots but can’t connect Device can’t receive the next fix Include connectivity in the self-test before confirming
Wrong image for the hardware Peripherals misbehave or device won’t start Put hardware ID and compatibility in signed metadata, and check before installing
Old signed image installed Known vulnerability returns Anti-rollback security counter
Signing key leaked Attackers can sign firmware Keep keys in an HSM or KMS, limit access, plan for key rotation
Expired or rotated server certificate Devices can no longer reach the update server Pin a long-lived CA rather than a leaf certificate; plan certificate updates well in advance
Clock not set TLS certificate validation fails on boot Get time via NTP or the network before validating, or handle the “no time yet” case deliberately

Pre-launch OTA checklist

  • Flash layout leaves room for growth: future images will be larger than today’s
  • Every release image is signed, and the bootloader verifies it on every boot
  • Hardware secure boot (and flash encryption, if needed) is enabled on production units
  • Rollback works: tested by deliberately shipping a build that fails its self-test
  • Self-test includes reaching the update server
  • Power-cut testing at random points during download and install
  • Anti-rollback policy defined
  • Update path tested from every supported older version
  • Staged rollout, pause and status reporting in place
  • Signing keys stored securely, with a documented rotation plan
  • Server certificates and CA trust lifetimes checked against the product’s expected lifespan

FAQ

Is OTA the same as FOTA? Mostly, yes. FOTA (firmware over the air) specifically means firmware updates. OTA is the broader term and can also cover configuration, ML models or full operating system images.

Do I need A/B partitions? Not strictly, but some form of rollback is strongly recommended. If flash is tight, a swap-based bootloader, external flash staging or a small recovery image can give you a fallback without doubling internal flash.

How big can an OTA image be? It’s limited by your slot size, link bandwidth, data costs and how long the device can stay awake. Wi-Fi devices routinely download images of a megabyte or more. LPWAN devices need images (or deltas) to be as small as possible.

Can I update the bootloader over the air? Some platforms support it, but a failed bootloader update can permanently brick a device. Many products keep the bootloader fixed for the device’s lifetime. If you must update it, follow the vendor’s recommended protected process and test it extensively.

Are there standards for IoT firmware updates? The IETF’s SUIT working group has published an architecture for firmware updates on IoT devices (RFC 9019) and related specifications for signed update manifests. Some bootloaders and platforms implement SUIT-style manifests, and the concepts are useful even if you build your own system.

The complete guide to iot and edge ai

Embedded Systems and the Internet of Things
Read the guide

Keep exploring

Guides from other topics

All topics →