Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

12.2 The architectural contract of a secure boot chain

A boot chain is a series of handovers. At each one, the outgoing stage hands over control of the PE with some state defined and the rest UNKNOWN. The incoming stage may assume only what was agreed. Most “it worked on FVP and hangs on silicon” bugs are a broken handover: the next stage relied on state nobody set, or the previous stage left state that matters (dirty lines, stale TLB entries, an enabled interrupt) that nobody cleaned up. This section lists what the architecture makes you specify at each boundary, and then walks through TF-A’s chain as the concrete instance. The reset path itself is in 17.1, EL3 initialisation in 17.2, and the multi-chiplet reset and boot-core election in 17.5.

The handover checklist

Every boundary has to settle each of these items, either by setting it or by stating that the next stage does:

ItemWhat must be agreedWhy the architecture makes it your problem
Target EL and Security stateSPSR_ELx.M[3:0] for the ERET, SCR_EL3.{NSE,NS}, SCR_EL3.RW, HCR_EL2.RWDetermines which regime and which register copies the next stage uses
PSTATEDAIF masked (normally all four), SPSR_ELx.SP selection (ELnh)An unmasked SError or IRQ before the next stage installs VBAR_ELx ends up at an UNKNOWN vector
Entry point and argumentsELR_ELx, X0–X3 (or more)Plain software convention, but it must be written down
MMU and caches of the next stageTarget SCTLR_ELx written to a known value: M=0, C=0, RES1 bits set, EE as requiredSCTLR_EL1/SCTLR_EL2 are UNKNOWN out of reset, and a stale M=1 jumps into the previous stage’s tables
Memory image coherencyNext-stage image cleaned to the PoC (and the I-cache invalidated to the PoU if the next stage fetches with SCTLR.I=1)With M=0, data accesses are Device-nGnRnE and do not look up the cache, so the image must already be in memory. See 8.5 and 9.3
TLBsInvalidated for any regime the outgoing stage used and the incoming stage will reuseStale entries survive SCTLR.M going 1→0→1
Lower-EL controlsCPTR_ELx, MDCR_ELx, HCR_EL2, CNTHCTL_EL2, CNTVOFF_EL2, VTTBR_EL2, … set to non-trapping safe valuesMany are UNKNOWN at reset, and an UNKNOWN trap bit gives an unexplained EC 0x18 or 0x07 trap
TimersCNTFRQ_EL0 written (only possible at the highest implemented EL), system counter enabled (CNTCR.EN)The OS cannot set the frequency and will compute time incorrectly (4.6)
GICDistributor and Redistributor security configured (GICD_CTLR.ARE_S/ARE_NS, groups, GICR_WAKER), ICC_SRE_EL3.SRE/Enable=1 so lower ELs can set ICC_SRE_EL2/EL1.SREOnly Secure software can configure groups. The Normal world can only enable its own Group 1 (4.5)
Feature enablesSCR_EL3/CPTR_EL3/MDCR_EL3 bits for every FEAT_ the next stage will useMissing ones trap to EL3, see 17.3
Memory protectionTZASC/GPT configured before any lower world runsOnce Non-secure code runs, it can touch anything left unprotected

A minimal, self-contained drop from EL3 to Non-secure EL2 that honours this contract looks like this (constants written out for clarity):

    // Next stage: AArch64 Non-secure EL2h, MMU off, DAIF masked
    ldr   x0, =0x30C50830          // SCTLR_EL2: RES1 bits, M=C=I=0, EE=0
    msr   sctlr_el2, x0
    msr   hcr_el2, xzr             // BL33 owns HCR_EL2; start with no traps
    msr   cntvoff_el2, xzr         // UNKNOWN at reset
    mov   x0, #0x531               // SCR_EL3: RW(10) | HCE(8) | RES1(5:4) | NS(0)
    msr   scr_el3, x0
    mov   x0, #0x3C9               // SPSR_EL3: D,A,I,F masked, M = EL2h
    msr   spsr_el3, x0
    adr   x0, bl33_entry
    msr   elr_el3, x0
    isb
    mov   x0, x20                  // e.g. DTB address for the next stage
    eret

The ISB before the ERET is not strictly needed for the ERET itself, because ERET is a context synchronization event. It is there so that any EL3 code between the writes and the ERET sees the new SCR_EL3. Real firmware also writes CPTR_EL2 (which has RES1 bits when HCR_EL2.E2H=0), MDCR_EL2 and the FEAT_ enables. The example shows the shape of the handover, not a complete production sequence.

TF-A as the worked example

TF-A’s generic chain without RME:

StageRuns atLoaded byHands over toMechanism
BL1 (AP Trusted ROM)EL3, from ROM, MMU on with a small mapreset (RVBAR)BL2ERET to S-EL1
BL2 (Trusted Boot Firmware)S-EL1 (or EL3 with RESET_TO_BL2, or when RME is enabled)BL1BL31SMC BL1_SMC_RUN_IMAGE back to BL1, which jumps to BL31 at EL3
BL31 (EL3 Runtime Firmware)EL3, residentBL2BL32 (init), then BL33ERET using per-world contexts
BL32 (Secure payload: OP-TEE, or an SPMC such as Hafnium)S-EL1 or S-EL2BL2back to BL31SMC “init done” to its SPD/SPMD
BL33 (Non-trusted firmware: UEFI, U-Boot)NS-EL2 (or NS-EL1)BL2OSLinux boot protocol, 17.6

Where TF-A meets each contract item:

  • BL1 → BL2. BL1 is the first trusted code. It does the EL3 architectural setup (SCTLR_EL3, SCR_EL3, CPTR_EL3, MDCR_EL3, CNTFRQ_EL0) and enables the interconnect’s coherency on Arm platforms. It authenticates BL2, then ERETs to S-EL1 with x1 holding a meminfo_t describing the memory BL2 may use. On FVP, x0 carries the address of the firmware configuration (FW_CONFIG). The S-EL1 SCTLR_EL1 is written to a clean MMU-off value as part of the context setup.
  • BL2 → BL31. BL2 loads, authenticates and cleans to the PoC every image it places (flush_dcache_range() after load), because each is entered with the MMU off. At S-EL1 it cannot jump to EL3, so it issues BL1_SMC_RUN_IMAGE. TF-A’s firmware-design document then describes BL1 doing exactly what the table requires: it clears SCTLR_EL3.M/I/C, cleans the data cache to the PoC, invalidates the TLBs and jumps to BL31 at EL3. x0 points to the bl_params list (an entry_point_info_t per image: PC, SPSR, security attribute, args). x1/x2 carry platform configuration such as SOC_FW_CONFIG and HW_CONFIG.
  • BL31 → BL32. BL31 repeats the EL3 setup (BL1 is in ROM and cannot be patched, so BL31 overrides it). It initialises the GIC Distributor and Redistributors as their Secure owner, and builds a cpu_context_t per world. The SPD (opteed) or SPMD then ERETs into BL32 for initialisation, and BL32 returns via an SMC with a fixed function ID that means “boot done”. Only then does BL31 enter BL33.
  • BL31 → BL33. cm_prepare_el3_exit() builds SCR_EL3 for the Non-secure world (NS, RW, HCE, plus FEAT_ enables). For BL33 at EL2 it writes SCTLR_EL2 to its RES1 value with the correct EE. When EL2 is implemented but BL33 runs at EL1, init_nonsecure_el2_unused() neutralises EL2: HCR_EL2 with only RW set, CPTR_EL2 non-trapping, CNTHCTL_EL2 allowing EL1 physical timer and counter access, CNTVOFF_EL2=0, VTTBR_EL2=0, MDCR_EL2 and ICC_SRE_EL2 set up. The ERET carries the SPSR and args that BL2 recorded for BL33.

With RME enabled, BL2 runs at EL3 (BL1 still loads it) and also loads the RMM image into the Realm PAS. The GPT is built before any lower world runs. After initialising BL32, BL31 initialises the RMM by an ERET to R-EL2, and the RMM answers with RMM_BOOT_COMPLETE before BL31 enters BL33 (12.4).

Bring-up note: when the next stage hangs immediately after the ERET, read ESR_EL3/ELR_EL3 in the debugger before anything else. An ELR_EL3 pointing at an instruction in the next stage with EC 0x18 means a lower-EL system register access trapped: the next stage touched something CPTR_EL3/MDCR_EL3/SCR_EL3 still traps. A PC that ends up at an offset such as +0x200 or +0x380 from an address the next stage never set up means it took an exception before installing VBAR_EL2/VBAR_EL1, which are UNKNOWN out of reset. Check SPSR_EL3.DAIF in the handover, and whether the image was cleaned to the PoC.

Image authentication, in brief

The authentication contract comes from Arm’s TBBR (Trusted Board Boot Requirements, DEN0006), implemented by TF-A’s Trusted Board Boot:

  • The root of trust is a hash of the Root-of-Trust Public Key (ROTPK) held in OTP or fuses, plus BL1 in ROM. Everything else is verified against it.
  • A chain of X.509v3 certificates travels in the FIP: a Trusted Key certificate signed by the ROTPK, key certificates for the Trusted World and Non-trusted World keys, then content certificates holding image hashes for BL2, BL31, BL32, BL33 and the RMM.
  • Anti-rollback: certificates carry NV counters (Trusted and Non-trusted) that are checked against monotonic hardware counters.
  • Measured boot is a separate property from verified boot: each stage extends a measurement into an event log or a hardware root of trust (for example an RSE or a TPM) for later attestation. On CCA systems the platform attestation token is rooted in those measurements (12.4).

The architecture’s part is small but non-negotiable. Verification must happen on the copy that will execute, after it is in memory the verifier controls. The image must then be cleaned to the PoC before the jump, so that what runs is what was hashed.

Security note: a classic time-of-check/time-of-use gap is verifying an image in a Non-secure-accessible buffer (or one a DMA master can still write) and then executing it in place. The TZASC or GPT protection must cover the image before hashing starts, not after.

Checkpoint

Q12.2.1 BL2, running with its MMU and D-cache on, copies BL31 into SRAM and verifies its hash. BL31 is entered at EL3 with SCTLR_EL3.M=0, C=0. BL31 sometimes executes garbage. Which handover step is most likely missing?

  • A. A DSB SY after the copy, so the stores complete before the jump
  • B. A clean of the BL31 range to the PoC: with the MMU off, data accesses are Device-nGnRnE and the I-fetch is Non-cacheable if SCTLR_EL3.I=0, so the dirty lines in BL2’s cache are not seen
  • C. An ISB at BL31’s entry point
  • D. TLBI ALLE3, because BL1’s EL3 tables are still cached
Answer

B. The copy sits in dirty cache lines. A DSB (A) makes the stores complete, but for a cacheable store that does not imply the data has left the cache. Only a clean pushes it to the PoC, where a non-cacheable access looks. TF-A cleans every loaded image to the PoC for exactly this reason. Stale TLB entries (D) matter only once BL31 turns its MMU on.

Read more: Arm ARM (DDI0487), Behavior when stage 1 address translation is disabled; Data cache maintenance instructions; TF-A firmware design, “BL2 image load”

Q12.2.2 BL31 ERETs to BL33 at Non-secure EL1 on a core that implements EL2, without ever writing EL2 registers. Linux then fails intermittently, most visibly in timekeeping. What did the handover miss?

  • A. Nothing: EL2 registers are ignored when SCR_EL3.HCE=0
  • B. SCR_EL3.RW, which must be 0 when skipping EL2
  • C. ICC_SRE_EL3.Enable, without which EL1 cannot use the GIC system registers
  • D. Neutralising EL2: registers such as HCR_EL2, CNTHCTL_EL2 and CNTVOFF_EL2 still affect Non-secure EL1&0 when EL2 is implemented, even if nothing runs there, and their reset values are UNKNOWN
Answer

D. When EL2 is implemented and enabled for the Security state, its controls apply to EL1&0 whether or not software runs at EL2. An UNKNOWN CNTVOFF_EL2 offsets the virtual counter, and an UNKNOWN CNTHCTL_EL2 can trap physical timer access. HCE (A) only enables the HVC instruction. TF-A’s init_nonsecure_el2_unused() exists for exactly this case.

Read more: Arm ARM (DDI0487), HCR_EL2, CNTHCTL_EL2, CNTVOFF_EL2 reset values; TF-A init_nonsecure_el2_unused

Q12.2.3 Why does TF-A, without RME, have BL2 call back into BL1 with BL1_SMC_RUN_IMAGE instead of jumping to BL31 directly?

  • A. BL2 runs at S-EL1, and the only way to enter EL3 code from a lower EL is an exception to EL3. BL1’s SMC handler owns EL3 at that point, disables its MMU and caches, cleans to the PoC and enters BL31 at EL3
  • B. BL31’s entry point is in ROM, which only BL1 can map
  • C. The SMC is a context synchronization event, which is needed for the new VBAR_EL3
  • D. BL1 must authenticate BL31, because BL2 is not trusted to verify EL3 images
Answer

A. A lower EL cannot branch into a higher EL. It must take an exception that the higher EL handles. With RESET_TO_BL2 or RME, BL2 already runs at EL3 and jumps directly. Authentication of BL31 (D) is done by BL2 in TF-A’s Trusted Board Boot. BL31 is in trusted SRAM, not ROM (B).

Read more: TF-A firmware design, “BL1” and “Running BL2 at EL3 execution level”; Arm ARM (DDI0487), Exception entry