</>EmbeddedInterview

Explain ARM Trusted Firmware (TF-A), including BL1, BL2, BL31, BL32 and BL33.

MediumARM Architecture

Trusted Firmware-A (TF-A) is an open-source implementation of secure boot firmware and runtime firmware for Arm A-profile processors, such as Cortex-A53, Cortex-A55, Cortex-A72 and Cortex-A78.

It is responsible for:

  • Secure boot and authentication of firmware images when Trusted Board Boot is enabled.
  • Initializing essential hardware.
  • Configuring ARM TrustZone.
  • Switching between Secure and Non-secure worlds.
  • Handling Secure Monitor Calls (SMC).
  • Providing power management services through PSCI.

1. Complete TF-A boot flow

Power ON / ResetCPU starts executingBL1 — Boot ROMSecure EL3BL2 — Trusted Boot LoaderSecure EL1BL31 — Runtime FirmwareEL3 / Secure MonitorBL32 (Optional)OP-TEE / Trusted OSSecure EL1BL33U-Boot / UEFINon-secure EL2 / EL1Linux / AndroidNormal WorldSecure worldNormal world
Stage Name Typical exception level
BL1 Trusted ROM Firmware EL3
BL2 Trusted Boot Firmware Secure EL1
BL31 EL3 Runtime Firmware EL3
BL32 Secure Payload / Trusted OS Secure EL1
BL33 Non-trusted Boot Firmware Non-secure EL2/EL1

This is the conventional AArch64 TF-A boot architecture. Actual boot stages may differ depending on the SoC.

2. BL1 – Boot Loader Stage 1

BL1 is the first trusted firmware stage in the reference TF-A boot flow. It normally resides in ROM.

Responsibilities:

  • Execute immediately after CPU reset.
  • Initialize stack, exception vectors and essential CPU registers.
  • Configure initial MMU and cache settings.
  • Initialize the boot storage interface.
  • Load BL2 into trusted SRAM.
  • Authenticate BL2 if secure boot is enabled.
  • Transfer execution to BL2.

Important source files:

bl1/aarch64/bl1_entrypoint.S
bl1/bl1_main.c

Function flow:

bl1_entrypoint()
    └── bl1_main()
          └── bl1_load_bl2()
                └── load_auth_image()

BL1 normally transfers control from EL3 to Secure EL1 using the ERET instruction.

3. BL2 – Trusted Boot Firmware

BL2 is responsible for loading the remaining firmware images from storage into their respective memory regions.

Responsibilities:

  • Initialize DDR, if not already initialized by earlier firmware.
  • Initialize platform-specific hardware.
  • Load and authenticate BL31.
  • Load and authenticate BL32, if present.
  • Load and authenticate BL33.
  • Prepare entry-point addresses and processor state for the next stages.

Typically, images are packaged inside a Firmware Image Package (FIP).

FIP (Storage)BL31 binaryBL32 binaryBL33 binaryCertificatesBL2Load / verifyBL31Trusted memoryBL32Secure memoryBL33Non-secure memory

Important source files:

bl2/aarch64/bl2_entrypoint.S
bl2/bl2_main.c
bl2/bl2_image_load_v2.c

Function flow:

bl2_entrypoint()
    └── bl2_main()
          ├── bl2_platform_setup()
          └── bl2_load_images()
                └── load_auth_image()

In the conventional Secure EL1 boot configuration, BL2 executes an SMC instruction to return to BL1, which then transfers control to BL31 at EL3. Some platforms execute BL2 directly at EL3 instead.

4. BL31 – EL3 Runtime Firmware

BL31 is the most important runtime component of TF-A. Unlike the earlier boot stages, it remains available even after Linux boots.

Responsibilities:

  • Implement the Secure Monitor.
  • Manage Secure and Non-secure world transitions.
  • Handle Secure Monitor Calls.
  • Initialize PSCI power management services.
  • Configure security-related CPU registers.
  • Initialize BL32, if present.
  • Transfer control to BL33.
  • Handle CPU hotplug, suspend, resume and system reset.

Important source files:

bl31/aarch64/bl31_entrypoint.S
bl31/bl31_main.c
bl31/aarch64/runtime_exceptions.S
lib/psci/
lib/el3_runtime/

Function flow:

bl31_entrypoint()
    └── bl31_main()
          ├── bl31_platform_setup()
          ├── runtime_svc_init()
          └── bl31_prepare_next_image_entry()

Before transferring control to BL33, BL31 prepares the following ARM registers:

Register Purpose
SCR_EL3 Security state and lower-level execution configuration
SPSR_EL3 Target exception level and processor state
ELR_EL3 Target instruction address
VBAR_EL3 EL3 exception vector table address

Finally, it executes:

ERET

The CPU starts executing BL33 in the Non-secure world, normally at EL2 if available, otherwise EL1.

5. BL32 – Secure Payload

BL32 is an optional secure firmware image, commonly a Trusted Execution Environment (TEE), such as OP-TEE.

It typically executes at Secure EL1.

Responsibilities:

  • Secure key management.
  • Cryptographic operations.
  • Secure storage.
  • Trusted application execution.
  • Protection of sensitive information.
  • Secure authentication.
Secure WorldNormal WorldTrusted ApplicationSecure EL0User ApplicationNon-secure EL0OP-TEE (BL32)Secure EL1Linux KernelNon-secure EL1SMCBL31 — Secure MonitorEL3

For example, when a Linux application requests a secure cryptographic operation:

User application
    ↓
Linux OP-TEE driver
    ↓
SMC instruction
    ↓
BL31 Secure Monitor (EL3)
    ↓
OP-TEE (Secure EL1)
    ↓
Trusted application
    ↓
Result returned to Linux

BL31 initializes BL32 before starting BL33 in the conventional boot flow.

6. BL33 – Non-trusted Firmware

BL33 is normally U-Boot or UEFI firmware.

Here, non-trusted means that it executes outside the TrustZone Secure world. It does not mean that its image cannot be authenticated.

Responsibilities:

  • Initialize remaining hardware.
  • Initialize storage, USB, Ethernet and other peripherals.
  • Load the Linux kernel.
  • Load DTB and optional initramfs.
  • Pass boot arguments.
  • Transfer control to the Linux kernel.

For U-Boot, a typical function flow is:

_start
    └── board_init_f()
          └── Relocation
                └── board_init_r()
                      └── main_loop()
                            └── boot command
                                  └── Linux kernel

7. How BL31 works after Linux boots

Consider Linux starting another CPU core using PSCI.

Linux issues the PSCI CPU_ON request using an SMC instruction when the platform uses the SMC conduit.

SMC #0

At the hardware level:

  1. CPU takes a synchronous exception to EL3.
  2. The return address is saved in ELR_EL3.
  3. Processor state is saved in SPSR_EL3.
  4. CPU jumps to the exception vector configured in VBAR_EL3.
  5. BL31 saves the required register context.
  6. The SMC handler identifies the requested PSCI function.
  7. PSCI and platform-specific power controller code power on the requested CPU.
  8. BL31 restores the caller's context.
  9. ERET returns execution to Linux.
Linux kernel
    └── PSCI CPU_ON
          └── SMC #0
                └── EL3 exception handler
                      └── psci_smc_handler()
                            └── psci_cpu_on()
                                  └── Platform power controller

This is why BL31 remains necessary even after the boot process completes.

8. Secure boot chain of trust

When Trusted Board Boot is enabled, firmware authentication establishes a chain of trust.

Hardware Root of TrustTrusted root public key or hashBL1Authenticates BL2BL2Authenticates subsequent firmwareBL31BL32BL33

The root key or its hash may be provisioned in OTP memory or eFuse, depending on the platform.

Firmware certificates, digital signatures and cryptographic hashes are used to verify the authenticity and integrity of subsequent images. Authentication failure normally prevents the affected image from executing.

9. Real-world example: NXP i.MX8

For i.MX8 QM/QXP, the simplified application processor boot flow is:

Boot ROM / SoC boot firmware
    ↓
BL31 (ARM Trusted Firmware)
    ↓
BL33 (U-Boot)
    ↓
Linux kernel
    ↓
Root filesystem / init
    ↓
User applications

For i.MX8M, a common boot flow is:

Boot ROM
    ↓
U-Boot SPL
    ↓
DDR initialization
    ↓
BL31 (ARM Trusted Firmware)
    ↓
BL33 (U-Boot)
    ↓
Linux kernel

Not every platform uses TF-A's own BL1 and BL2. SoC vendor firmware or U-Boot SPL can perform the equivalent responsibilities.

10. Important interview points

Question Answer
Which stage executes first? BL1 in the reference architecture
Which stage loads other firmware? BL2
Which stage implements Secure Monitor? BL31
Which stage remains active after Linux boots? BL31
Which stage implements OP-TEE? BL32
Which stage is U-Boot? BL33
Is BL32 mandatory? No
Which instruction requests an EL3 secure monitor service? SMC
Which instruction returns from EL3? ERET
Which register controls the lower-level security state? SCR_EL3
Which register contains the exception return address? ELR_EL3
Which register saves the previous processor state? SPSR_EL3
Which register holds the EL3 vector table address? VBAR_EL3
Who handles PSCI requests? BL31

Easy way to remember:

  • BL1: Start and verify.
  • BL2: Load and authenticate.
  • BL31: Monitor and manage.
  • BL32: Secure execution.
  • BL33: Boot the operating system.

Official reference: Trusted Firmware-A Firmware Design.