AN4992 · Application noteIntroduction to secure firmware install (SFI) for STM32 MCUs
Download .pdfOpen in the full document

STM32WL5

Secure bootloader overview

The secure bootloader is split in two parts.

The first part is stored in boot ROM (system memory). It is responsible for loading the second part of the bootloader in SRAM2 through the supported COM ports. The supported COM ports are USART, SPI and JTAG.

The second part runs in SRAM2 and is responsible for executing the SFI process and applying the SFI protocol thanks to the commands received through the above mentioned supported COM ports.

The secure bootloader permits to run the SFI process several times. For this, the STM32WL5 has been reprogrammed to its initial OB configuration (as delivered by STMicroelectronics).

For more details on the STM32 bootloader protocols, refer to [AN3155] (USART protocol) and [AN4286] (SPI protocol).

Figure 11. STM32WL5 secure bootloader


User flash memory mapping

The secure bootloader is stored in system memory and SRAM2, the products are delivered in RDP level0 and all the user flash memory is available for OEM.

The OEM internal firmware can be built to start at the beginning of the user flash memory (starting address 0x0800 0000). After a SFI, the SRAM2 is fully available for OEM.

Secure boot path

In order to get the STM32WL5 booting on secure user flash memory after successful SFI, it is recommended to set nSWBOOT0 to 0 and nBOOT0 to 1 in FLASH_OPTR register.

More information is available in [RM0453].

SFI image preparation

The SFI image can be prepared by using STMicroelectronics STM32 Trusted Package Creator available both

in CLI (command line interface) and GUI (graphical user interface) modes. This tool can be downloaded free of

charge from www.st.com.

Note:

STM32 Trusted Package Creator tool is included inside STM32CubeProgrammer tool package (STM32CubeProg) available on www.st.com.

It allows the generation of SFI images for STM32 microcontrollers.

Figure 12 STM32 Trusted Package Creator - SFI option bytes shows STM32 TPC screen to be used for building SFI option bytes configuration file (.csv) that is needed for SFI image creation (examples of SFI OB configuration file available in a dedicated STM32CubeProgrammer directory). More information is available in [UM2238].

For STM32 supporting OEM password keys, values 0x00000000 (default) and 0xFFFFFFFF do not enable OEM password.

Figure 12. STM32 Trusted Package Creator - SFI option bytes


Figure 13 STM32 Trusted Package Creator - SFI image creation shows STM32 TPC screen to be used to create SFI image.

Figure 13. STM32 Trusted Package Creator - SFI image creation


SFI firmware image format

The SFI format is an encryption format for firmware created by STMicroelectronics. It uses AES-GCM algorithm with a 128-bit key to transform a firmware in Elf, Hex, Bin or Srec formats into an encrypted and authenticated firmware in SFI format.

An SFI firmware image is composed of a header plus several areas. The areas are usually contiguous firmware areas. The last area is the configuration area containing the option byte values to be programmed when the SFI is complete.

SFI firmware image creation procedure for STM32H7/L5/U3/U5/WBA5/WBA6/WL5

To obtain SFI firmware images in the correct format (see SFI firmware image format), the OEM must follow the steps below to build an SFI image:

  1. Build the firmware image(s) using regular development tools.
  2. Build the option byte configuration file.

    This file contains the option bytes that the customer plans to apply on the STM32 and that are programmed thanks to SFI. Among option bytes, the user must define the intended RDP and TZEN values to be applied in order to enable the protection of user firmware and data against debug connection. Refer to applicable reference manual for more details on RDP level.

    Table 3 Minimum RDP requirements below sums up the minimum RDP level that the customer must apply within the option byte file in order to protect the user firmware and data within either internal flash memory or (if applicable) external flash memories.

  3. Generate the binary image(s). A binary image does not need to be contiguous (that is it can cover multiple disjoint areas).
Table 3. Minimum RDP requirements
MicrocontrollerUse CaseMin RDP levelTZEN (TrustZone enable)
STM32H75xxxSFI on internal flash memory1Not applicable

STM32L5

STM32U3

STM32U5

STM32WBA5

STM32WBA6

SFI on internal flash memory

Protection of secure internal flash memory only

0.51 (enabled)

SFI on internal flash memory

Protection of secure and non-secure internal flash memory only

11 (enabled)

SFI on internal and external flash memories(1)

Protection on both memories

11 (enabled)
STM32WL5

SFI on internal flash memory

Protection of secure internal flash memory only

0(2) 1 (enabled)

SFI on internal flash memory

Protection of secure and non-secure internal flash memory only

11 (enabled)
Figure 14 SFI image preparation procedure shows the SFI image preparation procedure based on the STM32 Trusted Package Creator.
Note:

STM32 Trusted Package Creator tool is included inside STM32CubeProgrammer tool package (STM32CubeProg) available on www.st.com .

Figure 14. SFI image preparation procedure


1 Applicable to STM32L562xx, STM32U585xx, STM32U5Axxx and STM32U5Gxxx only (with OTFDEC).
2 With DDS = 1 and FSD = 0.

Internal flash memory only

To successfully generate an SFI image from the supported input firmware formats, click the SFI GUI tab, select the targeted micro-controller and fill in the interface fields with valid values:

Figure 15. SFI image generation tab example


  1. Add the firmware file using the Add button located within the Firmware files area appended to the input firmware files list.
  2. Make sure you are referring to the right valid firmware. Details are available in the Firmware information section once you have the Input firmware file is selected.
  3. Select the Encryption key and Nonce files. They can be selected either by entering their absolute or relative paths, or by selecting them with the Open button.
  4. Make sure that the size of the Encryption key file (16 bytes) and the Nonce file (12 bytes) are respected. In order to properly protect the firmware confidentiality, the AES secret key must be different every time the OEM encrypts a new firmware or a new release of the same firmware.
  5. Select the Option bytes file in .csv format. This is the only format supported.
  6. Enter the image version of the SFI to be generated. It must range from 0 to 255.
  7. Select Random key area file using the Open button (this is optional). Key area requests STM32 to randomly generate data of a specified size and at a specified address filled by user within key area file in .kcsv format.
  8. The Generate Hash option must be enabled on all STM32 devices supporting SFI.
  9. Select MCU to fill available RAM size for the SFI operation.
  10. Select the address where the continuation token is going to be stored. This field is only relevant for STM32H75xxx products, depending on firmware mapping, 0x081FF000 can be used as a nominal value.
  11. For STM32H75xxx only, select SMI files, if any (optional field).
  12. Select the Output file folder path where the SFI image, out.sfi, is going to be generated.
  13. Generate the SFI file by clicking the Generate SFI button. If all the fields are filled properly, the "SFI created successfully" message is displayed.

More information is available in [UM2238].

Note:

SMI files selection is only mandatory for secure module installation process. It is only supported on STM32H75xxx products.

Figure 16. SFI image successful generation


Both internal and external flash memories

To successfully generate a SFI image including external FW and Data (also called SFIx image) from the supported input firmware formats, click the SFIx GUI tab, select the targeted micro-controller and fill in the interface fields with valid values:

Figure 17. SFIx image generation tab example


  1. Add the internal firmware file(s) using the Add button located within the Internal firmware files area appended to the input firmware files list. If the file is in bin format, the destination address has to be filled. If OEM uses global AES external flash memory keys, then internal firmware files must include those keys at the right address.
  2. Add the external firmware file(s) using the Add button located within the external firmware files area appended to the input firmware files list. When adding an external firmware, several additional fields have to be filled (destination address in external flash memory, OTFD region number, OTFD mode and global AES external flash key address).
  3. Select key area file using the Open button (this is optional). Key area requests STM32 to randomly generate data of a specified size and at a specified address filled by user within key area file in .kcsv format.
  4. Select the Encryption key and Nonce files. They can be selected either by entering their absolute or relative paths, or by selecting them with the Open button.
  5. Make sure that the size of the Encryption key file (16 bytes) and the Nonce file (12 bytes) are respected. In order to properly protect the firmware confidentiality, the AES secret key must be different every time the OEM encrypts a new firmware or a new release of the same firmware.
  6. Select the Option bytes file in .csv format. This is the only format supported.
  7. Enter the image version of the SFIx image to be generated. It must range from 0 to 255.
  8. The Generate Hash option must be enabled on all STM32 devices supporting SFI.
  9. Select MCU to fill available RAM size for the SFIx operation.
  10. Select the address where the continuation token is going to be stored. This field is only relevant for STM32H75xxx products, depending on firmware mapping, 0x081FF000 can be used as a nominal value.
  11. Select the Output file folder path where the SFIx image, out.sfix, is going to be generated.
  12. Generate the SFIx image file by clicking the "Generate SFIx" button. If all the fields are filled properly, the "SFIx created successfully" message is displayed.

More information is available in [UM2238].

Figure 18. SFIx image successful generation


OEM passwords for RDP regression (STM32U3, STM32U5, STM32WBA5 and STM32WBA6 series only)

On STM32U3, STM32U5, STM32WBA5, and STM32WBA6, it is possible to set the OEM1 and OEM2 passwords during the option bytes programming. To do so, the OEM must provide passwords different than 0x00000000 or 0xFFFFFFFF in the dedicated fields inside the Option-Bytes configuration file.

The OEM can also decide to diversify these passwords for each programmed chips thanks to the KEYDIVERS field in the Option-Bytes configuration file. This diversification is done during the secure programming of the SFI image using the KDF256 algorithm, with the OEM-Key registers and the chip’s Device Authentication ID as inputs. Depending on part numbers, the following OEM password diversification schemes are available:

Figure 19. OEM password diversification scheme for STM32U5, STM32WBA5 and STM32WBA6


Figure 20. OEM password diversification scheme for STM32U3


Knowing the master keys, the OEM can read the Authentication ID from the DBG_MCU interface, compute the chip’s diversified keys on his own and then trigger the desired RDP regression.

The OEMDIVERS field from the Option-Bytes can be configured in multiple ways:

  • 0x00000000 means that no OEM password is diversified.
  • 0x0000EABE means that only OEM1 password is diversified.
  • 0xEABE0000 means that only OEM2 password is diversified.
  • 0xEABEEABE means that both OEM1 and OEM2 passwords are diversified.
CAUTION:

On STM32U5, STM32WBA5 and STM32WBA6 the OEM passwords can be reset in RDP 0 only.

On STM32U3, once programmed the OEM passwords can never be reset.

KDF256 details

The KDF256 algorithm is described by ANSI X9.63-2011.

KDF256 (OEMxKeyR1 || OEMxKeyR2 || AUTHID) is equivalent to SHA256 (OEMxKeyR1 || OEMxKeyR2 || AUTHID || 0x00000001) with OEMxKeyR1, OEMxKeyR2, AUTHID, and the counter all expressed in big endian.

KDF256 (OEMxKeyR1 || OEMxKeyR2 || OEMxKeyR3 || OEMxKeyR4 || AUTHID) is equivalent to SHA256 (OEMxKeyR1 || OEMxKeyR2 || OEMxKeyR3 || OEMxKeyR4 || AUTHID || 0x00000001) with OEMxKeyR1, OEMxKeyR2, OEMxKeyR3, OEMxKeyR4, AUTHID, and the counter all expressed in big endian.

OEM passwords diversification example on STM32U5

OEM1KEYR1 = 0x11111111

OEM1KEYR2 = 0x22222222

AUTHID = 0x10e0e13e

KDF256 (OEM1 || OEM2 || AUTHID) = SHA256 (11 11 11 11 22 22 22 22 10 0e e1 3e 00 00 00 01) = 98 ed c0 39 2e 06 c3 17 03 21 20 9c 8b 36 7e 52 a9 05 86 75 88 e4 33 9f 6f 47 44 86 89 64 a4 18

The first four bytes are used for the derived OEM1 password (0x98edc039) and the second group of four bytes is the derived OEM2 password (0x2e06c317).

So, KDF256 result is:

OEM1KEYR1_divers = 0x98edc039

OEM1KEYR2_divers = 0x2e06c317