bootESP32otadataota_0ota_1v2.bin1esp_https_ota(&cfg);2esp_restart();3if (self_test_ok())4esp_ota_mark_app_valid_cancel_rollback();NEWPENDINGVALIDABORTEDota_1ota_1v2!v1
Back: the ESP32 board (bootloader, chip, flash: otadata, ota_0, ota_1) and the update serverFront: the update code and the image states of ota_1Tokens: v2 arriving, chunks, the otadata pointer, the image that bootsAn ESP32 board, 4 MB flash with two app slots: v1 runs from ota_0 while v2 is downloaded over HTTPS and written into ota_1. Only after the image is checked does otadata switch to ota_1. With rollback on, v2 gets one boot to confirm itself; ours crashes first, so the bootloader marks it ABORTED and starts v1 again.

Two slots

  1. An over-the-air (OTA) update installs new firmware through the network, with no cable. Our ESP32's flash has two OTA app slots of 1 MB each. Version v1 runs from ota_0. A small record, otadata, says which slot to start.

Download and switch

Prove it or roll back

What happens

;; step 1/10 · two-slots
flash (4 MB)   nvs · otadata · phy_init · factory · ota_0 · ota_1
otadata   0xd000, 0x2000 bytes: which slot boots
ota_0     0x110000, 1 MB   v1, running
ota_1     0x210000, 1 MB   empty

The card shows four lines. The full code also fills in the server address and certificate, and calls esp_ota_mark_app_invalid_rollback_and_reboot() when the self-test fails. esp_https_ota() runs esp_ota_begin, esp_ota_write, esp_ota_end and esp_ota_set_boot_partition for you. Rollback only works when the bootloader is built with CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE (in menuconfig). Without it the new image boots with no trial, and the confirm call is optional.