Q&A-4Walk me through the embedded boot sequence from power-on reset (POR) through ROM, primary bootloader, secondary bootloader, to kernel/application handoff.
Answer
Assumptions up front: Cortex-M33-class MCU, mask ROM root of trust with OTP eFuses, A/B slots, MCUboot-style secondary bootloader. On an application processor (Cortex-A + Linux) the same five stages exist, but TF-A and U-Boot take stages 1–2 and the handoff is to a kernel image rather than a bare reset handler.
Core answer (first 90 seconds)
POR releases the core reset line. The hardware fetches the initial MSP from 0x00000000 and the reset vector (PC) from 0x00000004, landing in mask ROM. ROM reads strap pins and OTP, verifies the FSBL signature against a hash burned into eFuses, and branches to it. FSBL brings up the PLL and external DRAM, checks the anti-rollback counter, verifies the SBL, and jumps. The SBL selects the active slot, verifies the application image, completes any pending A/B swap, then disables interrupts and DMA and branches to the application's reset handler with VTOR and MSP repointed at the app's vector table. Every stage verifies the next before handing over; nothing downstream is trusted until its signature checks out.
Stage detail
Boot ROM. Minimal oscillator init, watchdog config, flash controller enable. Verifies the FSBL signature (ECDSA-P256 or Ed25519) against a public-key hash in OTP. On success it sets SCB->VTOR, resets the stack pointer, and branches. On failure it forces recovery (USB DFU/UART) or enters a watchdog reset loop.
Primary bootloader (FSBL). Moves the clock from the internal RC (e.g. 16 MHz) to the external crystal via PLL, brings up the PMIC and external memory controller (Octal SPI PSRAM, DRAM, or NOR). Checks rollback counters in secure monotonic counters/eFuses and authenticates the SBL. Loads it into RAM or leaves it XIP and jumps.
Secondary bootloader. Reads slot metadata (slot-0 active vs slot-1 candidate) and image trailer flags (IMAGE_OK, TEST_PENDING). Authenticates the application header and payload hash, checks the security counter against the anti-rollback threshold, and performs the pending swap or decrypts the payload into the execution slot.
Trade-offs and when not to use each
- Skip the FSBL or keep it. If the part has no external DRAM and runs XIP from on-chip flash, ROM can jump straight to the application: one fewer signed image and one fewer key to rotate. Keep the FSBL when you need PLL/DRAM/PMIC bring-up that ROM deliberately omits, or when you want the ROM's attack surface frozen while boot policy evolves.
- XIP vs copy-to-RAM. XIP keeps RAM free and starts instantly, but every fetch pays flash latency and in-place decryption is awkward. Copy-to-RAM costs image-size RAM plus a memcpy, and buys deterministic timing and easy decryption. Choose XIP when RAM is the scarce resource; copy when the image is encrypted or the flash is slow (QSPI at ~50 MHz vs SRAM at ~200 MHz).
- Swap vs overwrite. Swap gives rollback: a failed new image reverts to the old slot, at the cost of a scratch area and flash wear from moving sectors. Overwrite is simpler and cheaper but a power loss mid-write bricks the device. Use swap when field updates must be recoverable; use overwrite only with a separate recovery path (ROM DFU) you are willing to fall back on.
- ECDSA-P256 vs Ed25519. Ed25519 verifies faster with smaller keys and signatures (32-byte key, 64-byte signature), which matters when the ROM verify budget is tens of milliseconds. ECDSA-P256 is the pick when a FIPS/NIST mandate or an existing PKI forces it. Both are sound; decide on verify time, key size, and compliance, not on "more secure".
Failure modes and detection
- OTP hash mismatch → ROM falls to recovery or a reset loop; read the boot status register / ROM error code.
- DRAM init fault (bad timing params) → FSBL hangs before console output; detect with a scope on the clock lines or a ROM-level UART trace.
- Interrupted swap → trailer flags inconsistent; the SBL must validate trailer magic and image state on every boot and resume or revert.
- Dirty interrupt/DMA state at handoff → the app faults on its first interrupt; clear
NVIC->ICER/ICPRand check DMA channel enable bits before the branch.
Handoff
/* Checked against CMSIS for Cortex-M33. */
void jump_to_app(uint32_t app_vector_addr) {
uint32_t *app_vtor = (uint32_t *)app_vector_addr;
uint32_t app_sp = app_vtor[0];
uint32_t app_entry = app_vtor[1];
__disable_irq();
SysTick->CTRL = 0; /* Stop core timer */
SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk; /* Write-1-to-clear, not |= */
for (int i = 0; i < 8; i++) { /* 8 regs cover 256 IRQs */
NVIC->ICER[i] = 0xFFFFFFFF; /* Disable all */
NVIC->ICPR[i] = 0xFFFFFFFF; /* Clear pending */
}
SCB->VTOR = app_vector_addr; /* Relocate vector table */
__set_MSP(app_sp); /* Reset main stack pointer */
__DSB();
__ISB();
((void (*)(void))app_entry)(); /* Branch to Reset_Handler */
}| Stage | Executed from | Key responsibilities | Primary failure mode |
|---|---|---|---|
| Boot ROM | Mask ROM | Read strap pins/OTP, check FSBL signature, basic clocks | OTP hash mismatch, unrecoverable boot loop |
| Primary bootloader | SRAM / on-chip flash | PLL/DRAM bring-up, anti-rollback counters, authenticate SBL | Memory init fault (bad timing params) |
| Secondary bootloader | External/internal flash (XIP) | A/B swap state, payload decryption, app signature check | Interrupted swap, signature mismatch |
| Application / OS | Internal flash / DRAM | HAL, RTOS scheduler init, set IMAGE_OK | Fault from dirty interrupt/DMA state |
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.