<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dh-electronics.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Dkierner</id>
	<title>Wiki-DB - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dh-electronics.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Dkierner"/>
	<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=Special:Contributions/Dkierner"/>
	<updated>2026-04-27T19:41:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3658</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3658"/>
		<updated>2022-03-22T12:24:39Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Undo revision 3657 by Dkierner (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
* swig&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add STM32CubeProrammer binaries to user environment ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
export PATH=${PATH}:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without errors, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3657</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3657"/>
		<updated>2022-03-22T12:01:40Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Add separate out directory for the STM32_MP_SigningTool_CLI instruction /* Sign U-Boot SPL with STM32MP_SigningTool_CLI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
* swig&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add STM32CubeProrammer binaries to user environment ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
export PATH=${PATH}:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without errors, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mkdir out&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output out/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3656</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3656"/>
		<updated>2022-03-22T11:55:09Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Add instruction for adding the STM32CubeProgrammer tools to the user PATH-variable /* Tutorial: Secure boot from BootROM to Linux with basic boot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
* swig&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add STM32CubeProrammer binaries to user environment ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
export PATH=${PATH}:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without errors, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3655</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3655"/>
		<updated>2022-03-22T11:20:39Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix plural in /* Run the build script build_signed_uboot.sh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
* swig&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without errors, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3654</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3654"/>
		<updated>2022-03-22T11:18:37Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Add swig to required debian packages /* System requirements and needed tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
* swig&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3653</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3653"/>
		<updated>2022-03-22T11:12:33Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix branch name in &amp;quot;git clone&amp;quot; command /* Checkout source code for Verified Boot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_stm32mp1_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3652</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3652"/>
		<updated>2022-03-22T10:52:45Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix prepositions in /* Program publicKeyhash.bin into OTP with stm32key command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; per TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3651</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3651"/>
		<updated>2022-03-22T10:49:47Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix plural of SoC /* Write U-Boot SPL and U-Boot to your boot media */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoCs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3650</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3650"/>
		<updated>2022-03-22T10:39:45Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Replace example password with a reminder to use a secure password /* Sign U-Boot SPL with STM32MP_SigningTool_CLI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password &amp;lt;a secure password&amp;gt; --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3649</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3649"/>
		<updated>2022-03-22T10:36:11Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Replace example password with a reminder to use a secure password /* Generate key pair with STM32MP_KeyGen_CLI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password &amp;lt;a secure password&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3648</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3648"/>
		<updated>2022-03-22T10:31:47Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Reword /* Generate key pair with STM32MP_KeyGen_CLI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoCs only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate a ECDSA key pair for the STM32MP Secure Boot use the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3647</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3647"/>
		<updated>2022-03-22T10:23:27Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix contact info /* Run the build script build_signed_uboot.sh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with [mailto:info@dh-electronics.com us] and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3646</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3646"/>
		<updated>2022-03-22T10:19:12Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix preposition in /* Checkout source code for Verified Boot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; in my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3645</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3645"/>
		<updated>2022-03-22T10:04:59Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Correct full stop to colon in: /* Run the build script build_signed_uboot.sh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix:&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3644</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3644"/>
		<updated>2022-03-22T09:53:35Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Fix links to /* Verified Boot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#Verified Boot|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3643</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3643"/>
		<updated>2022-03-22T09:34:20Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Shorten title of /* What does Secure Boot mean? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#What is meant by Verified Boot?|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#What is meant by Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3642</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3642"/>
		<updated>2022-03-22T09:29:14Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Improve wording of /* What is meant by Verified Boot? */ including title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== What does Secure Boot mean? ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#What is meant by Verified Boot?|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#What is meant by Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== Verified Boot ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes care the signature creation for the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3641</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3641"/>
		<updated>2022-03-22T09:08:52Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Add TF-A and OP-TEE to section /* Abbreviations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| OP-TEE || Open Portable Trusted Execution Environment&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|-&lt;br /&gt;
| TF-A || Trusted Firmware A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== What does Secure Boot mean? ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#What is meant by Verified Boot?|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#What is meant by Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== What is meant by Verified Boot? ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes over the creation of the signatures in the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with the included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3640</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3640"/>
		<updated>2022-03-22T09:06:33Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Improve wording and correct grammar issue in section /* What is meant by Secure Boot with basic/trusted boot? */ including headline&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== What does Secure Boot mean? ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== Basic and trusted boot in the context of Secure Boot ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#What is meant by Verified Boot?|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#What is meant by Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== What is meant by Verified Boot? ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes over the creation of the signatures in the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with the included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
	<entry>
		<id>https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3639</id>
		<title>DHCOM STM32MP15 Secure Boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&amp;diff=3639"/>
		<updated>2022-03-22T09:00:50Z</updated>

		<summary type="html">&lt;p&gt;Dkierner: Improve wording of section &amp;quot;What is meant by Secure Boot?&amp;quot; including headline&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
https://wiki.dh-electronics.com/index.php?title=DHCOM_STM32MP15_Secure_Boot&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--http://automaten-karl.de/blog/?p=74--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Template:TOC--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:$wgAllowUserCss--&amp;gt;&lt;br /&gt;
&amp;lt;!--https://www.mediawiki.org/wiki/Manual:CSS--&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;toclimit-3&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Abbreviations ===&lt;br /&gt;
&amp;lt;!--TODO: Check for non listed/used abbreviation--&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Abbreviation !! Description&lt;br /&gt;
|-&lt;br /&gt;
| BSI || Bundesamt für Sicherheit in der Informationstechnik&lt;br /&gt;
|-&lt;br /&gt;
| CoM || Computer on module&lt;br /&gt;
|-&lt;br /&gt;
| FIT || Flattened Image Tree&lt;br /&gt;
|-&lt;br /&gt;
| FSBL || Fist Stage Bootloader (TF-A or U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| OTP || One Time Programmable (eFuses)&lt;br /&gt;
|-&lt;br /&gt;
| PKH || Public Key Hash&lt;br /&gt;
|-&lt;br /&gt;
| ROM || Read-Only Memory&lt;br /&gt;
|-&lt;br /&gt;
| RSA || Rivest, Shamir und Adleman (asynchronous encryption)&lt;br /&gt;
|-&lt;br /&gt;
| SHA || Secure Hash Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| SoC || System on chip&lt;br /&gt;
|-&lt;br /&gt;
| SoM || System on module&lt;br /&gt;
|-&lt;br /&gt;
| SSBL || Second Stage Bootloader (U-Boot)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== What does Secure Boot mean? ===&lt;br /&gt;
&lt;br /&gt;
The term Secure Boot originally comes from the UEFI specification&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot; /&amp;gt; and describes a secure boot process in which only signed software is loaded and executed during the boot process.&lt;br /&gt;
&lt;br /&gt;
Secure Boot is a necessary cornerstone for enforcing security mechanisms in a trusted computing environment.&lt;br /&gt;
Enforcing the execution of signed software only during the boot process, as long as the chain of trust is secure, can guarantee that said software is free from tampering, as any manipulation will invalidate the software&#039;s signature and prevent the software from being executed.&lt;br /&gt;
&lt;br /&gt;
[[File:Secure Boot Generic en.png|600px|Secure Boot Generic]]&lt;br /&gt;
&lt;br /&gt;
The figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]] shows an example of a secure boot process that leads to a reset in the event of an error in the signature check. Each stage uses the certificate and signature to check the origin and integrity of the next stage. On success, the next stage is executed, and in the event of an error, this always leads to a defined error state. In the simplest case, the certificates are integrated into the binary image of the previous stage.&lt;br /&gt;
&lt;br /&gt;
Program code and certificate need to be trustworthy and therefore protected against tampering in each stage, otherwise the secure boot chain can be compromised. Except for the first stage, all binary images are protected against third-party tampering by the signature. As this is practically impossible for the first stage, manipulation protection has to be enforced by hardware measures to make said stage immutable, with the first stage&#039;s program code and the verification certificate for the second stage being stored in read-only memory (ROM).&lt;br /&gt;
&lt;br /&gt;
=== What is meant by Secure Boot with basic/trusted boot? ===&lt;br /&gt;
&lt;br /&gt;
When booting Linux on the STM32MP1 SoC&#039;s with U-Boot SPL and U-Boot only, STM speaks of &amp;quot;Basic Boot&amp;quot;&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
However, if Linux is booted with a combination of TF-A, U-Boot and OP-TEE, STM refers to this as &amp;quot;Trusted Boot&amp;quot;&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Boot chain !! Description&lt;br /&gt;
|-&lt;br /&gt;
| Basic boot || BootROM -&amp;gt; U-Boot SPL -&amp;gt; U-Boot -&amp;gt; Linux&lt;br /&gt;
|-&lt;br /&gt;
| Trusted boot || BootROM -&amp;gt; TF-A -&amp;gt; U-Boot + OP-TEE -&amp;gt; Linux&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Basic Boot with BootROM authentication and Verified Boot ==&lt;br /&gt;
&lt;br /&gt;
This Secure Boot implementation does use the the BootROM integrated image authentication to authenticate the U-Boot SPL as FSBL.&lt;br /&gt;
Authentication of U-Boot as SSBL by the U-Boot SPL and authentication of the Linux kernel, Device Tree and ramdisk by U-Boot is done using the open source implementation [[#What is meant by Verified Boot?|Verified Boot]].&lt;br /&gt;
&amp;lt;!--The authentication of U-Boot as an SSBL image and the Linux kernel, Device Tree and ramdisk is done by the open source [[#What is meant by Verified Boot?|Verified Boot]] implementation of U-Boot itself.--&amp;gt;&lt;br /&gt;
This also means that everything from U-Boot SPL onwards is platform independent, as we do not rely on hardware specific implementations.&lt;br /&gt;
&lt;br /&gt;
=== What is meant by Verified Boot? ===&lt;br /&gt;
&lt;br /&gt;
Developers of Google&#039;s Chromium project worked out a concept for the Verified Boot called Secure Boot mechanism on the basis of the boot loader &amp;quot;Das U-Boot&amp;quot;.&lt;br /&gt;
They use the existing infrastructure of the FIT images and for the system configuration at runtime via a Device Tree.&lt;br /&gt;
The description language for the FIT images was extended by an additional signature node and the Device Tree of the platform was used to store the certificate(s) for the authentication of the images.&lt;br /&gt;
The signature node can be used to sign individual subimages as well as combinations of individual subimages in the FIT image.&lt;br /&gt;
The tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; takes over the creation of the signatures in the FIT images and the addition of the certificate in a Device Tree.&lt;br /&gt;
&lt;br /&gt;
With Verified Boot, the Device Tree with the included public key is integrated into the program image of the stage, which accomplishes the authentication and is thus very similar to the general procedure shown in figure [[Media:Secure Boot Generic en.png|Secure Boot Generic]].&lt;br /&gt;
The number of public keys that can be integrated is theoretically unlimited, but they must be distinguishable by name.&lt;br /&gt;
&lt;br /&gt;
==== Technical details of Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Name&#039;&#039;&#039;&lt;br /&gt;
| Verified Boot&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Implementierung&#039;&#039;&#039;&lt;br /&gt;
| Software (Open Source)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Hash algorithms&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
* SHA1 (deprecated)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* SHA256&lt;br /&gt;
* SHA384&lt;br /&gt;
* SHA512&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Crypto algorithms&lt;br /&gt;
|&lt;br /&gt;
* RSA2048 (deprecated as of 2024)&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot; /&amp;gt;&lt;br /&gt;
* RSA4096&lt;br /&gt;
&amp;lt;!--TODO: Mention ECDSA limitations--&amp;gt;&lt;br /&gt;
* ECDSA256 (currently limited to U-Boot SPL)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Number of key pairs&#039;&#039;&#039;&lt;br /&gt;
| unlimited&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== In-depth references for Verified Boot ====&lt;br /&gt;
&amp;lt;!--TODO: Use &amp;lt;references group=&amp;quot;XYZ&amp;quot;&amp;gt;&amp;lt;ref group=&amp;quot;A&amp;quot; name=&amp;quot;O&amp;quot;&amp;gt;ABCDEF&amp;lt;/ref&amp;gt;&amp;lt;/references&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Flatten Image Tree =====&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT U-Boot Documentation: doc/uImage.FIT]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/d5934ad7 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add dual format uImage support framework&amp;quot;]&lt;br /&gt;
* ...&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3310c549 U-Boot Commit d5934ad7: &amp;quot;new uImage: Add new uImage format documentation and examples&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== Verified Boot =====&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/tree/master/doc/uImage.FIT/signature.txt U-Boot Documentation: doc/uImage.FIT/signature.txt]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/3e569a6b U-Boot Commit 3e569a6b: &amp;quot;image: Add signing infrastructure&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/56518e71 U-Boot Commit 56518e71: &amp;quot;image: Support signing of images&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/4d098529 U-Boot Commit 4d098529: &amp;quot;image: Add support for signing of FIT configurations&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===== ECDSA signature verification =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Mention ECDSA limitations&amp;lt;/div&amp;gt;&lt;br /&gt;
Note: This has currently some limitations!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;references group=&amp;quot;Verified Boot ECDSA&amp;quot;&amp;gt;--&amp;gt;&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/928a8be7 U-Boot Commit 928a8be7: &amp;quot;lib: ecdsa: Implement UCLASS_ECDSA verification on target&amp;quot;]&lt;br /&gt;
* [https://source.denx.de/u-boot/u-boot/-/commit/ee870859 U-Boot Commit ee870859: &amp;quot;arm: stm32mp1: Implement ECDSA signature verification&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
=== Tutorial: Secure boot from BootROM to Linux with basic boot ===&lt;br /&gt;
&lt;br /&gt;
==== System requirements and needed tools ====&lt;br /&gt;
&lt;br /&gt;
The following table lists all requirements to create the key pairs and build the signed images with embedded public keys.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Category !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Host operating system&#039;&#039;&#039; ||&lt;br /&gt;
* Linux (Debian 9, Ubuntu 18.04 or higher prefered)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;Debian packages&#039;&#039;&#039; ||&lt;br /&gt;
* bison&lt;br /&gt;
* device-tree-compiler&lt;br /&gt;
* flex&lt;br /&gt;
* gcc-arm-linux-gnueabihf (&amp;gt;= gcc 6)&lt;br /&gt;
* git&lt;br /&gt;
* make&lt;br /&gt;
* openssl&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;STM32 Tools&#039;&#039;&#039; ||&lt;br /&gt;
* [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer]&lt;br /&gt;
** STM32MP_KeyGen_CLI&lt;br /&gt;
** STM32MP_SigningTool_CLI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Should we give host setup instructions?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&#039;&#039;&#039;Install debian packages:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install bison device-tree-compiler flex gcc-arm-linux-gnueabihf git make openssl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download and install STM32CubeProgrammer:&#039;&#039;&#039; [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubeProgrammer].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Intended use of the four generated key pairs ====&lt;br /&gt;
&lt;br /&gt;
We&#039;ve decided to create and use as few certificates as reasonable to ensure a high level of security.&lt;br /&gt;
Therefore, we chose a separate key pair for each boot stage and also a separate key pair for image and configuration nodes.&lt;br /&gt;
If you&#039;re confused about the difference between image and configuration nodes, head over to [[#Flatten Image Tree|Flatten Image Tree]] to refresh your knowledge.&lt;br /&gt;
The exact purpose of the four key pairs generated for Verified Boot is described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Intended use&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot SPL (U-Boot, Device Tree, firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;fsbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot SPL (U-Boot + Device Tree + firmware)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-img&#039;&#039;&#039; || Authenticate image nodes of FIT images loaded by U-Boot (Kernel, Device Tree, InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
| &#039;&#039;&#039;ssbl-cfg&#039;&#039;&#039; || Authenticate config nodes of FIT images loaded by U-Boot (Kernel + Device Tree + InitRamFS)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Created/Modified files in the U-Boot source for Verified Boot ====&lt;br /&gt;
&lt;br /&gt;
The created or modified files to build U-Boot with Verified Boot on STM32MP15 are described in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| build_signed_uboot.sh&lt;br /&gt;
| Shell script that automates the creation of key pairs, the modification of FIT source files and Device Tree&#039;s and building of U-Boot SPL and U-Boot.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/u-boot-dhco?.its&lt;br /&gt;
| FIT source files with defined U-Boot image and Device Tree&#039;s for DHSOM platforms.&lt;br /&gt;
|-&lt;br /&gt;
| board/dhelectronics/dh_stm32mp1/linux-dhcom.its&lt;br /&gt;
| Dummy FIT source file with defined dummy kernel image and dummy Device Tree for DHSOM platforms.&amp;lt;br&amp;gt;To avoid relying on a built kernel image on a fixed path, we created this dummy, since adding the public keys with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;mkimage&amp;lt;/syntaxhighlight&amp;gt; requires a valid FIT source file.&lt;br /&gt;
|-&lt;br /&gt;
| configs/stm32mp15_dhco?_secure_defconfig&lt;br /&gt;
| Example U-Boot defconfig&#039;s with enabled &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;CONFIG_SPL_FIT_SIGNATURE&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Build Verified Boot enabled U-Boot SPL and U-Boot ====&lt;br /&gt;
&lt;br /&gt;
To build the U-Boot SPL and U-Boot images, you need to check out the source code and run a build script that automates everything from key generation to image creation and signing.&lt;br /&gt;
&lt;br /&gt;
===== Checkout source code for Verified Boot =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: Replace my personal GitLab by a public available repository&amp;lt;/div&amp;gt;&lt;br /&gt;
Checkout the branch &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;v2022.01_dhcom_secure_boot&amp;lt;/syntaxhighlight&amp;gt; of my personal GitLab repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@dhplgl01:jneuhauser/u-boot.git -b v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have a cloned U-Boot source code, you can also fetch it into your existing repository with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
git remote add jneuhauser git@dhplgl01:jneuhauser/u-boot.git&lt;br /&gt;
git fetch jneuhauser&lt;br /&gt;
git checkout v2022.01_dhcom_secure_boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Run the build script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; included in the U-Boot source performs the following steps.&lt;br /&gt;
# Prebuild U-Boat SPL and U-Boat to build the required tools and Device Tree&#039;s&lt;br /&gt;
# Generate the [[#Intended use of the four generated key pairs|four key pairs]] if not already created&lt;br /&gt;
# Generate/Modify FIT image source files for Linux (dummy) and U-Boot&lt;br /&gt;
# Add public keys to the built Device Tree&#039;s used by U-Boot SPL and U-Boot&lt;br /&gt;
# Rebuild U-Boot SPL and U-Boot with new Device Tree&#039;s containing the public keys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The script supports the following environment variables to configure the target architecture, the cross compiler, the defconfig, the key algorithm, the key directory, and a key postfix.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Description !! Default&lt;br /&gt;
|-&lt;br /&gt;
| ARCH || Target architecture for the U-Boot build || arm&lt;br /&gt;
|-&lt;br /&gt;
| CROSS_COMPILE || Used cross compiler to build U-Boot || arm-linux-gnueabihf-&lt;br /&gt;
|-&lt;br /&gt;
| DEFCONFIG || Used defconfig for the U-Boot build || stm32mp15_dhcom_secure_defconfig&lt;br /&gt;
|-&lt;br /&gt;
| KEY_ALGO || Signature algorithm used for Verified Boot || rsa&lt;br /&gt;
|-&lt;br /&gt;
| KEY_DIR || Directory where the key pairs are stored || ../keys&lt;br /&gt;
|-&lt;br /&gt;
| KEY_POSTFIX || Postfix which is appended to the key names || -$(date +%F)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To perform the steps mentioned above, you just need to run the shell script &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;build_signed_uboot.sh&amp;lt;/syntaxhighlight&amp;gt; like below.&lt;br /&gt;
In this example, we override the default value for &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;KEY_POSTFIX&amp;lt;/syntaxhighlight&amp;gt; with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;-testing&amp;lt;/syntaxhighlight&amp;gt; to append this string to the [[#Intended use of the four generated key pairs|four key file names]].&lt;br /&gt;
The script has debug output enabled by default, which should output all the statements in the script itself and the output of the commands used in the script.&lt;br /&gt;
If you have any problems with the script, feel free to get in touch with the script author [mailto:jneuhauser@dh-electronics.com Johann Neuhauser]  and attach a logfile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
cd /path/to/u-boot&lt;br /&gt;
KEY_POSTFIX=&amp;quot;-testing&amp;quot; ./build_signed_uboot.sh | tee build_signed_uboot.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this process completes without error, there are two boot loader images in the root directory of the U-Boot source.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name !! Stage !! Description&lt;br /&gt;
|-&lt;br /&gt;
| u-boot-spl.stm32 || FSBL || U-Boot SPL binary with appended Device Tree and prepended STM32 image header&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot; /&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u-boot.itb || SSBL || U-Boot and Device Tree&#039;s contained in a signed FIT image.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Generate key pair and sign U-Boot SPL for BootROM authentication ====&lt;br /&gt;
&lt;br /&gt;
To sign the U-Boot SPL as SSBL image for authentication with the BootROM we have to use the STM32 tools &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== Generate key pair with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
All STM32MP15 SoC&#039;s only support one key pair for authenticating images through the BootROM.&lt;br /&gt;
To generate ECDSA key pairs for the STM32MP Secure Boot we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_KeyGen_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot; /&amp;gt; to generate a single key pair.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_KeyGen_CLI --absolute-path &amp;quot;$(pwd)&amp;quot; --password 12345678&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Key Generator v2.9.0                              &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 AES_256_cbc algorithm is selected for private key encryption&lt;br /&gt;
 Generating Prime256v1 keys... &lt;br /&gt;
 Private key PEM file created &lt;br /&gt;
 Public key PEM file created &lt;br /&gt;
 public key hash file created &lt;br /&gt;
 Keys generated successfully.&lt;br /&gt;
 + public key:       publicKey.pem&lt;br /&gt;
 + private key:      privateKey.pem&lt;br /&gt;
 + public hash key:  publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sign U-Boot SPL with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
To add the public key and the image signature to our built U-Boot SPL binary with STM32 image header, we are using the tool &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;STM32MP_SigningTool_CLI&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot; /&amp;gt; to update the existing STM32 image header of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; with the required details.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --binary-image /path/to/u-boot/u-boot-spl.stm32 --public-key publicKey.pem --private-key privateKey.pem --password 12345678 --output /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 Prime256v1 curve is selected. &lt;br /&gt;
 Header version 1 preparation ... &lt;br /&gt;
 Reading Private Key File... &lt;br /&gt;
 ECDSA signature generated.&lt;br /&gt;
 Signature verification:  SUCCESS &lt;br /&gt;
 The Signed image file generated successfully:  /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check the STM32 image header details with:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
STM32MP_SigningTool_CLI --dump-header /path/to/u-boot/u-boot-spl.stm32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
                       STM32MP Signing Tool v2.9.0                     &lt;br /&gt;
       -------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Header description:&lt;br /&gt;
&lt;br /&gt;
    Magic: 0x53544d32&lt;br /&gt;
    Signature: c8 30 a0 62 2d 6d 4e 1b b9 f7 fe 38 27 65 e0 44 f0 f5 9d e6 8a a6 02 cb 74 52 26 9c 1e e9 07 17 &lt;br /&gt;
               1a c7 da 8e 96 fa 82 d3 b1 dc d5 3a 05 0e 87 83 94 4d 47 ad 17 07 88 0d b5 ae 2e 38 1d 90 22 ad &lt;br /&gt;
    Checksum: 0xa8ca85&lt;br /&gt;
    Header version: 0x10000&lt;br /&gt;
    Size: 0x22dec&lt;br /&gt;
    Load address: 0x2ffc2500&lt;br /&gt;
    Entry point: 0x2ffc2500&lt;br /&gt;
    Image version: 0x0&lt;br /&gt;
    Option flags: 0x0&lt;br /&gt;
    ECDSA Algo: 0x1&lt;br /&gt;
    ECDSA pub key: 3b 71 8e 59 f1 ee 4c a8 4b 72 5f 4a 1c 63 8b 6e b8 01 ec 1a 3f 8c 98 2f d2 1d 77 f9 09 10 8f 04 &lt;br /&gt;
                   30 da 5c 3a 24 53 0d 71 93 f0 a5 d9 c9 a7 27 b4 5f a5 c4 4d 55 8b 7a 25 e3 03 ef ca 87 ff 04 25 &lt;br /&gt;
    Binary type: 0x0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The difference to an unsigned STM32 image header is that the values for &amp;quot;Signature&amp;quot; and &amp;quot;ECDSA pub key&amp;quot; are not all zeros and that &amp;quot;Option flags&amp;quot; is 0x0 for enabled signature verification instead of 0x1 for disabled signature verification.&lt;br /&gt;
&lt;br /&gt;
==== Write U-Boot SPL and U-Boot to your boot media ====&lt;br /&gt;
&lt;br /&gt;
The first step to verify that the built U-Boot SPL and U-Boot works as expected is to program both images to your boot media.&lt;br /&gt;
Depending on the boot configuration, your DHSOM will boot from the module&#039;s SPI-NOR flash, from the module&#039;s or baseboard&#039;s eMMC or from an SD card.&lt;br /&gt;
The boot configuration is always defined by the boot pins by default, because the boot pins have no alternative function on the STM32MP15 SoC&#039;s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How can a user determine the used boot media?&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO: How to enforce boot media on Secure Boot enabled devices?&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the SPI-NOR flash of the SoM =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; calculate some addresses based on the image offsets expected by the BootROM, load the required images from SD card or via TFTP into memory and finally write the prepared memory into the SPI-NOR flash on the SoM.&lt;br /&gt;
&lt;br /&gt;
Prepare for loading &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; into memory:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mw.b ${loadaddr} 0xff 0x200000&lt;br /&gt;
setexpr fsbl1addr ${loadaddr} + 0x0&lt;br /&gt;
setexpr fsbl2addr ${loadaddr} + 0x40000&lt;br /&gt;
setexpr ssbl1addr ${loadaddr} + 0x80000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${fsbl1addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${fsbl2addr} u-boot-spl.stm32&lt;br /&gt;
load mmc 0:4 ${ssbl1addr} u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; from tftp server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${fsbl1addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${fsbl2addr} ${serverip}:u-boot-spl.stm32&lt;br /&gt;
tftp ${ssbl1addr} ${serverip}:u-boot.itb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check for magic numbers of expected image headers and conditionally program the SPI-NOR flash:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
if itest *${fsbl1addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${fsbl2addr} == 0x324d5453 &amp;amp;&amp;amp; itest *${ssbl1addr} == 0xedfe0dd0; then&lt;br /&gt;
  sf probe &amp;amp;&amp;amp; sf update ${loadaddr} 0 0x200000&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to an SD card =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Make on module SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make on baseboard SD card of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Write U-Boot SPL and U-Boot to the eMMC =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Write &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot-spl.stm32&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;u-boot.itb&amp;lt;/syntaxhighlight&amp;gt; to eMMC boot hardware partition:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
mmc dev 1 1&lt;br /&gt;
mmc write X X X&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make eMMC of STM32MP15xx on PDK2 with cmd &amp;quot;ums&amp;quot; available per USB-OTG-Port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
usb start&lt;br /&gt;
ums 0 mmc 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enroll, test and enforce BootROM image authentication ====&lt;br /&gt;
&lt;br /&gt;
To enroll, test and enforce image authentication by the BootROM you need to program the PKH into the OTP of the STM32MP15 SoC.&lt;br /&gt;
The &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; file that you created in the [[#Generate key pair with STM32MP_KeyGen_CLI|Generate key pair with STM32MP_KeyGen_CLI]] step contains the PKH in binary format for use with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; U-Boot command.&lt;br /&gt;
If the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command does fail or is not available on the target U-Boot, you can also write the PKH manually with the more generic &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command into the OTP.&lt;br /&gt;
&lt;br /&gt;
===== Program public key hash to eFuses =====&lt;br /&gt;
&lt;br /&gt;
The following &#039;&#039;&#039;commands for the U-Boot Shell&#039;&#039;&#039; load the file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into memory and program the contained PKH to the OTP of the STM32MP15 SoC.&lt;br /&gt;
The used command &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; writes and locks the words of the OTP automatically without knowing anything about the OTP layout/addresses.&lt;br /&gt;
If this fails or the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command is not available, you can also write and lock the OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command &lt;br /&gt;
&lt;br /&gt;
====== Program &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command ====== &lt;br /&gt;
&lt;br /&gt;
Load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by SD card:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
load mmc 0:4 ${loadaddr} publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or load &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; by TFTP:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
setenv serverip 10.20.30.1&lt;br /&gt;
setenv ipaddr 10.20.30.100&lt;br /&gt;
setenv netmask 255.255.255.0&lt;br /&gt;
tftp ${loadaddr} ${serverip}:publicKeyhash.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key read ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
Read KEY at 0xc2000000&lt;br /&gt;
OTP value 24: 4e31bbcd&lt;br /&gt;
OTP value 25: 51e827dd&lt;br /&gt;
OTP value 26: 3511f521&lt;br /&gt;
OTP value 27: fd9c11a2&lt;br /&gt;
OTP value 28: 5b997b82&lt;br /&gt;
OTP value 29: 8150adc5&lt;br /&gt;
OTP value 30: a9c68fa9&lt;br /&gt;
OTP value 31: 72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the contents of &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; to OTP with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key fuse ${loadaddr}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
TODO: Add output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Program PKH manually into OTP with &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command ======&lt;br /&gt;
&lt;br /&gt;
Generate fuse command with hexdump from file &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;publicKeyhash.bin&amp;lt;/syntaxhighlight&amp;gt; on linux host:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example output! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
echo fuse prog -y 0 0x18 $(hexdump -e &#039;/4 &amp;quot;0x&amp;quot;&#039; -e &#039;/1 &amp;quot;%x&amp;quot;&#039; -e &#039;&amp;quot; &amp;quot;&#039; /path/to/publicKeyhash.bin)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Write the PKH into OTP manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: Do not use the example command! Only use your unique values for programming the PKH in the OTP!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x18 0x4e31bbcd 0x51e827dd 0x3511f521 0xfd9c11a2 0x5b997b82 0x8150adc5 0xa9c68fa9 0x72a3ba74&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lock the related OTP words manually with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog -y 0 0x10000018 1 1 1 1 1 1 1 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Test BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
To verify the image authentication by the BootROM with the programmed PKH and the programmed signed images, you must reboot your device.&lt;br /&gt;
&lt;br /&gt;
On the third line of the U-Boot SPL output, check the BootROM authentication status.&lt;br /&gt;
The status output should look like this: &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;Bootrom authentication: succeeded&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
Note the &amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; inline&amp;gt;succeeded&amp;lt;/syntaxhighlight&amp;gt; status for successful authentication of the U-Boot SPL image by the BootROM.&lt;br /&gt;
&lt;br /&gt;
The following output shows successful authentication of the U-Boot-SPL image in line 3, as well as successful authentication of the used configuration in line 7 and the U-Boot and Device Tree subimages in lines 8 and 9 of the U-Boot-FIT image.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot; line highlight=&amp;quot;3,7-9&amp;quot;&amp;gt;&lt;br /&gt;
U-Boot SPL 2022.01-00012-g6c5892c90c28 (Feb 16 2022 - 11:11:16 +0100)&lt;br /&gt;
Model: STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit (2)&lt;br /&gt;
Bootrom authentication: succeeded&lt;br /&gt;
Code:  SoM:rev=1,ddr3=3 Board:rev=0&lt;br /&gt;
RAM: DDR3L 32bits 2x4Gb 533MHz&lt;br /&gt;
Trying to boot from SPI&lt;br /&gt;
## Checking hash(es) for config config-2 ... sha256,rsa4096:fsbl-cfg-2022-02-16+ OK&lt;br /&gt;
## Checking hash(es) for Image uboot ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
## Checking hash(es) for Image fdt-1 ... sha256,rsa4096:fsbl-img-2022-02-16+ sha256+ OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Enforce BootROM image authentication =====&lt;br /&gt;
&lt;br /&gt;
Without any further changes, the BootROM is able to perform authentication of the FSBL image, but unauthenticated images can still be used and executed.&lt;br /&gt;
The device is still open, let&#039;s see this as a kind of test mode to check if the PKH is set correctly.&lt;br /&gt;
&lt;br /&gt;
Once the authentication process is confirmed, the device can be closed and the user is forced to use signed images.&lt;br /&gt;
&lt;br /&gt;
The 6th bit in the 1st word of the OTP is responsible that the BootROM only accepts signed images.&lt;br /&gt;
Burning this bit enforces authentication of images by the BootROM and unsigned binaries are no longer supported on the target device.&lt;br /&gt;
&lt;br /&gt;
To program this bit, the U-Boot Shell can be used with the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command or with the more general &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
With usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;stm32key&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
stm32key close&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or with usage of the &amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot; inline&amp;gt;fuse&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;Warning: After running the following command, your device will only be able to boot signed images!&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
fuse prog 0 0x0 0x40&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure Boot in Trusted Boot with BootROM authentication, TF-A and OP-TEE ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;TODO:&amp;lt;/div&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;TF-A&amp;quot; /&amp;gt;&lt;br /&gt;
# Add support for STM32MP15 DHCOM in &amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot; /&amp;gt;&lt;br /&gt;
# Create stm32mp15_dhcom_trusted_defconfig???&lt;br /&gt;
# Integrate STM32MP15 DHCOM into &amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UEFI specification&amp;quot;&amp;gt;[http://www.uefi.org/specifications http://www.uefi.org/specifications]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Basic Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_basic_defconfig U-Boot Source stm32mp15_basic_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Trusted Boot&amp;quot;&amp;gt;[https://source.denx.de/u-boot/u-boot/-/blob/master/configs/stm32mp15_trusted_defconfig U-Boot Source stm32mp15_trusted_defconfig]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;BSI TR-02102&amp;quot;&amp;gt;[https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf BSI - Technische Richtlinie, &amp;quot;Kryptographische Algorithmen und Schlüssellängen&amp;quot;, BSI TR-02102-1]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;STM32 image header&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/STM32_header_for_binary_files STM32 header for binary files]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;KeyGen_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/KeyGen_tool STM32MP KeyGen tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Signing_tool&amp;quot;&amp;gt;[https://wiki.st.com/stm32mpu/wiki/Signing_tool STM32MP Signing tool]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;TF-A&amp;quot;&amp;gt;[https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/ Trusted Firmware-A (TF-A)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/optee_os&amp;quot;&amp;gt;[https://github.com/OP-TEE/optee_os OP-TEE Trusted OS]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;OP-TEE/build&amp;quot;&amp;gt;[https://github.com/OP-TEE/build Makefiles to use OP-TEE on various platforms]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Dkierner</name></author>
	</entry>
</feed>