Last edited 7 months ago

How to perform Secure Boot from Distribution Package



1. Article purpose[edit | edit source]

The purpose of this article is to explain how to perform a secure boot on an STM32MPU device with the Distribution Package.
Follow these steps to perform this use case:

You must proceed step-by-step (no rollback possible).

2. Creating signature key[edit | edit source]

To perform the secure boot, binaries must be signed with a specific signature key.

If this signature key is already present on the STM32MPU device, go directly to Distribution Package with signed FIP.

To create the signature key, use the STM32MP KeyGen CLI Tool.

Refer to the KeyGen tool page for installation and command-line options.
The minimal command to use is:

STM32MP_KeyGen_CLI -abs <output directory> -pwd <password> -n <number of key>

With:

  • <output directory> = Patch to the generated private and public key files (privateKey.pem and publicKey*.pem).
  • <password> = Password of the private key. The password must contain at least four characters. The number of passwords must match the number of key pairings.
  • <number of key> = Number of key pairs, one for STM32MP15 or more for other platforms.

2.1. Creating signature key for STM32MP13[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Creating signature key for STM32MP13x lines More info.png .

2.2. Creating signature key for STM32MP15[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Creating signature key for STM32MP15x lines More info.png .

2.3. Creating signature key for STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Creating signature key for STM32MP25x lines More info.png .

3. Creating encryption key[edit | edit source]

3.1. Creating encryption key for STM32MP13 and STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Creating encryption key for STM32MP13x lines More info.png and STM32MP25x lines More info.png.

4. Putting signature key on STM32 MPU[edit | edit source]

4.1. Putting hash key on device for STM32MP13 and STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Putting hash key on device for STM32MP13x lines More info.png and STM32MP25x lines More info.png.

4.2. Putting the hash key on the device for STM32MP15[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Putting hash key on device for STM32MP15x lines More info.png.

5. Putting encryption key on STM32 MPU[edit | edit source]

5.1. Putting an encryption key on the device for STM32MP13 and STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Putting an encryption key on the device for STM32MP13x lines More info.png and STM32MP25x lines More info.png .

6. Distribution Package with signed FIP[edit | edit source]

6.1. Prerequisites[edit | edit source]

6.2. Generate Distribution Package with signed binaries[edit | edit source]

  • Source the environment of the Distribution Package.
source layers/meta-st/scripts/envsetup.sh

Select your DISTRO and your machine.

  • Indicate where to find the signature key (in this example, the signature key is located in the key directory on the meta-st-stm32mp layer).

Add the following lines to local.conf (in the build directory):

6.2.1. Generate Distribution Package with signed binaries for STM32MP13[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Generate Distribution Package with signed binaries for STM32MP13.

6.2.2. Generate Distribution Package with signed binaries for STM32MP15[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Generate Distribution Package with signed binaries for STM32MP15.

6.2.3. Generate Distribution Package with signed binaries for STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Generate Distribution Package with signed binaries for STM32MP25.

  • Compile the binaries:
bitbake st-image-weston

The FIP file, signed and ready to be programmed on the board, can be found in tmp-glibc/deploy/images/<machine name>/fip/.

6.3. Generate a Distribution Package with encrypted partition binaries[edit | edit source]

6.3.1. Generate a Distribution Package with encrypted partition binaries for STM32MP13[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Generate a Distribution Package with encrypted partition binaries for STM32MP13.

6.3.2. Generate a Distribution Package with encrypted partition binaries for STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Generate a Distribution Package with encrypted partition binaries for STM32MP25x lines More info.png .

7. Signing first-stage bootloader binaries[edit | edit source]

If the first-stage bootloader binaries (TF-A BL2) are generated unsigned, they must be signed manually using STM32MP_SigningTool_CLI.

For installation and command-line options, see Signing tool.

These tools are used to sign a binary with an STM32 header, with the minimal options to sign the FSBL binary:

STM32MP_SigningTool_CLI -pubk <public key> -prvk  <private key> -pwd <password> -t fsbl -of <Option_Flags> -bin FSBL binary not signed>.stm32 -o <FSBL binary signed>.stm32

with:

  • <public key> = The path of the public key file generated by KeyGen: publicKey.pem.
  • <private key> = The path of the private key files generated by KeyGen: privateKey*.pem; one for STM32MP15 and eight for STM32MP13/STM32MP25.
  • <password> = Password used by KeyGen to protect the key files. The number of passwords must match the number of key pairs.
  • <Option_Flags> = The -of option is required only for STM32MP13, with a 0x0000 0001 value.

7.1. Signing first-stage bootloader binaries for STM32MP13[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Signing first stage bootloader binaries for STM32MP13x lines More info.png .

7.2. Signing first stage bootloader binaries for STM32MP15[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Signing first stage bootloader binaries for STM32MP15x lines More info.png .

7.3. Signing first stage bootloader binaries for STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Signing first stage bootloader binaries for STM32MP25x lines More info.png .

8. Encrypt first stage bootloader binaries[edit | edit source]

8.1. Encrypt first stage bootloader binaries for STM32MP13[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Encrypt first stage bootloader binaries for STM32MP13.

8.2. Encrypt first stage bootloader binaries for STM32MP25[edit | edit source]

Click on "Expand", visible on the right side of the page, to view Encrypt first stage bootloader binaries for STM32MP25.

9. Create FlashLayout file for signed binaries[edit | edit source]

To populate the correct binaries on the board, you need to create a FlashLayout file with the signed binaries:

  • FSBL = tf-a-*_Signed.stm32
  • FIP = fip-*.bin

Example for FlashLayout_sdcard_stm32mp157f-dk2-optee.tsv:

#Opt	Id	Name	Type	IP	Offset	Binary
- 	0x01	fsbl-boot	Binary	none	0x0	arm-trusted-firmware/tf-a-stm32mp157f-dk2-usb.stm32
-	0x03	fip-boot	FIP	none	0x0	fip/fip-stm32mp157f-dk2-optee.bin
P	0x04	fsbl1	Binary	mmc0	0x00004400	arm-trusted-firmware/tf-a-stm32mp157f-dk2-sdcard.stm32
P	0x05	fsbl2	Binary	mmc0	0x00044400	arm-trusted-firmware/tf-a-stm32mp157f-dk2-sdcard.stm32
P	0x06	metadata1	Binary	mmc0	0x00084400	arm-trusted-firmware/metadata.bin
P	0x07	metadata2	Binary	mmc0	0x000C4400	arm-trusted-firmware/metadata.bin 
P	0x08	fip-a	FIP	mmc0	0x00104400	fip/fip-stm32mp157f-dk2-optee.bin
PED	0x09	fip-b	FIP	mmc0	0x00504400	none
PED	0x0A	u-boot-env	Binary	mmc0	0x00904400	none
P	0x10	bootfs	System	mmc0	0x00984400	st-image-bootfs-openstlinux-weston-stm32mp1.ext4
P	0x11	vendorfs	FileSystem	mmc0	0x04984400	st-image-vendorfs-openstlinux-weston-stm32mp1.ext4
P	0x12	rootfs	FileSystem	mmc0	0x05984400	st-image-weston-openstlinux-weston-stm32mp1.ext4
P	0x13	userfs	FileSystem	mmc0	0x33984400	st-image-userfs-openstlinux-weston-stm32mp1.ext4

Update the fsbl1-boot, fip-boot, fsbl1, fsbl2 and fip partitions.
Result:

#Opt	Id	Name	Type	IP	Offset	Binary
- 	0x01	fsbl-boot	Binary	none	0x0	arm-trusted-firmware/tf-a-stm32mp157f-dk2-usb_Signed.stm32
-	0x03	fip-boot	FIP	none	0x0	fip/fip-stm32mp157f-dk2-optee_Signed.bin
P	0x04	fsbl1	Binary	mmc0	0x00004400	arm-trusted-firmware/tf-a-stm32mp157f-dk2- sdcard_Signed.stm32
P	0x05	fsbl2	Binary	mmc0	0x00044400	arm-trusted-firmware/tf-a-stm32mp157f-dk2- sdcard_Signed.stm32
P	0x06	metadata1	Binary	mmc0	0x00084400	arm-trusted-firmware/metadata.bin
P	0x07	metadata2	Binary	mmc0	0x000C4400	arm-trusted-firmware/metadata.bin 
P	0x08	fip-a	FIP	mmc0	0x00104400	fip/fip-stm32mp157f-dk2-optee_Signed.bin
PED	0x09	fip-b	FIP	mmc0	0x00504400	none
PED	0x0A	u-boot-env	Binary	mmc0	0x00904400	none
P	0x10	bootfs	System	mmc0	0x00984400	st-image-bootfs-openstlinux-weston-stm32mp1.ext4
P	0x11	vendorfs	FileSystem	mmc0	0x04984400	st-image-vendorfs-openstlinux-weston-stm32mp1.ext4
P	0x12	rootfs	FileSystem	mmc0	0x05984400	st-image-weston-openstlinux-weston-stm32mp1.ext4
P	0x13	userfs	FileSystem	mmc0	0x33984400	st-image-userfs-openstlinux-weston-stm32mp1.ext4

10. Program and test[edit | edit source]

Use the previously created FlashLayout file with the signed binaries to populate the correct binaries on the board.

At board boot time, check the two levels of the secure boot: the ROM code secure boot validation and the TF-A BL2 trusted board boot validation.

11. Close the device[edit | edit source]

For more information, refer to How to secure STM32 MPU.

In U-Boot console:

  stm32key close

For more information, see the How to use U-Boot stm32key command.

As soon as the device is closed, the operation is irreversible; the user is forced to only use signed images.

12. References[edit | edit source]