Esp32 Boot Flow

The boot flow is where the hardware design and the firmware stack hand off to each other, and on an ESP32-class chip that handoff happens in layers because the chip can't trust anything about its own flash contents until it has verified it — a mask ROM bootloader baked into silicon at manufacturing time, a second-stage bootloader stored in flash, and finally the application image itself, each stage only running if the one before it decided it was safe to proceed. This layering exists because a chip that just jumped straight to executing whatever is in external flash would have no defense against a corrupted image, a failed OTA update, or a deliberately malicious firmware swap — the boot chain's entire job is making each of those failure modes recoverable instead of catastrophic.

Power-on reset
CPU starts executing from a fixed address in on-die mask ROM
Stage 1 — Mask ROM bootloaderBurned into silicon, cannot be changed after fabrication
Read strapping pins
Determines boot mode: normal, UART download, etc.
Load stage-2 bootloader from flash
Optionally verifies a cryptographic signature first
Stage 2 — Flash bootloaderStored in flash, updatable, still runs before the app
Partition table lookup
Finds which flash region holds the current valid app image
Image integrity + rollback check
Confirms checksum and whether this slot is marked bootable
Application firmware runs
RTOS starts, user application code executes
OTA update path
New image written to inactive partition
Current running app keeps running during download
Boot partition flag flipped
Next boot points stage 2 at the new, verified image

The mask ROM stage exists specifically because it's the one piece of boot logic a firmware bug or malicious actor can never modify — it's fixed in silicon at the fab, not stored in rewritable flash. Everything from the second-stage bootloader onward lives in external flash and is, by construction, updatable (which is exactly what makes OTA updates possible) — but that updatability is also an attack surface, so the trust chain has to start from something that genuinely cannot be altered after the chip leaves the fab, which is the entire reason mask ROM code exists instead of just putting everything in flash from the start.

Boot Chain of Trust — From Fixed Silicon to Updatable Firmware each stage only runs if the one before it verified the next Stage 0 — Mask ROM bootloader (in silicon, never changes) Reads boot-strapping pins · optional secure-boot signature check Cannot be patched, updated, or compromised by any firmware bug The one fixed anchor the entire trust chain is built on Stage 1 — Flash bootloader (in flash, updatable) Reads partition table · checks image checksum and bootable flag Decides which of two app partitions to boot (OTA slot A or B) Updatable — which is exactly what makes it an attack surface too Stage 2 — Application firmware RTOS scheduler starts, Wi-Fi/BLE stack initializes, user code runs This is the image OTA updates actually replace OTA partition A (active) currently running, untouched by OTA write OTA partition B (standby) new image written here, verified, then flagged bootable

Secure boot and flash encryption are the two protections that close the gap between "the chip verifies its firmware" and "an attacker with physical flash access can't forge or read that firmware," and they solve genuinely different problems. Secure boot checks a cryptographic signature on every image before executing it, which stops an attacker from loading unsigned or tampered firmware even if they can physically reprogram the external flash chip; flash encryption separately scrambles the actual contents of flash so that same attacker can't read out proprietary firmware or extract embedded secrets even with full physical access to the flash — a chip can run either, neither, or both depending on the product's actual threat model, and conflating the two is a common mistake in early security reviews.

The dual-partition OTA scheme exists because an update that fails halfway through can never be allowed to leave the device unable to boot at all. Writing a new firmware image directly over the currently-running one would leave the device bricked if power failed or the download corrupted mid-write; writing the new image to the inactive partition while the current one keeps running means a failed update simply leaves the device running its old, still-valid firmware, and the boot-partition flag only flips to the new image after it's been written and verified completely — which is the specific mechanism that makes field OTA updates safe to ship at scale rather than a recall risk.

The boot flow is the layer that makes every other part of this chip's design trustworthy in the field: a fixed mask-ROM anchor that can never be compromised, an updatable-but-verified second stage, optional secure boot and flash encryption closing the physical-access attack surface, and a dual-partition OTA scheme that makes firmware updates recoverable by construction rather than a gamble on every single deployed unit.

Take esp32 boot flow further

Ask the copilot about this term, or have our engineers assess it against your process.