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

4.6 TF-M: the Secure side, compared with OP-TEE + TF-A

Trusted Firmware-M (TF-M) is the reference Secure Processing Environment (SPE) for Armv8-M. It implements PSA Firmware Framework-M (FF-M), which defines these pieces:

  • SPM (Secure Partition Manager): TF-M’s core. It runs privileged in Secure state and owns partition isolation (Secure MPU, and peripheral and memory protection controllers), the scheduling and messaging of IPC-model partitions, and interrupt delivery to partitions.
  • Secure partitions: isolated services described by a manifest. They divide into the PSA Root of Trust (e.g. Crypto, Internal Trusted Storage, Initial Attestation, Platform) and the Application RoT (e.g. Protected Storage). Partitions use the IPC model (own thread, psa_connect/psa_call messages, signals) or, since FF-M 1.1, the SFN (Secure Function) model.
  • Isolation levels:
    • Level 1: the SPE is isolated from the NSPE only.
    • Level 2: also isolates the PSA RoT from the Application RoT. In TF-M, ARoT partitions run unprivileged behind the Secure MPU.
    • Level 3: also isolates every partition from every other partition.
  • APIs: PSA Crypto, PSA Internal Trusted Storage and Protected Storage, PSA Initial Attestation and Firmware Update, called from the Non-secure side.

The Non-secure interface. Non-secure code (for example a FreeRTOS or Zephyr application) calls the PSA client APIs. On a single-core TrustZone system these go through TF-M’s NS interface layer to an SG veneer in NSC memory, and the SPM routes the request to the target partition. Multi-core platforms where the NSPE runs on a separate core use a mailbox instead of veneers. Secure boot is normally TF-M’s BL2, which is based on MCUboot.

Mapping to OP-TEE + TF-A. On A-profile, BL31 at EL3 is the secure monitor: it handles SMC, switches worlds and saves context. OP-TEE OS is the S-EL1 trusted OS, and TAs are its isolated services. On Armv8-M, no software plays the secure monitor role. The PE’s hardware does it: SG and NSC entry, BXNS/BLXNS, FNC_RETURN, exception stacking with the additional state context, and banked registers. TF-M’s SPM corresponds to OP-TEE OS, and partitions correspond to TAs. TF-M’s BL2 roughly plays the role of TF-A’s BL2. Note that the A-profile “SPM” (Hafnium SPMC, under FF-A) is a different framework, despite the shared name.

Coming from A-profile: Your OP-TEE/TF-A model maps across with one big change: the EL3 dispatcher (SMC handling, opteed SPD, context save) disappears into hardware. Everything you would review in BL31’s world-switch code becomes CMSE veneer, register-clearing and stack-sealing review.

Checkpoint

Q4.6.1 In a TF-M system on an Armv8-M Mainline core, which component plays the role that TF-A BL31 plays for OP-TEE on A-profile (world switch and state preservation)?

  • A. TF-M’s SPM, running in Secure Handler mode as the monitor
  • B. A Secure SVC handler that every Non-secure call must trap into
  • C. None in software: the Security Extension hardware switches state (SG/BXNS/BLXNS, FNC_RETURN, exception stacking) and banked registers preserve per-state context
  • D. TF-M’s BL2 bootloader, which stays resident as the dispatcher
Answer

C. Armv8-M has no monitor: crossings are hardware-checked branches and exception mechanisms, and the state that needs separating is banked. TF-M’s SPM corresponds to OP-TEE OS, the trusted kernel that isolates and schedules services. Calling the SPM the monitor is the most tempting mapping, but the SPM does not perform the world switch.

Read more: TF-M documentation (SPM design); Armv8-M ARM (DDI0553), Security state transitions

Q4.6.2 What does PSA FF-M isolation Level 2 add on top of Level 1?

  • A. Isolation of the PSA Root of Trust (SPM and PSA RoT partitions) from Application RoT partitions, typically by running ARoT partitions unprivileged behind the Secure MPU
  • B. Isolation of each Secure partition from every other Secure partition
  • C. Isolation of the SPE from the NSPE using the SAU
  • D. Encryption of Secure RAM with keys from Initial Attestation
Answer

A. Level 1 separates only Secure from Non-secure. Level 2 also protects the PSA RoT from the Application RoT. Level 3 goes further and isolates every partition from every other. The “each partition from every other” option is the tempting answer, but it describes Level 3.

Read more: Arm PSA Firmware Framework-M (FF-M), isolation levels

Q4.6.3 A FreeRTOS task on the Non-secure side calls psa_cipher_encrypt() on a single-core Armv8-M TF-M system that uses the IPC model. Which sequence is correct?

  • A. The task executes SMC, and the PE vectors to the Secure SPM at a fixed address
  • B. The NS PSA client library goes through TF-M’s NS interface to an SG veneer in NSC memory, which enters Secure state, and the SPM delivers the request as a message to the Crypto partition
  • C. The task writes a request to a shared mailbox, and the Secure core polls it
  • D. The task triggers a Secure SVC directly, and the Crypto partition runs in Non-secure Handler mode
Answer

B. On single-core TrustZone-M systems, Non-secure requests enter through SG veneers placed in NSC memory, and the SPM then routes the request to the target partition (as a message in the IPC model). SMC does not exist on M-profile. The mailbox path is tempting but applies to TF-M’s multi-core configurations, where the NSPE runs on a different core from the SPE.

Read more: TF-M documentation (NS interface, IPC model); PSA FF-M