Table of Contents

Advertisement

Quick Links

Introduction
This document describes how to get started with the STM32CubeU5 TFM (trusted firmware for Arm
delivered as part of the
STM32CubeU5
The STM32CubeU5 TFM application provides a root of trust solution, including Secure Boot and Secure Firmware Update
functionalities. This solution is used before executing the application. It provides a set of secure services that are isolated from
the nonsecure application, but can be used by the nonsecure application at runtime. The STM32CubeU5 TFM application is
based on the open-source TF‑M reference implementation, ported onto
STM32U5 in this document). This brings the benefit of STM32U5 hardware security features such as:
®
®
‑M33 TrustZone
Arm
Cortex
®
TrustZone
-aware peripherals
Memory protections (HDP, WRP)
Enhanced life-cycle scheme (RDP)
Additionally, security can be augmented with the addition of a secure element, the
STSAFE in this document).
The secure services are implemented as upgradeable code that provides a set of services available at runtime for the
nonsecure application. It also manages critical assets isolated from the nonsecure application. The nonsecure application
cannot directly access any of the critical assets, but can call secure services that use the critical assets:
Secure Boot (root of trust services) is a piece of immutable code that is always executed after a system reset. It checks
the STM32U5 static protections, activates STM32U5 runtime protections, and then verifies the authenticity and integrity of
the installed firmware before every execution. This ensures that invalid or malicious code cannot be run.
The Secure Firmware Update application is a piece of immutable code. It detects that a new firmware image is available,
then checks its authenticity, and the integrity of the code before installing it. The firmware update can be done on the
single firmware image, including both secure and nonsecure parts of the firmware image. Alternatively, it can be done on
the secure part of the firmware image, on the nonsecure part of the firmware image, or on both independently. The
firmware update can also be done either in overwrite mode or in swap mode. Firmware can be received clear or
encrypted.
The secure services are upgradeable code implementing a set of services managing critical assets that are isolated from the
nonsecure application. This means that the nonsecure application cannot directly access any of the critical assets, but can only
use secure services that use the critical assets:
Crypto: secure cryptographic services, based on opaque key APIs
Protected storage: protects data confidentiality/authenticity/integrity
Internal trusted storage: protects data confidentiality/authenticity/integrity in internal flash memory (the most secure
storage space for microcontrollers)
Attestation: proves product identity via an entity attestation token
The TFM application presented in this document is a complete implementation of [TF-M]. A second application implementing
only the Secure Boot and Secure Firmware Update functionalities of [TF-M], named STM32CubeU5 SBSFU, is also available in
the
STM32CubeU5
MCU Package. For further information on the SBSFU application, refer to [AN5447].
The first sections of this document (sections
document (sections
7
to 12) present TF‑M ported onto the STM32U5 microcontroller and integrated in the
Package. STM32CubeU5 TFM application and SBSFU application examples are provided for the
Refer to
[TF-M]
for more information about the open-source TF‑M reference implementation.
UM2851 - Rev 4 - October 2023
For further information contact your local STMicroelectronics sales office.
Getting started with STM32CubeU5 TFM application
MCU Package.
®
and memory protection unit (MPU)
4
to 6) present the open-source TF‑M part (v1.3.0). The last sections of this
®
STM32U5 series
microcontrollers (referred to as
STSAFE-A110
microcontroller (referred to as
B-U585I-IOT02A
UM2851
User manual
‑M) application,
®
Cortex
STM32CubeU5
MCU
board.
www.st.com

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM32CubeU5 TFM and is the answer not in the manual?

Questions and answers

Summary of Contents for ST STM32CubeU5 TFM

  • Page 1 This solution is used before executing the application. It provides a set of secure services that are isolated from the nonsecure application, but can be used by the nonsecure application at runtime. The STM32CubeU5 TFM application is based on the open-source TF‑M reference implementation, ported onto...
  • Page 2: General Information

    UM2851 General information General information ® The STM32CubeU5 TFM application runs on STM32U5 series 32-bit microcontrollers based on the Arm ® ‑M33 processor with Arm ® ® Cortex TrustZone Note: Arm and TrustZone are registered trademarks of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
  • Page 3 UM2851 Acronyms Acronym Description Nonsecure processing environment (PSA term). In TF‑M, this means nonsecure domain typically running an NSPE operating system using services provided by TF‑M. Memory protection unit. OAEP Optimal asymmetric encryption padding is a padding scheme often used together with RSA encryption. Protected storage service.
  • Page 4: Documents And Open-Source Software Resources

    CBOR object signing and encryption (COSE) - tools.ietf.org/html/rfc8152 1. Available on www.st.com. Contact STMicroelectronics when more information is needed. 2. This URL belongs to a third party. It is active at document publication. However, STMicroelectronics shall not be liable for any change, move, or inactivation of the URL or the referenced material.
  • Page 5: Stm32Cube Overview

    UM2851 STM32Cube overview STM32Cube overview STM32Cube is an STMicroelectronics original initiative to improve designer productivity significantly by reducing development effort, time, and cost. STM32Cube covers the whole STM32 portfolio. STM32Cube includes: • A set of user-friendly software development tools to cover project development from conception to realization, among which are: –...
  • Page 6: Arm® Trusted Firmware-M (Tf-M) Introduction

    UM2851 Arm® Trusted Firmware‑M (TF‑M) introduction ® Trusted Firmware‑M (TF‑M) introduction TF‑M (refer to [TF-M]) is an Arm Limited driven open-source software framework providing a reference ‑M33 (TrustZone ® ® ® implementation of the PSA standard on the Arm Cortex ) processor: •...
  • Page 7: Secure Boot And Secure Firmware Update Services (Psa Immutable Rot)

    UM2851 Secure Boot and Secure Firmware Update services (PSA immutable RoT) Secure Boot and Secure Firmware Update services (PSA immutable RoT) Product security introduction A device deployed in the field operates in an untrusted environment, and is therefore subject to threats and attacks.
  • Page 8: Secure Firmware Update

    UM2851 Secure Firmware Update Secure Firmware Update Secure Firmware Update provides a secure implementation of in-field firmware updates, enabling the download of new firmware images to a device in a secure way. As shown in Figure 3, two entities are typically involved in a firmware update process: •...
  • Page 9: Cryptography Operations

    UM2851 Cryptography operations Cryptography operations The TFM_SBSFU_Boot application example is delivered with configurable cryptographic schemes (solution for firmware authentication and firmware encryption): • RSA-2048 asymmetric cryptography for image authenticity verification, AES-CTR-128 symmetric cryptography with key RSA-OAEP encrypted for image confidentiality, and SHA256 cryptography for image integrity check.
  • Page 10: Secure Services At Runtime

    UM2851 Secure services at runtime Secure services at runtime The secure services at runtime are a set of services that can be called at a nonsecure application runtime. They manage critical assets that are isolated from the nonsecure application. A nonsecure application cannot access directly to any of the critical assets but can only use the secure services that use the critical assets.
  • Page 11: Secure Cryptographic Service

    UM2851 Secure cryptographic service The design addresses the following high-level requirements as well: • Confidentiality: Resistance to unauthorized accesses through hardware/software attacks, by means of the hardware isolation of the flash memory access domain • Access authentication: Mechanism to establish the requester’s identity (a nonsecure entity, a secure entity, or a remote server).
  • Page 12: Protection Measures And Security Strategy

    To resist possible attacks, a set of measures and system-level strategy are needed for protecting critical operations, sensitive data (such as a secret key), and the execution flow. The STM32CubeU5 TFM example uses a security strategy based on the following concepts: •...
  • Page 13: Protections Against Outer Attacks

    UM2851 Protections against outer attacks Protections against outer attacks Outer attacks refer to attacks triggered by external tools such as debuggers or probes, trying to access the device. In the TFM_SBSFU_Boot application example, device life cycle (managed through RDP option bytes), boot lock, protected SRAM2 protections, and antitamper are used to protect the product against outer attacks: •...
  • Page 14 UM2851 Protections against inner attacks In the TFM application example, the system has been defined to put in place different protected execution environments according to the product execution states: • System state: execution of the TFM_SBSFU_Boot application (application executed after product reset) –...
  • Page 15: Figure 5. System Protection Overview

    UM2851 Protections against inner attacks Figure 5. System protection overview Refer to Memory protections for more details on memory protections implementation. UM2851 - Rev 4 page 15/117...
  • Page 16: Package Description

    UM2851 Package description Package description STM32CubeU5 MCU Package proposes two different examples of applications, based on the TF‑M reference implementation. • TFM: application with full TF‑M services. • SBSFU: application with only the Secure Boot and Secure Firmware Update services of the TF‑M. This document focuses on the TFM application only.
  • Page 17: Table 4. Features Configurability In Tf-M-Based Examples In The Stm32Cubeu5 Mcu Package

    UM2851 TFM application description • Configurable firmware image upgrade strategy, for primary and secondary slots mode: – Overwrite strategy, for which the image in the secondary slot overwrites the image in the primary slot. – Swap strategy, for which the image in primary and secondary slots are swapped. After the swap, the new image in the primary slot must be confirmed by the user application, else, at the next boot, the images are swapped back.
  • Page 18: Tfm Application Architecture Description

    UM2851 TFM application architecture description SBSFU_Boot TFM_SBSFU_Boot Feature (B-U585I-IOT02A) (B-U585I-IOT02A) None None Image encryption AES-CTR AES-CTR Software Software Cryptography modes Mix of hardware and software Mix of hardware and software Primary only slot Primary only slot Slot modes Primary and secondary slots Primary and secondary slots 1 image 1 image...
  • Page 19: Hardware Abstraction Layer (Hal) And Low-Layer (Ll)

    UM2851 TFM application architecture description • BSP driver It allows linking the component driver to a specific board and provides a set of user-friendly APIs. The API naming rule is BSP_FUNCT_Action(). Example: BSP_LED_Init(), BSP_LED_On() The BSP is based on a modular architecture that allows an easy porting on any hardware by just implementing the low-level routines.
  • Page 20: Stsafe

    Each secure element comes with a default personalization profile (refer to [AN5435] for further details): • a preprovisioned device certificate signed with ST root CA (self-signed CA certificate) in the STMicroelectronics factory • a unique asymmetric key pair (private key and public key) •...
  • Page 21 UM2851 Memory layout • SCRATCH region: region used by TFM_SBSFU_Boot to store the image data temporarily during the image swap process (not used in overwrite-only mode). • Integrator personalized data region: region to personalize TF‑M data specific to the integrator or specific to the STM32U5 microcontroller (the keys used by the SBSFU application, and the keys and information used by the TFM secure application).
  • Page 22: Figure 7. Stm32U5 Tfm Flash Memory Layout (Default Configuration)

    UM2851 Memory layout In the TFM application default configuration, the flash memory layout is described in Figure Figure 7. STM32U5 TFM flash memory layout (default configuration) Legend: Nonsecure local loader (24 Kbytes) Nonsecure area FLASH_LOADER_AREA_OFFSET Nonsecure area Unused (176 Kbytes / 1136 Kbytes Nonsecure area Secure area...
  • Page 23: Figure 8. Stm32U5 Tfm Flash Memory Layout (Primary Only Slot)

    UM2851 Memory layout In the case of the primary only slot configuration, the secondary slot areas 2 and 3 (application code) are not present and the secondary slot areas 6 and 7 (data code) are not present. Additionally, a local loader secure region is introduced, to permit the download of a secure image in primary slot area 0 (secure area).
  • Page 24: Figure 9. Stm32U5 Tfm Flash Memory Layout (One Image)

    UM2851 Memory layout In the case of one image configuration, the primary slot areas 1 and 3 are not present. Slot areas 0 and 2 receive the assembled image with secure and nonsecure binaries. In this configuration, the flash memory layout is described in Figure Figure 9.
  • Page 25: Figure 10. Stm32U5 Tfm Flash Memory Layout (Swap Mode)

    UM2851 Memory layout In the case of the swap mode strategy, a SCRATCH region is introduced to permit the swap of images. In this configuration, the flash memory layout is described in Figure Figure 10. STM32U5 TFM flash memory layout (swap mode) Legend: Nonsecure local loader (24 Kbytes) Nonsecure area...
  • Page 26: Figure 11. New Firmware Download And Install Procedure For Overwrite Mode, Two Firmware Images Configuration, And For

    UM2851 Memory layout Figure 11. New firmware download and install procedure for overwrite mode, two firmware images configuration, and for primary and secondary slot configuration Legend: Nonsecure image #B1 Nonsecure image #B2 TFM loader or Secure image #A1 TFM nonsecure appli TFM_SBSFU_Boot Initial state downloads new images...
  • Page 27: Figure 13. New Firmware Download And Install Procedure For Overwrite Mode, One Firmware Image Configuration And For

    UM2851 Memory layout Figure 13. New firmware download and install procedure for overwrite mode, one firmware image configuration and for primary and secondary slot configuration Legend: TFM loader or Image #1 (secure and nonsecure) TFM nonsecure appli TFM_SBSFU_Boot Image #2 (secure and nonsecure) Initial state downloads new images installs new images...
  • Page 28: Figure 15. New Firmware Download And Install Procedure For Swap Mode, With Images Confirmation

    UM2851 Memory layout Figure 15. New firmware download and install procedure for swap mode, with images confirmation Legend: Nonsecure image #B1 Secure image #A1 Nonsecure image #B2 Secure image #A2 TFM loader or TFM_SBSFU_Boot TFM nonsecure appli TFM_SBSFU_Boot TFM nonsecure appli updates versions downloads new images installs new images...
  • Page 29: Figure 17. Firmware Image And Slot Area

    UM2851 Memory layout The image slots (secure/non-secure and primary/secondary image slots) contain signed images. A signed image consists in a binary encapsulated by a header (1 Kbyte) and TLV (type-length-value) records containing image metadata (< 1 Kbyte). To trigger an image installation request, a magic data must be written at the very end position in the image slot (by the application in charge of the download).
  • Page 30: Sram Layout

    Memory layout 8.3.2 SRAM layout The STM32CubeU5 TFM application relies on a dynamic SRAM layout: the SRAM layout is redefined between the TFM_SBSFU_Boot execution and application execution. The SRAM layout defines the following regions: • TFM_SBSFU_Boot shared area: region where TFM_SBSFU_Boot stores the secure data needed by the...
  • Page 31: Folder Structure

    UM2851 Folder structure Figure 19. STM32U5 user SRAM mapping (2 of 2) Legend: Nonsecure area Secure area 2-Mbyte flash memory devices 4-Mbyte flash memory devices SRAM 512-Kbyte flash memory devices 4-Mbyte flash memory STM32U5Fxxx/Gxxx devices TFM_Loader execution TFM_Loader execution (primary and secondary slots) (primary slot only) SRAM 6 SRAM 6...
  • Page 32: Figure 21. Projects File Structure (2 Of 3)

    UM2851 Folder structure Figure 21. Projects file structure (2 of 3) SBSFU application directory Memory mapping shared between SBSFU_Boot, SBSFU_Appli, and SBSFU_Loader applications Nonsecure application (user application example) Secure application (“secure GPIO toggle” service example) Secure and nonsecure application implementation information Secure Boot and Secure Firmware Update application Secure Boot and Secure Firmware Update implementation information Loader application (Ymodem loader application example)
  • Page 33: Apis

    UM2851 APIs Figure 22. Projects file structure (3 of 3) TFM application directory Memory mapping shared between TFM_SBSFU_Boot, TFM_Appli, and TFM_Loader applications Nonsecure application Secure application (such as TFM core or TFM secure services) Secure and nonsecure application implementation information Loader application (Ymodem loader application example) Nonsecure part of the loader application Secure part of the loader application...
  • Page 34: Hardware And Software Environment Setup

    This section describes the hardware and software setup procedures. Hardware setup To set up the hardware environment, connect the ST-LINK USB port of the development board to a personal computer via a USB cable. This connection with the PC allows the user to: •...
  • Page 35: Software Setup

    STM32CubeProgrammer is delivered in GUI (graphical user interface) and CLI (command-line interface) versions. Refer to the STM32CubeProgrammer (STM32CubeProg) software tool on www.st.com. 9.2.4 Terminal emulator A terminal emulator software is needed to run the application.
  • Page 36: Installation Procedure

    UM2851 Installation procedure Installation procedure To get a complete installation with security fully activated, the STM32U5 product preparation must be done in four steps: • Step 1: Software compilation (refer to Section 10.1) • Step 2: STM32U5 device initialization (refer to Section 10.2) •...
  • Page 37: Application Compilation Overview

    10.1.1 Application compilation overview Figure 23. Compilation process overview Legend: Step 1.1: compilation output Integrated tools Step 1.2: compilation output (primary slot) Step 1.2: compilation output (secondary slot) script Step 1.3: compilation output (primary slot) Generates Input for Step 1.3: compilation output (secondary slot) Local loader Placed in (initial installation) Steps 1.4 and 1.5: compilation output...
  • Page 38: Application Compilation Steps

    UM2851 10.1.2 Application compilation steps Build the TFM-related projects provided in the STM32CubeU5 MCU Package strictly following the order described in the six steps below. Step 1.1: build the TFM_SBSFU_Boot application The TFM_SBSFU_Boot project is in: \Projects\B-U585I-IOT02A\Applications\TFM\TFM_SBSFU_Boot\ It can be built in the development mode or in the production mode. The build configuration mode can be selected via the project compile switch TFM_DEV_MODE (managed as a preprocessor symbol of the TFM_SBSFU_Boot project): •...
  • Page 39 UM2851 Protections can be disabled with the following flags: /* Static protections */ #define TFM_WRP_PROTECT_ENABLE /*!< Write Protection */ #define TFM_HDP_PROTECT_ENABLE /*!< HDP protection */ #define TFM_SECURE_USER_SRAM2_ERASE_AT_RESET /*!< SRAM2 clear at Reset */ #ifdef TFM_DEV_MODE #define TFM_OB_RDP_LEVEL_VALUE OB_RDP_LEVEL_1 /*!< RDP level */ #else #define TFM_OB_RDP_LEVEL_VALUE OB_RDP_LEVEL_2 /*!<...
  • Page 40 UM2851 Additionally, by means of the postbuild command integrated in the IDE project, it also produces the following application images: • The clear TFM secure signed application image for initial installation in TFM_Appli\Binary\tfm_s_app_init.bin • The encrypted TFM secure signed application image for download in TFM_Appli\Binary\tfm_s_app_enc_sign.bin •...
  • Page 41: Stm32U5 Device Initialization

    UM2851 STM32U5 device initialization Step 1.5: build the TFM_Loader nonsecure application The TFM_Loader nonsecure project is in: \Projects\B-U585I-IOT02A\Applications\TFM\TFM_Loader. Build the TFM_Loader nonsecure project, using the selected IDE. This step creates the TFM_Loader nonsecure binary. Check that the binary is correctly created at this location: •...
  • Page 42: Figure 24. Stm32Cubeprogrammer Connection Menu

    UM2851 STM32U5 device initialization To make the device initialization procedure easier, execute an automatic script relying on the STM32CubeProgrammer CLI in the STM32CubeU5 MCU Package: • EWARM: Projects\B-U585I-IOT02A\Applications\TFM\TFM_SBSFU_Boot\EWARM\regressio n.bat • MDK-ARM: Projects\B-U585I-IOT02A\Applications\TFM\TFM_SBSFU_Boot\MDK-ARM\regres sion.bat • STM32CubeIDE: Projects\B-U585I-IOT02A\Applications\TFM\TFM_SBSFU_Boot\STM32CubeI DE\regression.sh When using this automatic script, the user must check that there is no error reported during the script execution. As an alternative, it is possible to initialize and verify manually the option bytes configuration by means of the STM32CubeProgrammer GUI through the steps below.
  • Page 43: Figure 25. Stm32Cubeprogrammer Option Bytes Screen (Read Out Protection)

    UM2851 STM32U5 device initialization Step 2.2 - Option bytes settings: menu Option bytes/User Configuration The following option bytes values must be set: • RDP level 0 • SWAP_BANK: unchecked (bank1 and bank2 are not swapped) • DBANK: checked (dual-bank mode with 64-bit data) •...
  • Page 44: Figure 26. Stm32Cubeprogrammer Option Bytes Screen (User Configuration - Part 1)

    UM2851 STM32U5 device initialization Figure 26. STM32CubeProgrammer Option bytes screen (User Configuration - part 1) Figure 27. STM32CubeProgrammer Option bytes screen (User Configuration - part 2) Figure 28. STM32CubeProgrammer Option bytes screen (Boot Configuration) UM2851 - Rev 4 page 44/117...
  • Page 45: Figure 29. Stm32Cubeprogrammer Option Bytes Screen (Secure Area 1)

    UM2851 STM32U5 device initialization Figure 29. STM32CubeProgrammer Option bytes screen (Secure Area 1) Figure 30. STM32CubeProgrammer Option bytes screen (Write Protection 1) UM2851 - Rev 4 page 45/117...
  • Page 46: Figure 31. Stm32Cubeprogrammer Option Bytes Screen (Secure Area 2)

    UM2851 STM32U5 device initialization Figure 31. STM32CubeProgrammer Option bytes screen (Secure Area 2) Figure 32. STM32CubeProgrammer Option bytes screen (Write Protection 2) Step 2.3 - Check OEM2 password provisioning state The OEM2LOCK option bit is set in FLASH_NSSR after having provisioned an OEM2 password. If a password is already provisioned other than the default one proposed in the regression script, apply one of the two following solutions: •...
  • Page 47: Software Programming Into Stm32U5 Internal Flash Memory

    UM2851 Software programming into STM32U5 internal flash memory Figure 33. STM32CubeProgrammer flash memory nonsecure status register screen (OEM2LOCK) Refer to [AN5347] for password provisioning and clearing methods. Step 2.4 - Disconnect Figure 34. STM32CubeProgrammer disconnect 10.3 Software programming into STM32U5 internal flash memory To make the programming of the generated binaries in internal flash memory easier, execute the automatic script relying on the STM32CubeProgrammer (STM32CubeProg) CLI in the STM32CubeU5...
  • Page 48: Configuring Stm32U5 Static Security Protections

    UM2851 Configuring STM32U5 static security protections The script programs all the generated binaries/images into the flash memory. Data format (clear or encrypted) and flash memory location depend on the system configuration used. The script is dynamically updated during the postbuild of TFM_SBSFU_Boot compilation (see Section 10.1 Step 2.1), according to the flash memory layout and to the application configuration.
  • Page 49: Figure 36. Stm32Cubeprogrammer Option Bytes Screen (Boot Configuration)

    UM2851 Configuring STM32U5 static security protections Step 4.2 - Option bytes settings: menu Option bytes / User Configuration The following option byte values have been set first by the hardening script, according to flash memory layout and application configuration, the protection settings can be verified manually by means of the STM32CubeProgrammer (STM32CubeProg) GUI: •...
  • Page 50: Figure 38. Stm32Cubeprogrammer Option Bytes Screen (Write Protection 1)

    UM2851 Configuring STM32U5 static security protections Figure 38. STM32CubeProgrammer option bytes screen (Write Protection 1) Figure 39. STM32CubeProgrammer option bytes screen (Secure Area 2) UM2851 - Rev 4 page 50/117...
  • Page 51: Figure 40. Stm32Cubeprogrammer Option Bytes Screen (Write Protection 2)

    UM2851 Configuring STM32U5 static security protections Figure 40. STM32CubeProgrammer option bytes screen (Write Protection 2) As a second step, the WRP1A and WRP2A lock must be set manually: • WRP1A locked (UNLOCK_1A unchecked) • WRP2A locked (UNLOCK_2A unchecked) Figure 41. STM32CubeProgrammer option bytes screen (WRP1A lock) UM2851 - Rev 4 page 51/117...
  • Page 52: Figure 42. Stm32Cubeprogrammer Option Bytes Screen (Wrp2A Lock)

    UM2851 Configuring STM32U5 static security protections Figure 42. STM32CubeProgrammer option bytes screen (WRP2A lock) And finally, the RDP must be set manually: • RDP level 2 (JTAG connection only allowed to inject RDP 2 password and obtain device identification) Figure 43. STM32CubeProgrammer option bytes screen (RDP) UM2851 - Rev 4 page 52/117...
  • Page 53: Figure 44. Stm32Cubeprogrammer Option Bytes Screen (Rdp Confirmation)

    UM2851 Configuring STM32U5 static security protections Figure 44. STM32CubeProgrammer option bytes screen (RDP confirmation) Step 4.3 - Disconnect Figure 45. STM32CubeProgrammer disconnect At this step, the device is in freeze state due to the intrusion detection after the RDP level change. As a result, the connection with the device is lost.
  • Page 54: Tera Term Connection Preparation Procedure

    UM2851 Tera Term connection preparation procedure 10.5 Tera Term connection preparation procedure Tera Term connection is achieved by applying in sequence the steps described from Section 10.5.1 Section 10.5.3. 10.5.1 Tera Term launch The Tera Term launch requires that the port is selected as COMxx: STMicroelectronics STLink Virtual COM port. Figure 46 illustrates an example based on the selection of port COM63.
  • Page 55: St-Link Disable

    10.5.3 ST-LINK disable The security mechanisms managed by TFM_SBSFU_Boot forbid a JTAG connection (interpreted as an external attack). The ST-LINK must be disabled to establish a Tera Term connection. The following procedure applies from ST-LINK firmware version V3J8M3 onwards: •...
  • Page 56: Figure 49. Information Example Displayed On Tera Term In Development Mode

    UM2851 Tera Term connection preparation procedure • The TFM_SBSFU_Boot application starts with the static protections correctly configured. Then it jumps to the TFM_Appli displaying the user application main menu on the terminal emulator. Figure 49. Information example displayed on Tera Term in development mode UM2851 - Rev 4 page 56/117...
  • Page 57: Stm32U5 Device Reinitialization

    UM2851 STM32U5 device reinitialization Figure 50. Display on Tera Term in production mode 10.6 STM32U5 device reinitialization Once the TFM application is running on the device (in development mode or in production mode), it is possible to reinitialize the device to install a new TFM application. •...
  • Page 58: Step-By-Step Execution

    UM2851 Step-by-step execution Step-by-step execution 11.1 Welcome screen display After the installation procedure, the welcome screen of the TFM nonsecure application is displayed on Tera Term: Figure 51. TFM nonsecure application welcome screen 11.2 Test protections By pressing ‘1’, the user enters the test protection menu. Press then ‘1’...
  • Page 59: Figure 53. Test Protection Results

    UM2851 Test protections Several access attempts are performed in a row. For each access attempt, the effective behavior is checked against the expected behavior. The result can be one of the following ones: • DENIED (provoking reset) • SILENT (read as zero, write no effect) •...
  • Page 60: Test Tfm

    UM2851 Test TFM 11.3 Test TFM By pressing ‘2’, the user enters the TFM test menu. Figure 54. TFM test menu This menu permits the test of some of the TF‑M secure services at runtime. The user can select the TFM test to run by pressing the corresponding key: •...
  • Page 61: Figure 55. Tfm Test Results

    UM2851 Test TFM • ‘f’: Test Persistent key destruction services Additionally, the following menu item is not activated by default: • ‘s’: Test STSAFE (refer to Section 12.1 Configuration for its activation) When pressing ‘0’, all TFM test examples are executed in a row and the overall result is displayed in the log. Figure 55.
  • Page 62 UM2851 Test TFM Additional information regarding the EAT service token response The entity token is CBOR encoded. It is possible to decode it by following these steps: ™ ™ Ensure that a Python version is installed as indicated in Section 9.2.5 Python Copy and paste the token response obtained in the terminal emulator into the text file Middlewares\Thir d_Party\trustedfirmware\tools\iat-verifier\st_tools\eat.txt Navigate to Middlewares\Third_Party\trustedfirmware\tools\iat-verifier and execute the...
  • Page 63 UM2851 Test TFM The example below shows the decoding result of an EAT token response: Signature OK Token format OK Token: "CHALLENGE": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000", "BOOT_SEED": "5350bd5adf2246508f1ec3dd08e755ca78a2410825bdd0f52de9d12bf041d26b", "INSTANCE_ID": "01fa58755f658627ce5460f29b75296713248cae7ad9e2984b90280efcbcb50248", "IMPLEMENTATION_ID": "14802125f37bb43958d97435ddfcea8421c22d92ebac15a270a17c3130fd6bc3", "CLIENT_ID": -1, "SECURITY_LIFECYCLE": "SL_SECURED", "SW_COMPONENTS": [ "SW_COMPONENT_TYPE": "SPE", "SW_COMPONENT_VERSION": "1.0.0", "MEASUREMENT_VALUE": "b0b145240ead6765f9ee80b1bb241d9ad3d8deaf3c812ab904dd358beddfadcf", "MEASUREMENT_DESCRIPTION": "SHA256",...
  • Page 64: New Firmware Image

    UM2851 New firmware image 11.4 New firmware image 11.4.1 New firmware image in overwrite mode configuration (default configuration) By pressing ‘3’, the user enters the new firmware image menu. Figure 56. New firmware image menu It is possible to download a new TFM secure application image, a new TFM nonsecure application image, or both. •...
  • Page 65: Figure 57. Firmware Image Transfer Start

    UM2851 New firmware image In all four cases, send the signed binary with Tera Term by using the menu [File]>[Transfer]>[YMODEM]>[Send...]. Figure 57. Firmware image transfer start Once the file is selected, the Ymodem transfer starts. The transfer progress is reported as shown in Figure Figure 58.
  • Page 66: Figure 59. Reset To Trigger Installation

    UM2851 New firmware image After the download, press ‘1’ to reset the board and trigger the installation (or press the board reset button), as shown in Figure Figure 59. Reset to trigger installation UM2851 - Rev 4 page 66/117...
  • Page 67: Figure 60. Image Installation (In Overwrite Mode)

    UM2851 New firmware image After reset, the downloaded firmware images (one or two) are detected verified (including version antirollback check) decrypted (if needed) installed executed by TFM_SBSFU_Boot Figure 60. Image installation (in overwrite mode) In the case of a one-image configuration (and not the two-image configuration by default), the procedure is similar with the exception that the new firmware image menu proposes to download a unique image instead of secure and nonsecure images.
  • Page 68: New Firmware Image In Swap Mode Configuration

    UM2851 New firmware image 11.4.2 New firmware image in swap mode configuration In the swap mode configuration, the procedure to install a new image is similar to the one described in the overwrite mode configuration (refer to Section 11.4.1 New firmware image in overwrite mode configuration (default configuration)) while the image installation logs differ.
  • Page 69: Figure 62. New Firmware Image Menu (Swap Mode)

    UM2851 New firmware image In this the swap mode configuration, once installed, the new image must be validated at the first image boot; otherwise, it is reverted at the next boot. To validate the image after the installation, the user must press ‘3’ to enter the new firmware image menu in the user application, then press ‘6’...
  • Page 70: Figure 64. Image Reverted If Not Validated

    UM2851 New firmware image If the new image is not validated, it is then reverted at the next boot. Figure 64. Image reverted if not validated The new firmware image menu offers also the possibility to request the reinstallation of a reverted image. Press ‘a’...
  • Page 71: Nonsecure Data

    UM2851 Nonsecure data 11.5 Nonsecure data By pressing ‘4’, the user enters the nonsecure data menu. When pressing ‘1’, the primary nonsecure data image content is read and displayed. Figure 65. Nonsecure data menu 11.6 Local loader By pressing the user button (blue) during board reset, the user enters the local loader menu. The local loader is not part of the TFM nonsecure application, but is an immutable standalone application, in the nonsecure area.
  • Page 72: Integrator Role Description

    UM2851 Integrator role description Integrator role description STMicroelectronics delivers to customers (also called integrators or OEMs) a complete ecosystem around the STM32U5 microcontroller: • STM32U5 device: delivered with virgin user flash memory and security not activated in option byte • Set of reference boards (Nucleo board, Discovery kit, and Evaluation board) •...
  • Page 73 UM2851 Configuration Hardware-accelerated cryptography By default, the cryptography operations in the TFM and SBSFU applications are performed through the hardware cryptography peripherals of the device (PKA, SAES, HASH). The hardware-accelerated cryptography improves performance and is resistant against side channel attacks. It is possible to disable the hardware acceleration in MCUboot by commenting the BL2_HW_ACCEL_ENABLE define in TFM_SBSFU_Boot\Inc\config-boot.h.
  • Page 74 UM2851 Configuration Number of data images The TFM application example can be provisioned with data images. The installation and update mechanisms are like for the application images. No image, one data image (secure or nonsecure), or two data images (secure and nonsecure) can be defined in Linker\flash_layout.h.
  • Page 75 UM2851 Configuration No keys storage is necessary. /* Uncomment to associate and pair definitively STM32 and STSAFE */ //#define USE_PAIRING #ifdef USE_PAIRING /* Set to 1 if Host Keys are retrieved from a generation algorithm during the runtime. Set to 0 otherwise to use static keys values */ #define USE_COMPUTED_HOST_KEYS /* Set to 1 if STSAFE has never been provisioned */ /* Set to 0 otherwise to avoid self-verification of provisioning state */...
  • Page 76: Figure 67. Integrator Minimal Customizations

    UM2851 Minimal customization 12.2 Minimal customization At this stage, the integrator must at least customize the following: Figure 67. Integrator minimal customizations ST TFM application example Legend: Nonsecure area Local loader Nonsecure area Local loader Nonsecure area Secure area Nonsecure image secondary slot...
  • Page 77: Table 6. Integrator Personalized Data In Source Code

    UM2851 Minimal customization Table 6. Integrator personalized data in source code In integrator Personalized data Variable and source file personalized area binary RSA-2048 private key TFM\TFM_SBSFU_Boot\Src\root-rsa-2048.pem for secure image signature generation (used by the TFM_Appli RSA-2048 private key TFM\TFM_SBSFU_Boot\Src\root-rsa-2048_1.pem postbuild) for nonsecure image signature generation RSA-2048 public key...
  • Page 78: Figure 68. Integrator Personalized Data In Tfm_Sbsfu_Boot Binary (Initial_Attestation_Priv_Key Example)

    UM2851 Minimal customization In integrator Personalized data Variable and source file personalized area binary EC-256 public key for EC-256 crypto (used by the TFM\TFM_SBSFU_Boot\Src\enc-ec256-pub.pem AES-CTR key scheme TFM_Appli encryption postbuild) HUK for AES-GCM based AEAD huk_value encryption for the protected storage service (for full software cryptography TFM\TFM_SBSFU_Boot\Src\keys.c configuration only)
  • Page 79 UM2851 Other customization 12.3 Other customization The integrator can also change or configure the source code of the three TFM projects delivered in the STM32CubeU5 MCU Package via compiler switches to do additional customizations such as: • integrate additional secure services into the secure application. •...
  • Page 80: Figure 69. B-U585I-Iot02A Board Setup

    The BOOT0 pin must also be configured to boot from the flash memory in the case of the development mode: the switch SW1 must be configured on the position 0 indicated in Figure Figure 69. B-U585I-IOT02A board setup Tamper pins ST-LINK BOOT0 pin (SW1) Figure 70. B-U585I-IOT02A board setup (detail) Connector CN3 (front view)
  • Page 81: Figure 71. Reset Button On The B-U585I-Iot02A

    UM2851 Development hardware boards Figure 71 Figure 72 show the reset button and the JP3 jumper (IDD) used to disable the ST-LINK interface. Figure 71. Reset button on the B-U585I-IOT02A Reset button (B2) Figure 72. Jumper JP3 (IDD) on the B-U585I-IOT02A board...
  • Page 82: Figure 73. Stm32U5A9J-Dk Board Setup

    SW1 must be configured on the position 0 indicated in Figure Figure 73. STM32U5A9J-DK board setup BOOT0 pin (SW1) Tamper pins IDD jumper (JP3) ST-LINK Figure 74. STM32U5A9J-DK board setup (detail) Expansion connector CN10 (top view) Tamper pins UM2851 - Rev 4 page 82/117...
  • Page 83: Figure 75. Reset Button On The Stm32U5A9J-Dk

    UM2851 Development hardware boards Figure 75 Figure 73 show the reset button and the JP3 jumper (IDD) used to disable the ST-LINK interface. Figure 75. Reset button on the STM32U5A9J-DK Reset button (B2) ST-LINK UM2851 - Rev 4 page 83/117...
  • Page 84: Figure 76. Stm32U5G9J-Dk2 Board Setup

    The BOOT0 pin must be configured to boot from the flash memory in the case of the development mode: the switch SW1 must be configured on the position 0 indicated in Figure 76. This figure also shows the reset button, and the JP4 jumper (IDD) used to disable the ST-LINK interface. Figure 76. STM32U5G9J-DK2 board setup ST-LINK...
  • Page 85: Figure 77. Reset Button And Jp4 Jumper (Idd) On The Nucleo-U545Re-Q

    This board supports the examples for the STM32U5 microcontrollers with 512 Kbytes of flash memory. Figure 77 shows the reset button and the JP4 jumper (IDD) used to disable the ST-LINK interface. Figure 77. Reset button and JP4 jumper (IDD) on the NUCLEO-U545RE-Q...
  • Page 86: Figure 78. Flash Memory Protection Overview During Tfm_Sbsfu_Boot Application Execution

    UM2851 Memory protections Appendix B Memory protections Flash memory protections During the different applications execution, the flash memory protections are achieved by combining SAU, MPU, and GTZC configurations. During the TFM_SBSFU_Boot execution, the TFM_SBSFU_Boot code area is the only flash memory area allowed to be executed, with the immutable local loader.
  • Page 87: Figure 79. Flash Memory Protection Overview When Leaving Tfm_Sbsfu_Boot Application To Tfm Application

    UM2851 Flash memory protections When leaving the TFM_SBSFU_Boot application for jumping to the secure application, all flash memory areas dedicated to the TFM_SBSFU_Boot execution are hidden, and the execution is allowed in the secure and nonsecure primary slot areas. Figure 79. Flash memory protection overview when leaving TFM_SBSFU_Boot application to TFM application Legend: Nonsecure / Privileged...
  • Page 88: Figure 80. Flash Memory Protection Overview During Application Execution

    UM2851 Flash memory protections Once the secure application has performed the SPM initialization, a secure unprivileged area is created inside the secure image primary slot for the application RoT. Figure 80. Flash memory protection overview during application execution Legend: Nonsecure / Privileged Secure / Privileged Secure / Unprivileged Immutable application...
  • Page 89: Figure 81. Flash Memory Protection Overview When Leaving Tfm_Sbsfu_Boot Application To Nonsecure Local Loader

    UM2851 Flash memory protections When leaving the TFM_SBSFU_Boot application for jumping to the nonsecure local loader application (primary and secondary slot configuration), all flash memory areas dedicated to the TFM_SBSFU_Boot execution are hidden, and the SAU/MPU configurations are locked. Figure 81. Flash memory protection overview when leaving TFM_SBSFU_Boot application to nonsecure local loader application Legend:...
  • Page 90: Figure 82. Flash Memory Protection Overview When Leaving Tfm_Sbsfu_Boot Application To Secure And Nonsecure Local

    UM2851 Flash memory protections When leaving the TFM_SBSFU_Boot application for jumping to the secure and nonsecure local loader application (primary only slot configuration), all flash memory areas dedicated to TFM_SBSFU_Boot execution are hidden, the SAU/MPU configurations are locked, and the flash memory area corresponding to the secure part of the local loader is configured as secure.
  • Page 91 UM2851 SRAM protections SRAM protections The SRAM memory protection is achieved by combining the SAU, MPU, and GTZC configurations. GTZC and MPU are used to fix privileged and unprivileged accesses. The GTZC protection prevents illegal accesses from the peripheral bus controller (such as DMA). The MPU prevents the SRAM from being executed. During the application execution, the BL2 shared data area is write protected.
  • Page 92 UM2851 Memory footprint Appendix C Memory footprint As described in Section 8.2, the TFM-based application examples consist of four main software components, which can be configured by the integrators according to their needs: • TFM_SBSFU_Boot: Secure Boot and Secure Firmware Update application •...
  • Page 93: Table 7. Sbsfu Configuration Option

    UM2851 TFM_SBSFU_Boot memory footprint TFM_SBSFU_Boot memory footprint The TFM_SBSFU_Boot application consists of the sections in the flash memory described in Section 8.3 Memory layout. The sizes of these flash memory sections can be impacted by the configuration described in Table Table 7.
  • Page 94 UM2851 TFM_SBSFU_Boot memory footprint Items Configuration possibility Size impact 2 data images: Number of data images: • EWARM: + 0.4 Kbyte SBSFU code • Additional code needed to manage the 2 data images • MDK-ARM: + 0.3 Kbyte • STM32CubeIDE: + 0.4 Kbyte Swap mode: Image upgrade strategy: •...
  • Page 95: Table 8. Sbsfu Footprint Examples

    UM2851 TFM_SBSFU_Boot memory footprint Table 8 describes three examples: • Minimal configuration example • SBSFU_Boot example delivered in the STM32CubeU5 MCU Package • TFM_SBSFU_Boot example delivered in the STM32CubeU5 MCU Package Table 8. SBSFU footprint examples Items Minimal configuration SBSFU example Full TFM example HASH REF data 32 SHA256 max...
  • Page 96: Table 9. Secure Application Configuration Options

    UM2851 TFM_Appli_Secure memory footprint TFM_Appli_Secure memory footprint The secure application provides secure services that can be used by the nonsecure application at runtime: • Put in place the security architecture with the isolation of the different domains and with the secure APIs mechanisms •...
  • Page 97 UM2851 TFM_Appli_Secure memory footprint Items Configuration possibility Size impact Protected storage service needed at user application runtime: Code: • Based on open-source TFM reference implementation • 2 NV data buffers needed (2 flash memory sectors of • EWARM: + 3.8 Kbytes 8 Kbytes each at minimum) •...
  • Page 98: Table 10. Secure Application Footprint Example

    UM2851 TFM_Loader memory footprint Table 10 describes three examples: • Empty secure application template • Limited TFM crypto services only • Full TFM secure services Table 10. Secure application footprint example Empty secure Limited TFM crypto Configuration application Full TFM secure services services only template Very basic...
  • Page 99: Table 12. Firmware Loader Application Footprint Example

    UM2851 TFM_Appli_NonSecure memory footprint 2. The minimal code size is obtained using MDK-ARM version 5.37.0.0. Table 12 describes two examples: • Single image slot • Two images slots Table 12. Firmware loader application footprint example Configuration Single image slot Two images slots Number of firmware slots 1 (primary slot only) IDEs...
  • Page 100: Table 14. Nonsecure Application Footprint Example

    UM2851 TFM_Appli_NonSecure memory footprint Items Configuration possibility Size impact Size of firmware loader Refer to TFM_Loader memory Refer to TFM_Loader memory footprint. application footprint Different binary size according to the IDE used and its Code and IDE dependent compiler options. Table 14 describes the two examples provided in the STM32CubeU5...
  • Page 101: Table 15. Tfm_Sbsfu_Boot Cryptographic Algorithms

    UM2851 Performance Appendix D Performance TFM_SBSFU_Boot application performance The TFM_SBSFU_Boot application implements the "Secure Boot" function and the "Secure Firmware Update" function. The "Secure Boot" function: • controls the security static protections and sets up the runtime protections. • configures runtime protections. •...
  • Page 102: Figure 84. Secure Boot Execution Timing

    UM2851 TFM_SBSFU_Boot application performance • Number of firmware slots: – Primary and secondary slots: new firmware image can be downloaded by the nonsecure application – Primary slot only: active image overwritten, new firmware image can only be downloaded by a standalone loader application •...
  • Page 103: Table 16. "Secure Boot" Operations Timing Indications

    UM2851 TFM_SBSFU_Boot application performance Table 16 provides the different “Secure Boot” operations timings for the following reference configurations: • Hardware configuration: hardware-accelerated cryptography capability, 160 MHz, instruction cache activated • Number of firmware images: two firmware images • Number of firmware slots: primary and secondary slots •...
  • Page 104: Table 17. "Secure Boot" Execution Timing Value Indications

    UM2851 TFM cryptographic performance Timing for reference configuration Fluctuation versus reference EWARM MDK-ARM Operation name Timing influencing factor STM32CubeIDE configuration (version (version (version 1.10.0) 9.20.1) 5.37.0.0) SBSFU • Size of RAM used by % RAM size used by SBSFU application 1.4 ms 1.4 ms 1 ms...
  • Page 105: Table 19. Cryptographic Algorithms Present But Not Activated

    UM2851 TFM cryptographic performance Functionality Algorithm Key size Mode Implementation RSA (PKCS#1 v1.5) 1024 Hardware accelerated 2048 RSA (PKCS#1 v2.1) Hardware accelerated 3072 Curves: secp192r1, secp224r1, secp256r1, Asymmetric secp384r1, secp521r1, secp192k1, algorithms Hardware accelerated secp224k1, secp256k1, bp256r1, bp384r1, ECDH or ECDSA bp512r1 Curves: 25519, 448 mbed-crypto software...
  • Page 106 UM2851 TFM cryptographic performance As an indication, some performance measurements are provided in Table 20 for some TFM cryptographic services with and without hardware accelerators usage. The timings are measured at TFM nonsecure side, when calling PSA APIs with ICACHE enabled on the internal flash memory.
  • Page 107: Table 20. Performance For Cryptographic Tfm Runtime Services

    Table 20. Performance for cryptographic TFM runtime services Hardware accelerated mbed-crypto software PSA service EWARM MDK-ARM STM32CubeIDE EWARM MDK-ARM STM32CubeIDE (called from the TF‑M nonsecure application) (version 9.20.1) (version 5.37.0.0) (version 1.10.0) (version 9.20.1) (version 5.37.0.0) (version 1.10.0) Initial attestation (including ECDSA signature) psa_initial_attest_get_token 6 766 209 cycles 6 666 116 cycles...
  • Page 108: Table 21. Troubleshooting

    No logs on the terminal after the device Same as above. programming No logs on the terminal when ST-LINK USB is Same as above. connected to a board programmed with TFM Plug the tamper cable between the tamper pins on the...
  • Page 109: Table 22. Document Revision History

    Appendix D Performance. Added STM32U5A9J-DK and NUCLEO-U545RE-Q to the set of available development boards: • Added Appendix A Development hardware boards • Updated Section 9.1 Hardware setup and Section 10.5.3 ST-LINK disable UM2851 - Rev 4 page 109/117...
  • Page 110 UM2851 Date Revision Changes Added STM32U5G9J-DK2 to the set of available development boards: • Updated Section 1.1 Applicable products and default examples Appendix A Development hardware boards • Updated Section 9.1 Hardware setup • Updated the compatibility with 4-Mbyte STM32U5Fxxx/Gxxx devices in Figure 18.
  • Page 111: Table Of Contents

    UM2851 Contents Contents General information ............. . . 2 Applicable products and default examples.
  • Page 112 ST-LINK disable ........
  • Page 113 UM2851 Contents 12.2 Minimal customization ............76 12.3 Other customization .
  • Page 114 UM2851 List of tables List of tables Table 1. List of acronyms ..............2 Table 2.
  • Page 115 UM2851 List of figures List of figures Figure 1. TF-M overview ..............6 Figure 2.
  • Page 116 UM2851 List of figures Figure 50. Display on Tera Term in production mode..........57 Figure 51.
  • Page 117 ST’s terms and conditions of sale in place at the time of order acknowledgment. Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of purchasers’...

Table of Contents