17.6 Handing off to the OS
The last firmware stage (BL33: U-Boot, UEFI/EDK2, or a minimal loader) hands the PE to an operating system. For Linux on arm64 this handover is specified in a single document, Documentation/arch/arm64/booting.rst in the kernel tree, and that document is effectively a checklist of architectural state. This section reads it as an architecture contract: what each requirement means in Arm ARM terms, which boot stage is responsible for it, and how a violation shows up. The general handover checklist is in 12.2, and the EL3 enables it relies on are in 17.3.
The loader’s part: memory, DTB, image placement
Before the jump, the loader must have:
- Initialised all RAM the kernel will use, and described it (DT
memorynodes, or the UEFI memory map). Anything described and not reserved is the kernel’s to overwrite, so firmware-resident memory (BL31, BL32, the RMM, the SCP’s shared memory) must be excluded or listed in/memreserve/orreserved-memory. - Placed the DTB on an 8-byte boundary, no larger than 2 MB. The kernel maps it cacheable with blocks of up to 2 MB, so the DTB must not share a 2 MB region with anything that needs different attributes, such as a Device region or Non-cacheable shared memory. Otherwise you get the mismatched-attribute aliases of 6.6.
- Decompressed the kernel (arm64 has no self-decompressor) and placed the
Imageattext_offsetfrom a 2 MB-aligned base in usable RAM, with at leastimage_sizebytes free after it. Both values come from the 64-byte image header (magic0x644d5241, “ARM\x64”), whoseflagsfield also gives the kernel’s endianness and page size. - Quiesced every DMA-capable device. A DMA engine still writing into memory the kernel now owns corrupts it with no fault. Firmware drivers that started DMA (network boot, storage) must stop it, and an SMMU left in bypass does not help.
The CPU state at entry
The architectural requirements for the primary CPU, and the stage that normally satisfies each one:
| Requirement | Architectural meaning | Set by |
|---|---|---|
x0 = physical address of the DTB; x1–x3 = 0 | Plain convention; nonzero x1–x3 are reserved for future use | BL33 |
All of PSTATE.DAIF masked | No exception may be taken before the kernel installs VBAR_EL2/VBAR_EL1 | BL33 (and BL31’s SPSR_EL3 for BL33) |
| Non-secure state, at EL2 (recommended) or EL1 | EL2 entry gives the kernel the choice of running with VHE at EL2 (KVM host) or installing a stub and dropping to EL1 | BL31 SCR_EL3.NS=1, HCE=1; BL33 must not drop to EL1 unnecessarily |
| MMU off at the entry EL | SCTLR_ELx.M=0: data accesses are Device-nGnRnE, instruction fetches Normal | BL33 |
| I-cache on or off, but no stale entries for the image | After writing the image, IC IALLU (or by VA to the PoU) and DSB and ISB (8.6) | BL33 |
| Image cleaned to the PoC, by VA when a system cache or other coherent masters with caches enabled exist | With M=0 the kernel’s first data accesses bypass the caches, so the image must be in memory. Set/way only cleans the local hierarchy (8.5) | BL33 |
| System caches that obey VA CMOs: configured, may be enabled; caches that don’t: configured and disabled | The kernel’s VA maintenance must be sufficient for correctness | Platform firmware |
CNTFRQ_EL0 programmed; CNTVOFF_EL2 consistent on all CPUs; at EL1 entry, CNTHCTL_EL2.EL1PCTEN=1 | Only the highest EL can write CNTFRQ_EL0. An inconsistent CNTVOFF_EL2 makes the virtual counters of different CPUs disagree (4.7) | BL31 (CNTFRQ), BL31/BL33 (EL2 state) |
| All booted CPUs in the same coherency domain | TLBI ...IS, DC ... broadcasts and Inner Shareable ordering must reach every CPU; this may require IMPLEMENTATION DEFINED setup | BL31 and platform (17.4, 17.5) |
| All writable architected system registers at or below the entry EL initialised | Nothing may run in an UNKNOWN state. This is the general rule behind the per-feature list that follows | BL31 and BL33 |
The document’s register-level list then names specific bits, grouped by feature, separately for “EL3 is present” and for “the kernel is entered at EL1 and EL2 is present”. It is the Linux side of the EL3 checklist in 17.3. A representative selection:
| Feature | If EL3 is present | If the kernel is entered at EL1 with EL2 present |
|---|---|---|
| EL2 entry | SCR_EL3.HCE=1 | — |
| GICv3 in v3 mode | ICC_SRE_EL3.{Enable,SRE}=1; SCR_EL3.FIQ identical on all CPUs and constant | ICC_SRE_EL2.{Enable,SRE}=1 |
| FP/SIMD | CPTR_EL3.TFP=0 | CPTR_EL2.TFP=0 |
| SVE | CPTR_EL3.EZ=1; ZCR_EL3.LEN identical on all CPUs | CPTR_EL2.TZ=0 (or ZEN=0b11); ZCR_EL2.LEN identical |
| SME | CPTR_EL3.ESM=1, SCR_EL3.EnTP2=1, SMCR_EL3.LEN identical | CPTR_EL2 SME traps off, fine-grained traps for TPIDR2_EL0 off |
| PAuth | SCR_EL3.{API,APK}=1 | HCR_EL2.{API,APK}=1 |
| MTE | SCR_EL3.ATA=1 | HCR_EL2.ATA=1 |
| AMU | CPTR_EL3.TAM=0, CPTR_EL2.TAM=0, AMCNTENSET0_EL0/AMCNTENSET1_EL0 set | AMCNTENSET0_EL0/AMCNTENSET1_EL0 set |
| FGT, FGT2, HCX, TCR2, S1PIE, GCS | SCR_EL3.{FGTEn, FGTEn2, HXEn, TCR2En, PIEn, GCSEn}=1 | Corresponding HCRX_EL2 and HFG*TR_EL2 enables set |
| Debug, PMU, BRBE | MDCR_EL3.TDA=0, TPM=0, SBRBE = 0b01 or 0b11 | Matching MDCR_EL2/HDFG*TR_EL2 fields |
The document allows one relaxation: where a value is specified to disable a trap, firmware may leave the trap enabled, provided the higher EL handles it transparently, as if the documented value had been set. A hypervisor emulating a register is fine. EL3 panicking or injecting an UNDEF is not.
Always check the version of booting.rst that matches the kernel you boot. The per-feature list grows with every new extension the kernel supports, and older firmware will not know about the newest entries.
Secondary CPUs
Every CPU must enter the kernel at the same Exception level and meet the same CPU-state requirements (MMU off, DAIF masked, timers, coherency, system registers). The DTB’s cpu nodes must carry an enable-method:
"psci": the secondaries stay outside the kernel’s memory (in firmware, or in reserved memory), and the kernel issuesCPU_ONas described in the PSCI specification. The DT needs apscinode giving the conduit (smcorhvc)."spin-table": each secondary spins in reserved memory on itscpu-release-addr(a naturally aligned, zero-initialised 64-bit location) until the kernel writes an entry address there and issuesSEV(17.4).
With PSCI, BL31 satisfies the per-CPU state requirements on each secondary’s warm-boot path, using the same context code as for the primary. With spin-table, whatever ran on the secondary before it started spinning has to have done all of that, and nothing can correct it later.
Booting through UEFI
When BL33 is UEFI firmware, the kernel image is also a PE/COFF executable (the header’s res5 field points at the PE header). It runs first as a UEFI application, the EFI stub. That changes what is visible at each point:
- The stub runs under UEFI’s environment: MMU on with an identity map, caches enabled, at EL2 or EL1 as UEFI was entered.
- The stub loads the initrd, fetches the DTB from the UEFI configuration table (or none, with ACPI), calls
ExitBootServices(), and enters the kernel proper. Older kernels clean the image to the PoC and turn the MMU off first, then use the normal entry. Recent kernels (from around v6.2) can enter with UEFI’s identity map still live, through a kernel-internal path. Either way, this handover is internal to the kernel.
So with UEFI, the booting.rst MMU and cache rules are the stub’s concern, not the firmware’s, while the firmware’s obligations shift to the UEFI specification and to Arm’s BBR (Base Boot Requirements). The EL3-dependent items (SCR_EL3, CPTR_EL3, MDCR_EL3, CNTFRQ_EL0, GIC security configuration) remain BL31’s job in both paths.
Device tree or ACPI
The hardware description is the other half of the handover, and the choice is made by the platform class rather than by personal taste:
- Device tree is the norm for embedded and SoC-specific platforms: U-Boot or a minimal loader, firmware and kernel often built together, and bindings maintained in the kernel tree. TF-A can pass a DTB (
HW_CONFIG) through BL33 to the kernel. - ACPI (with UEFI) is required for Arm servers under SBSA/SystemReady SR. The OS discovers hardware through tables such as MADT (GIC and CPUs), GTDT (timers), IORT (SMMU and ITS topology), PPTT (cache and CPU topology), SRAT/HMAT (NUMA) and AEST (RAS), and runtime services go through firmware interfaces instead of OS drivers for platform-specific controllers.
The content requirements, the table-by-table mapping and the common mistakes found in compliance runs are in 18.6.
Bring-up note: when the kernel prints nothing at all, find out how far it got before guessing. Pass
earlycon(for exampleearlycon=pl011,0x9000000on QEMUvirt), which uses a fixed MMIO console before the console driver probes. Without output, halt the core in the debugger: a PC in the kernel’s exception vectors withESR_EL1/ESR_EL2set means the kernel took an exception before its handlers were ready, often an EC 0x00 UNDEF from a missing EL3 enable (17.3). A PC near the image base with the MMU still off usually means a bad DTB pointer inx0or an image that was not cleaned to the PoC. The full crash-decoding workflow is in 18.1.
Checkpoint
Q17.6.1 U-Boot loads Image with its D-cache enabled, invalidates the I-cache, and jumps to the kernel with the MMU and D-cache off. The kernel works on the development board, but on the production SoC, which adds a system-level cache, it crashes randomly in early boot. U-Boot cleans the kernel range with a set/way loop before jumping. What is wrong?
- A. The I-cache must be disabled at kernel entry
- B. The kernel must be entered with the D-cache on when a system cache exists
- C. Set/way maintenance only affects the PE’s local cache hierarchy. Dirty lines can still sit in the system cache, while the kernel’s MMU-off accesses read the stale copy beyond it. The image must be cleaned by VA to the PoC, which the interconnect forwards through the system cache
- D. The DTB is larger than 2 MB
Answer
C. booting.rst says this explicitly: in the presence of a system cache or other coherent masters with caches enabled, cleaning the image to the PoC “will typically require cache maintenance by VA rather than set/way operations”. Set/way is by definition local (8.8). The I-cache may be on or off (A). The D-cache must be off with the MMU off (B). D would break both boards.
Read more: Linux Documentation/arch/arm64/booting.rst, “Caches, MMUs”; Arm ARM (DDI0487), Data cache maintenance by set/way
Q17.6.2 A kernel that runs KVM boots on a new platform, but dmesg shows “CPU: All CPU(s) started at EL1”, and KVM is unavailable. EL2 is implemented. Which handover fault is most likely?
- A. BL33 (or BL31’s entry point information for it) entered the kernel at EL1 instead of EL2, for example because BL33 dropped to EL1 itself or
SPSR_EL3.Mtargets EL1h - B.
SCR_EL3.RW=0 - C.
CNTHCTL_EL2.EL1PCTEN=0 - D. The kernel was entered with the MMU on
Answer
A. Linux can use virtualization only if it is entered at EL2. It is the kernel’s choice to keep EL2 (VHE) or install a stub, so firmware must not decide by dropping to EL1. RW=0 (B) would make the lower ELs AArch32 or make the ERET illegal, not start the kernel at EL1. EL1PCTEN (C) affects counter access at EL1. A kernel entered with the MMU on (D) would most likely crash rather than report its EL.
Read more: Linux Documentation/arch/arm64/booting.rst, “CPU mode”; Arm ARM (DDI0487), SPSR_EL3.M
Q17.6.3 On an SVE-capable platform, Linux boots, but userspace programs sometimes see different maximum SVE vector lengths depending on the CPU they run on, and migrating SVE tasks between CPUs crashes. Firmware sets CPTR_EL3.EZ=1 on every CPU. Which requirement is violated?
- A. SVE must be disabled at EL3 and enabled by the kernel
- B.
ZCR_EL3.LENmust be initialised to the same value on all CPUs. Otherwise EL3 caps the effective vector length differently per CPU, and the kernel’s assumption of a single system-wide maximum fails - C.
CPTR_EL3.TFPmust be 1 when SVE is used - D.
SCR_EL3.EnTP2must be set for SVE
Answer
B. The effective SVE vector length at a lower EL is constrained by ZCR_EL3.LEN. booting.rst therefore requires it to be identical on all CPUs, and similarly ZCR_EL2.LEN when entering at EL1. A contradicts the requirement that EZ be 1. TFP=1 (C) would trap FP and SVE register access entirely. EnTP2 (D) is an SME control.
Read more: Linux Documentation/arch/arm64/booting.rst, SVE requirements; Arm ARM (DDI0487), ZCR_EL3