In development. It changes without notice.
Topic
Update Policy
What a boot decides after an update: to keep the new firmware, to refuse it, or to say that the board went back to the previous one.
| Action | When |
|---|---|
| NONE | The firmware that runs was accepted before. |
| MarkValid | The first boot of a new one. It is accepted once the hardware has come up. |
| RejectImage | The first boot of one that cannot read this vault's partition. It is sent back. |
| RollbackDetected | An update was tried and the previous firmware runs: the owner is told. |
A new firmware that never marks itself valid is undone by the bootloader at the next start. An update touches neither the vault nor the bootloader, and one older than the firmware that runs is refused. The upload is in Wi-Fi Admin Portal and the writer in Storage.
- See also
- Wi-Fi Admin Portal, Storage
Files | |
| file | src/ |
| Side-effect-free OTA boot-time decision logic (native-testable). | |
Classes | |
| class | kleidos:: |
| When a fresh OTA image is confirmed: once its first loop tick has run, never in setup. More about kleidos:: | |
Enumerations | |
| enum class | kleidos:: |
| Mirror of the platform OTA image states for the subset of values we care about. Kept stand-alone so the native test build does not pull in ESP-IDF OTA headers. More about kleidos:: | |
| enum class | kleidos:: |
| Requested action following OTA boot-time checks. More about kleidos:: | |
Functions | |
| BootAction | kleidos:: |
| Decide what to do on boot. | |
| constexpr BootAction | kleidos:: |
| Confirm a fresh OTA only when its read path does not refuse the vault. | |
| constexpr bool | kleidos:: |
| Whether the boot's verdict clears the OTA markers at once. | |
| bool | kleidos:: |
| Accept or reject a candidate firmware version before staging an OTA flash. | |
| bool | kleidos:: |
| Accept or reject a candidate image built for a different board variant. | |
Variables | |
| constexpr size_t | kleidos:: |
Enumeration Type Documentation
BootAction #
Requested action following OTA boot-time checks.
ImgState #
Mirror of the platform OTA image states for the subset of values we care about. Kept stand-alone so the native test build does not pull in ESP-IDF OTA headers.
Function Documentation
confirmPendingImage() #
Confirm a fresh OTA only when its read path does not refuse the vault.
The verdict is taken before the vault is first mounted, and an image once marked valid is never rolled back. An image whose read path refuses the vault partition (a whole-vault memory map the data window cannot hold, or a mapped read over an unflagged row under Flash Encryption, Storage) would then boot for good to an unlock screen with no vault behind it, and on the hardened build, with ROM download mode off, no cable could bring the vault back. Such an image is rejected while the bootloader can still return to the previous one.
It rejects a read-path refusal only. vaultMountAdmitted comes from no mount, so a fresh image whose LittleFS mount would fail for another reason is still confirmed.
- Parameters
-
Name Meaning action What decideOnBoot decided. vaultMountAdmitted The running image's read path would not refuse the vault partition ( littlefs::); only consulted formountAdmitted() MarkValid.
- Return values
-
Value Meaning BootAction:: RejectImage actionwasMarkValidand the read path refuses the vault.action Otherwise, unchanged.
- See also
- decideOnBoot
decideOnBoot() #
Decide what to do on boot.
Decision rules (in order)
- If
imgState==PendingVerify→MarkValid(the bootloader selected a new partition and is waiting for the running app to confirm it viaesp_).ota_ mark_ app_ valid_ cancel_ rollback() - Else if
attemptedFlagis set ANDcurrentVersionmatchespreviousVersion→RollbackDetected(the bootloader reverted because the new partition failed to self-validate in time). - Else →
NONE.
- Parameters
-
Name Meaning imgState Partition state reported by the bootloader. attemptedFlag NVS flag — true iff an OTA upload completed in the previous session and we expected the next boot to come from the new partition. previousVersion Version string of the firmware that was running at the moment the OTA was applied (stored in NVS right before a software restart). Empty/null if unknown — in that case rollback cannot be detected and the function returns NONE. currentVersion Firmware version string baked into the running binary (compile-time).
- Return values
-
Value Meaning BootAction:: NONE Long-validated firmware; no UI action needed. BootAction:: MarkValid First boot of a fresh OTA; show validated toast and call esp_.ota_ mark_ app_ valid_ cancel_ rollback() BootAction:: RollbackDetected Bootloader reverted; show blocking rollback alert.
- See also
- ImgState, BootAction
markersClearedAtVerdict() #
Whether the boot's verdict clears the OTA markers at once.
The markers are how the image that runs after a rollback knows one happened: decideOnBoot reads RollbackDetected from them. Two verdicts keep them: MarkValid, until the image is marked valid (one that faults or fails its mark first is rolled back with the markers there, and the previous image shows the rollback alert), and RejectImage, whose image goes back to the previous one, rebooting at once or, if the rollback is refused, on its next reset, and the previous image says so. RollbackDetected and NONE are final and clear them.
- Parameters
-
Name Meaning action What decideOnBoot and confirmPendingImage decided.
- Return values
-
Value Meaning true Clear the markers now. false Leave them: for the mark (ImageConfirmation:: clearMarkersAfterMark), or for the image the bootloader returns to.
projectNameIsAcceptable() #
Accept or reject a candidate image built for a different board variant.
The bootloader validates the chip ID, so a classic-ESP32 image can never boot on an ESP32-S3. It does nothing for boards that share a chip: an image built for one of them passes every check the bootloader makes on another, and then drives the wrong hardware. esp_ is the only field in the image header that names the variant, and each board's build stamps its own, so an exact match is the guard.
Both operands are treated as fixed-width, possibly unterminated buffers of kProjectNameFieldBytes bytes, because a candidate descriptor comes from an uploaded image and must never be walked past its field. A buffer with no terminator inside the field is malformed and rejected, exactly like an unreadable one.
- Parameters
-
Name Meaning running Project name of the currently running image. candidate Project name embedded in the OTA image being staged.
- Return values
-
Value Meaning true Both names are well-formed and identical. false Names differ, or either buffer is null, empty, or unterminated.
versionIsAcceptable() #
Accept or reject a candidate firmware version before staging an OTA flash.
Compares candidate against running using semantic-version ordering (major.minor.patch, numeric per field):
- Returns
truewhencandidate>=running(equal or newer: acceptable). - Returns
falsewhencandidate<running(downgrade: rejected). - Returns
false(fail-closed) on null, empty, or malformed input.
This is a defense-in-depth guard that runs in the application layer — the primary anti-rollback guarantee of the hardened build is the eFuse SECURE_ enforced by the bootloader. This check adds a visible rejection with a logged reason before a wasted flash/boot cycle.
- Parameters
-
Name Meaning running Version string of the currently running firmware, read from its own image descriptor (e.g. "1.2.3").candidate Version string embedded in the OTA image being staged.
- Return values
-
Value Meaning true Candidate is equal to or newer than the running version. false Candidate is older, or either string is null/ empty/ malformed.
Variable Documentation
kProjectNameFieldBytes #
Capacity of esp_, in bytes, terminator included.
Mirrored here rather than included: this header is compiled by the native test build, which has no ESP-IDF. The field is a fixed 32-byte array in the image header and a candidate image is untrusted input read back out of flash, so it may not be NUL-terminated at all — every comparison against it is bounded by this constant.