1. Configure secure boot
To build signed artifacts, modify your conf/local.conf
file to include the following:
# Required to include trustfence support.
INHERIT += "trustfence"
Digi Embedded Yocto generates a PKI tree by default under a new folder called trustfence
inside your project.
To specify a custom path for the PKI tree, see Advanced options.
1.1. U-Boot environment encryption
When enabling TrustFence, the U-Boot environment will be encrypted by default using the ?????.
This feature is only supported in closed devices. This setting has no effect on open devices. |
To explicitly disable U-Boot environment encryption, see Advanced options.
2. Build your target images
Once TrustFence is enabled and configured in your Digi Embedded Yocto project, you can build your target image. For example:
$ bitbake dey-image-webkit
When the build process finishes, several secure artifacts appear in the deployment directory:
-
arm-trusted-firmware/tf-a-ccmp15-dvk-nand.stm32_signed
: This the signed ARM Trusted Firmware. -
fip/fip-ccmp15-dvk-optee_Signed.bin
: This is the signed FIP image with the U-Boot bootloader and Trusted Execution Environment (OP-TEE).
The PKI tree is also generated (when not provided).
Its files are stored at the specified TRUSTFENCE_SIGN_KEYS_PATH
location (by default, a subfolder in the project called trustfence/
).
The folder contains the following:
-
keys/key_pass.txt
: the randomly generated password in plain text -
keys/privateKey.pem
: the private key -
keys/publicKey.pem
: the public key -
keys/publicKeyhash.bin
: hash of the ECC public key
These files need to be securely stored in order to be used in the manufacturing of secure devices. |
3. Program the signed artifacts (TF-A and FIP)
Program the signed ARM Trusted Firmware image on the fsbl1 partition:
=> update fsbl1 tftp tf-a-ccmp15-dvk-nand.stm32_signed
Program the signed FIP image on the fip-a partition:
=> update fip-a tftp fip-ccmp15-dvk-optee_Signed.bin
Flashing signed images does not enable any security features in the target. See Secure the device to learn how to close your device to only boot signed images. |
Reset the device, and check the new messages that appear:
NOTICE: CPU: STM32MP157CAC Rev.Z
NOTICE: Model: Digi International ConnectCore MP15 Development Kit
NOTICE: Bootrom authentication failed
NOTICE: BL2: v2.6-stm32mp1-r2.0(release):dey-4.0-r2.2(56756557)
NOTICE: BL2: Built : 15:41:16, Mar 10 2023
NOTICE: TRUSTED_BOARD_BOOT support enabled
NOTICE: ROTPK is not deployed on platform. Skipping ROTPK verification.
NOTICE: ROTPK is not deployed on platform. Skipping ROTPK verification.
NOTICE: BL2: Booting BL32
optee optee: OP-TEE: revision 3.16 (da44f979)
U-Boot dub-2021.10-r2.2-00003-g7dd1458751a7 (Mar 21 2023 - 08:48:30 +0000)
[...]
=>
The Bootrom authentication failed
message appears.
This means the ROM loader detected that it is booting a signed image, but it could not authenticate it.
This is expected because you have not yet programmed the hash of the ECC public key on the OTP bits.
The next message is TRUSTED_BOARD_BOOT support enabled
.
This means the TF-A image (or first-stage bootloader) has been built with authentication support enabled; that is, FSBL will either authenticate the second-stage boot loader or refuse to boot.
The next message is ROTPK is not deployed on platform. Skipping ROTPK verification
.
This displays because the Root Of Trust Public Key (ROTPK) has not yet been programmed on the OTP bits, so the FSBL skips the authentication of the second-stage bootloader and just boots it.
Following that, OP-TEE runs and then U-Boot starts.
4. Secure the device
The final step in configuring secure boot for a device is burning the secure OTP configuration.
The secure OTP configuration can only be written once and is irreversible. |
To secure the device:
4.1. Program the Public Key Hash (PKH)
The PKH OTP bits (words 24..31) hold the hash of the ECC public key.
The ConnectCore MP15 has two boot stages:
-
Initially, the ROM loader uses the PKH OTP bits to authenticate the FSBL (TF-A). In open devices, the FSBL will boot in any case and the log reports whether the authentication was successful or failed.
-
Next, the FSBL (built with authentication support when TrustFence is enabled) authenticates the second stage bootloader (SSBL), the FIP image. If the PKH is not programmed, it skips the authentication and boots it; if the PKH is programmed, it validates the signature and refuses to boot if the authentication fails.
To program the PKH:
-
Transfer the
publicKeyhash.bin
into an address in RAM, for example via TFTP:=> tftp ${loadaddr} publicKeyhash.bin
-
Read the contents of that RAM address into the PKH. This command prints the hexadecimal bytes that form the PKH:
=> stm32key read ${loadaddr} Read PKH at 0xc2000000 PKH OTP 24: [c2000000] 5cda63dc PKH OTP 25: [c2000004] 5a2b8e15 PKH OTP 26: [c2000008] f0708804 PKH OTP 27: [c200000c] c2dfc733 PKH OTP 28: [c2000010] a34fb740 PKH OTP 29: [c2000014] 246b14e3 PKH OTP 30: [c2000018] ef53f16b PKH OTP 31: [c200001c] 53ef8f83
-
Verify the hexadecimal values match the contents of the
publicKeyhash.bin
that corresponds to the PKI tree you are using to sign the files. Remember to back up this PKI tree to be able to sign future images. -
Fuse the PKH on the OTP bits (irreversible):
=> stm32key fuse ${loadaddr} PKH OTP 24: 5cda63dc lock : 50000000 PKH OTP 25: 5a2b8e15 lock : 50000000 PKH OTP 26: 17125380 lock : 50000000 PKH OTP 27: c2dfc733 lock : 50000000 PKH OTP 28: a34fb740 lock : 50000000 PKH OTP 29: 246b14e3 lock : 50000000 PKH OTP 30: ef53f16b lock : 50000000 PKH OTP 31: 53ef8f83 lock : 50000000 Warning: Programming fuses is an irreversible operation! This may brick your system. Use this command only if you are sure of what you are doing! Really perform this fuse programming? <y/N> y PKH updated!
At this point, the PKH has been programmed but the device is still open and can still boot any unsigned images.
-
Reset the device, and check the new messages that appear:
NOTICE: CPU: STM32MP157CAC Rev.Z NOTICE: Model: Digi International ConnectCore MP15 Development Kit NOTICE: Bootrom authentication succeeded NOTICE: BL2: v2.6-stm32mp1-r2.0(release):dey-4.0-r2.2(56756557) NOTICE: BL2: Built : 15:41:16, Mar 10 2023 NOTICE: TRUSTED_BOARD_BOOT support enabled NOTICE: BL2: Booting BL32 optee optee: OP-TEE: revision 3.16 (da44f979) U-Boot dub-2021.10-r2.2-00003-g7dd1458751a7 (Mar 21 2023 - 08:48:30 +0000) [...] =>
The Bootrom authentication succeeded
message appears.
This means the ROM loader detected that it is booting a signed image and it could successfully authenticate it against the programmed PKH.
The next message is TRUSTED_BOARD_BOOT support enabled
.
This means the TF-A image (or first-stage bootloader) has been built with authentication support enabled; that is, FSBL will either authenticate the second-stage bootloader or refuse to boot.
If the boot continues at this point, the FIP image was authenticated successfully. If authentication fails, the FIP image won’t boot at all, even if the device is open.
On open devices you can still boot unsigned images without authentication support (without TrustFence). |
4.2. Close the device
This step is irreversible and could brick your device. |
Before closing the device:
-
Verify you have programmed signed, not encrypted, TF-A and FIP images in the NAND.
-
Verify you have programmed the PKH.
-
Verify the FSBL shows
Bootrom authentication succeeded
. -
Verify the FSBL shows
TRUSTED_BOARD_BOOT support enabled
. -
Verify the images boot up to U-Boot.
-
Make sure you have a backup of the generated PKI tree.
To close the device:
=> stm32key close
Warning: Programming fuses is an irreversible operation!
This may brick your system.
Use this command only if you are sure of what you are doing!
Really perform this fuse programming? <y/N> y
Device is closed!
After that, the device will only boot properly signed images.
Advanced options
Disable signing of images
Signing of images is automatically enabled as part of TrustFence.
To explicitly disable the generation of signed images, define TRUSTFENCE_SIGN
to 0:
# Disable signed images
TRUSTFENCE_SIGN = "0"
Use a custom PKI tree path
You can use the following parameters to customize the location of the sensitive keys:
-
TRUSTFENCE_SIGN_KEYS_PATH
: Path to a folder containing the PKI tree. If the folder does not exist or does not contain a PKI tree, a new PKI tree is generated automatically. The default value is a new foldertrustfence
in the Digi Embedded Yocto project home location.
# Use a custom path to the signature keys and certificates.
TRUSTFENCE_SIGN_KEYS_PATH = "/mnt/secure/PKI_tree"
Disable U-Boot environment encryption
To explicitly disable U-Boot environment encryption, set TRUSTFENCE_ENCRYPT_ENVIRONMENT
to 0 as follows:
# Disable U-Boot environment encryption
TRUSTFENCE_ENCRYPT_ENVIRONMENT= "0"
When flashing U-Boot without the environment encryption feature in a device with an encrypted environment, all the values will be lost. Be sure to save any important data such as MAC addresses before you execute this procedure. |