Home / Learn Chip Programming / OTA Updates: Safe Remote Firmware Update

OTA Updates: Safe Remote Firmware Update

Update devices in the field over Wi-Fi without cables.

In shortUpdate devices in the field over Wi-Fi without cables.

Theory in plain words

Safe OTACheck version on serverdownload to ota_1verify hash/signatureset boot to ota_1, rebootself test OK? mark valid; else rollback
Safe OTA

What it is

OTA writes a new firmware image into the inactive app partition, verifies it, then switches the boot partition. If the new image fails, rollback returns to the old one.

Why we use it

A product without OTA cannot fix bugs after sale. A bad OTA that bricks devices is a disaster, so safety matters.

How it works

Host the .bin over HTTPS, download with esp_https_ota, verify the signature and version, set the boot partition, reboot, mark the new app valid after a self-test, otherwise roll back.

Where it is used

  • Smart home devices
  • Remote sensors
  • Fleet updates

OTA state machine

Simulate an update with a bad imageTry it Yourself

Rollback is the safety net. Enable CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE and call esp_ota_mark_app_valid_cancel_rollback() only after your self-test passes.

HTTPS OTA call
esp_http_client_config_t http = { .url = "https://example.com/fw/v1.1.bin", .cert_pem = server_cert_pem, .timeout_ms = 10000 };
esp_https_ota_config_t ota = { .http_config = &http };
if (esp_https_ota(&ota) == ESP_OK) esp_restart();
// after reboot, in app_main when everything works:
esp_ota_mark_app_valid_cancel_rollback();

Quick quiz

1. What protects against a bad update?

2. When mark the new app valid?

Common questions

What protects against a bad update?

Rollback to the previous partition. The bootloader returns to the old app.

When mark the new app valid?

After a successful self-test. Only confirmed good images stay.