Skip to content

Add support for recovery bootloaders - #7035

Open
playfulFence wants to merge 1 commit into
esp-rs:mainfrom
playfulFence:bootloader/recovery-bootloader
Open

playfulFence wants to merge 1 commit into
esp-rs:mainfrom
playfulFence:bootloader/recovery-bootloader

Conversation

@playfulFence

@playfulFence playfulFence commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

closes #6863

ESP32-C5, ESP32-C61, ESP32-P4, and ESP32-S31 have a recovery bootloader functionality. If the primary bootloader is broken, the ROM loads the recovery bootloader from the flash offset in eFuse. This PR uses it to update the bootloader safely:

  • BootloaderUpdater::install(staging) checks the new image, copies the current bootloader to the recovery offset, then writes the new image to the primary offset.
  • BootloaderUpdater::restore() copies the recovery bootloader back to the primary offset.
  • BootloaderUpdater::booted_from_recovery() returns true when the ROM started the recovery bootloader.
  • efuse::recovery_bootloader_offset() in esp-hal returns the recovery offset.

The image check covers the header, chip ID, chip revision, checksum, and SHA-256. The updater does not burn the eFuse, user should do that manually and following new module documentation.

An AI tool generated a significant part of this change.

Testing

ESP32-C61 v1.0, eFuse set to recovery offset 0x3F0000, ESP-IDF v6.1 bootloader from espflash:

  • install writes the new image to 0x0 and the backup to 0x3F0000. Both match the image byte for byte.
  • After I erase the first sector at 0x0, the ROM starts the recovery bootloader, and restore repairs the primary bootloader.

success

I (106) boot: Loaded app from partition at offset 0x10000
INFO - PROBE booted_from_recovery = false
INFO - PROBE install(staging) = Ok(())

damaged bootloader and restoring to the one in recovery.

invalid header: 0xffffffff
PRIMARY - FAIL
Loading RECOVERY Bootloader...
I (32) boot: ESP-IDF v6.1-829-g9a97f6c54ec 2nd stage bootloader
I (118) boot: Loaded app from partition at offset 0x10000
INFO - PROBE booted_from_recovery = true
INFO - PROBE restore() = Ok(())

Changelog

esp-bootloader-esp-idf

  • Added: bootloader_updater::BootloaderUpdater updates the bootloader with the recovery bootloader as a backup (ESP32-C5, ESP32-C61, ESP32-P4, and ESP32-S31).

esp-hal

  • Added: efuse::recovery_bootloader_offset() (ESP32-C5, ESP32-C61, ESP32-P4, and ESP32-S31).

@playfulFence
playfulFence marked this pull request as ready for review December 4, 2026 16:15
@playfulFence
playfulFence force-pushed the bootloader/recovery-bootloader branch from dd6a962 to 83854d3 Compare December 4, 2026 16:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esp-bootloader-esp-idf: Support recovery bootloaders and bootloader OTA updates

1 participant