8000
Skip to content

[safe_mode] Detect bootloader rollback support at runtime - #13230

Merged
swoboda1337 merged 2 commits into
esphome:devfrom
swoboda1337:safe_mode-detect-bootloader-rollback
Jan 15, 2026
Merged

[safe_mode] Detect bootloader rollback support at runtime#13230
swoboda1337 merged 2 commits into
esphome:devfrom
swoboda1337:safe_mode-detect-bootloader-rollback

Conversation

@swoboda1337
@swoboda1337 swoboda1337 commented Jan 15, 2026
Copy link
Copy Markdown
Member

What does this implement/fix?

Detect at boot if the bootloader supports OTA rollback by checking the partition state:

  • ESP_OTA_IMG_NEW: Bootloader didn't transition to PENDING_VERIFY → not supported
  • ESP_OTA_IMG_PENDING_VERIFY: Bootloader is tracking state → supported
  • Other states: support unknown

Note: Detection only works on the first boot after an OTA update. After safe_mode marks the partition as valid, subsequent boots will show "support unknown".

Note: Detection requires the device to have been OTA'd from a build with rollback enabled. If upgrading from an older build without rollback support, a second OTA may be needed before "supported" is shown.

This helps users identify when their bootloader doesn't support the rollback feature.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • N/A

Pull request in esphome-docs with documentation (if applicable):

  • N/A

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • LN882x
  • nRF52840

Example entry for config.yaml:

# No config changes required - detection is automatic when using:
esp32:
  framework:
    type: esp-idf
    advanced:
      enable_ota_rollback: true

safe_mode:

ota:
  platform: esphome

Example output in logs:

[C][safe_mode:030]:   Bootloader rollback: supported

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

🤖 Generated with Claude Code

@swoboda1337
swoboda1337 requested a review from kbx81 as a code owner January 15, 2026 02:41
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hi there! This PR modifies 2 file(s) with codeowners.

@jsuanet, @kbx81, @paulmonigatti - As codeowner(s) of the affected files, your review would be appreciated! 🙏

Note: Automatic review request may have failed, but you're still welcome to review.

@github-actions
github-actions Bot commented Jan 15, 2026
Copy link
Copy Markdown
Contributor

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#13230
    components: [safe_mode]
    refresh: 1h

(Added by the PR bot)

@codecov-commenter
codecov-commenter commented Jan 15, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.79%. Comparing base (f1e5d3a) to head (1600229).
⚠️ Report is 7 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #13230      +/-   ##
==========================================
+ Coverage   73.76%   73.79%   +0.02%     
==========================================
  Files          53       53              
  Lines       11329    11329              
  Branches     1538     1538              
==========================================
+ Hits         8357     8360       +3     
+ Misses       2572     2570       -2     
+ Partials      400      399       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
github-actions Bot commented Jan 15, 2026
Copy link
Copy Markdown
Contributor

Memory Impact Analysis

Components: safe_mode
Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 28,532 bytes 28,532 bytes ➡️ +0 bytes (0.00%)
Flash 324,127 bytes 324,127 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

Comment thread esphome/components/safe_mode/safe_mode.h Outdated
bdraco
bdraco previously approved these changes Jan 15, 2026
bdraco
bdraco previously approved these changes Jan 15, 2026
@swoboda1337
swoboda1337 marked this pull request as draft January 15, 2026 03:32
@swoboda1337
swoboda1337 force-pushed the safe_mode-detect-bootloader-rollback branch from 6b1fc4f to 90d345d Compare January 15, 2026 03:33
@swoboda1337
swoboda1337 marked this pull request as ready for review January 15, 2026 03:34
@swoboda1337
swoboda1337 requested a review from a team as a code owner January 15, 2026 03:34
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hi there! This PR modifies 4 file(s) with codeowners.

@esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏

Note: Automatic review request may have failed, but you're still welcome to review.

@swoboda1337
swoboda1337 marked this pull request as draft January 15, 2026 04:02
@swoboda1337
swoboda1337 marked this pull request as ready for review January 15, 2026 04:10
@swoboda1337
swoboda1337 requested a review from bdraco January 15, 2026 04:10
bdraco
bdraco previously approved these changes Jan 15, 2026
@swoboda1337
swoboda1337 marked this pull request as draft January 15, 2026 13:27
Check the OTA partition state at boot to detect if the bootloader
supports rollback:
- NEW: bootloader didn't transition to PENDING_VERIFY (not supported)
- PENDING_VERIFY: bootloader is tracking state (supported)
- Other: support unknown

Display the result in dump_config.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread esphome/components/safe_mode/safe_mode.h Outdated
Comment thread esphome/components/safe_mode/safe_mode.cpp Outdated
bdraco
bdraco previously approved these changes Jan 15, 2026
@swoboda1337
Copy link
Copy Markdown
Member Author

Thanks

@swoboda1337
swoboda1337 merged commit 0dc5a7c into esphome:dev Jan 15, 2026
25 checks passed
swoboda1337 added a commit that referenced this pull request Jan 15, 2026
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
@swoboda1337 swoboda1337 mentioned this pull request Jan 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0