# coreboot/arm-trusted-firmware architecture

> Architecture diagram of the GitHub repository coreboot/arm-trusted-firmware, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coreboot/arm-trusted-firmware
- Repository: https://github.com/coreboot/arm-trusted-firmware

## Overview

##### Project type and purpose
- This is not an application or web service but a reference firmware implementation (Trusted Firmware-A) for Arm A-Profile processors. It provides the secure-world boot stages and runtime services (EL3 Secure Monitor, secure payloads, PSCI, SMC/SCMI/SDEI interfaces) needed to bootstrap both secure and non-secure software on Armv8-A/Armv7-A systems.

##### Key architectural areas (derived from file tree and README)
- Boot stages (bl1, bl2, bl2u, bl31, bl32)
- Common libraries and utilities (common, lib, libfdt, zlib, compiler-rt)
- Hardware abstraction (drivers/)
- Platform integration (plat/)
- Secure services framework (services/, including PSCI, SPMD, SCMI, SDEI, TBBR)
- Tools and packaging utilities (tools/, fiptool, encrypt_fw, tlc)
- Documentation (docs/)

##### Main components and layers
A. Hardware and Boot ROM
- On-chip ROM / BootROM
- SoC peripherals (GIC, timers, memory controller)
B. BL1 – Initial Boot Loader
- Minimal SRAM code that sets up CPU and loads BL2 from storage
C. BL2 – Secondary Boot Loader
- Platform-agnostic image loading
- Authentication (TBBR/COT)
- Passes control to BL31
D. BL31 – EL3 Secure Monitor
- Implements SMCCC, PSCI, SCMI, SDEI interfaces
- Manages world switches (secure ↔ non-secure)
- Provides runtime services via “services/” modules
E. BL32 – Secure Payload(s)
- Optional Trusted OS or simple service (SP_MIN, TSP, OPTEE, TLKD, Trusty)
- Runs at EL1 in secure world
F. BL33 – Non-secure Payload
- Secondary bootloader or OS (e.g., UEFI, Linux) loaded via PSCI/smccc
G. Common Libraries and Drivers
- Driver framework (drivers/) behind unified IO and platform drivers
- lib/ and common/ for context management, memory management, crypto, FDT handling
H. Platform Adaptation Layer
- plat/ contains code for each SoC/Board (clock init, topology, platform_def.h, FDT fixups)
I. External Tools
- FIP creation (tools/fiptool), encryption (tools/encrypt_fw), certificate creation

##### Relationships and dataflow
- BootROM → BL1 → BL2 → BL31 → {BL32, BL33}
- BL31 exports SMC gateway (SMC invocations) to BL32 and BL33
- PSCI calls from non-secure OS → forwarded by BL31 to platform power drivers
- SCMI messages from EL3 → drivers in BL31 → devices
- SDEI interrupts handled in BL31 → delivered to registered handlers in BL32
- Drivers in BL31/BL1 use common libfdt to parse device-tree (fdts/)
- Platform code in plat/<vendor>/<board> is called from each stage for board-specific init

##### Architectural patterns and principles
- Layered boot stages isolate responsibilities and privileges
- Modular services in BL31 (services/) implement standardized Arm interfaces
- Portable hardware abstraction via drivers/ + common/ + include/
- Platform-specific overrides in plat/ allow reuse of core code
- Build system (Makefile, make_helpers/) orchestrates multicore, multi-stage builds

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    ROM["On-chip BootROM"]:::hardware
    Periph["SoC Peripherals\n(GIC, Timers, Memory Ctrl)"]:::hardware

    %% Boot Stages
    BL1["BL1 Initial Boot Loader"]:::boot
    BL2["BL2 Secondary Boot Loader"]:::boot
    BL31["BL31 Secure Monitor (EL3)"]:::boot
    BL32["BL32 Secure Payload (EL1 Secure)"]:::boot
    BL33["BL33 Non-secure Payload (EL1 Non-secure)"]:::boot

    %% BL31 Services
    subgraph "BL31 Services" 
        PSCI["PSCI Service"]:::service
        SCMI["SCMI Service"]:::service
        SDEI["SDEI Service"]:::service
        CTX["Context Manager"]:::service
    end

    %% Common Libraries and Drivers
    subgraph "Common Libraries & Drivers"
        Common["common/"]:::lib
        CompilerRT["lib/compiler-rt/"]:::lib
        Libfdt["lib/libfdt/"]:::lib
        Zlib["lib/zlib/"]:::lib
        Drivers["drivers/"]:::lib
    end

    %% Platform Adaptation Layer
    Plat["Platform Adaptation Layer\n(plat/)"]:::platform

    %% Tools and Documentation
    subgraph "Tools & Docs"
        FIP["FIP Creation\n(tools/fiptool/)"]:::tools
        ENC["Firmware Encryption\n(tools/encrypt_fw/)"]:::tools
        TLC["Transfer-list Compiler\n(tools/tlc/)"]:::tools
        DOC["Documentation\n(docs/)"]:::docs
    end

    %% Boot flow
    ROM --> BL1 --> BL2 --> BL31 --> BL32
    BL31 --> BL33

    %% Service interfaces
    BL31 --> PSCI
    BL31 --> SCMI
    BL31 --> SDEI
    BL31 --> CTX
    PSCI --> Drivers
    SCMI --> Drivers
    SDEI --> Drivers
    CTX --> Common

    %% Shared libraries usage
    BL1 --> Common
    BL2 --> Common
    BL31 --> Common
    BL32 --> Common
    BL33 --> Common
    BL1 --> Libfdt
    BL2 --> Libfdt
    BL31 --> Libfdt

    %% Platform code invoked
    BL1 --> Plat
    BL2 --> Plat
    BL31 --> Plat
    BL32 --> Plat
    BL33 --> Plat

    %% Tools & Docs usage
    FIP --> BL2
    ENC --> BL2
    TLC --> BL2
    DOC --> ROM

    %% Click Events
    click BL1 "https://github.com/coreboot/arm-trusted-firmware/tree/master/bl1/"
    click BL2 "https://github.com/coreboot/arm-trusted-firmware/tree/master/bl2/"
    click BL31 "https://github.com/coreboot/arm-trusted-firmware/tree/master/bl31/"
    click BL32 "https://github.com/coreboot/arm-trusted-firmware/tree/master/bl32/"
    click Common "https://github.com/coreboot/arm-trusted-firmware/tree/master/common/"
    click CompilerRT "https://github.com/coreboot/arm-trusted-firmware/tree/master/lib/compiler-rt/"
    click Libfdt "https://github.com/coreboot/arm-trusted-firmware/tree/master/lib/libfdt/"
    click Zlib "https://github.com/coreboot/arm-trusted-firmware/tree/master/lib/zlib/"
    click Drivers "https://github.com/coreboot/arm-trusted-firmware/tree/master/drivers/"
    click Plat "https://github.com/coreboot/arm-trusted-firmware/tree/master/plat/"
    click PSCI "https://github.com/coreboot/arm-trusted-firmware/tree/master/services/"
    click SCMI "https://github.com/coreboot/arm-trusted-firmware/tree/master/services/"
    click SDEI "https://github.com/coreboot/arm-trusted-firmware/tree/master/services/"
    click CTX "https://github.com/coreboot/arm-trusted-firmware/tree/master/services/"
    click FIP "https://github.com/coreboot/arm-trusted-firmware/tree/master/tools/fiptool/"
    click ENC "https://github.com/coreboot/arm-trusted-firmware/tree/master/tools/encrypt_fw/"
    click TLC "https://github.com/coreboot/arm-trusted-firmware/tree/master/tools/tlc/"
    click DOC "https://github.com/coreboot/arm-trusted-firmware/tree/master/docs/"

    %% Styles
    classDef hardware fill:#dddddd,stroke:#888888,color:#333333;
    classDef boot fill:#aed6f1,stroke:#2980b9,color:#1b4f72;
    classDef service fill:#a9dfbf,stroke:#27ae60,color:#145a32;
    classDef lib fill:#f9e79f,stroke:#d4ac0d,color:#7d6608;
    classDef platform fill:#f5cba7,stroke:#d35400,color:#6e2c00;
    classDef tools fill:#d2b4de,stroke:#8e44ad,color:#4a235a;
    classDef docs fill:#f0f3f4,stroke:#abb2b9,color:#566573;
```
