diff mbox series

[7/8] uboot-sign: add public keys to the U-Boot DTB with fdt_add_pubkey

Message ID 20261203143044.592073-8-adrian.freihofer@siemens.com
State Under Review
Headers show
Series uboot-sign: prepare for HSM-backed FIT signing | expand

Commit Message

AdrianF Dec. 3, 2026, 2:30 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

concat_dtb signed a dummy FIT image with mkimage only to get the public
keys written into the U-Boot DTB. This required the private keys in the
U-Boot build, although only the certificates are needed. With keys held
in an HSM, the U-Boot build would also need access to the HSM.

Use fdt_add_pubkey instead, which only reads <keyname>.crt and sets the
same required and algo properties. The dummy unused.itb and the
fit_check_sign self-test against it are dropped. UBOOT_MKIMAGE_SIGN_ARGS
and UBOOT_MKIMAGE_DTCOPTS no longer apply to concat_dtb.

The oe-selftest fitimage tests check the keys in the U-Boot DTB and
verify the signed kernel FIT image against it.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/classes-recipe/uboot-sign.bbclass | 61 ++++++--------------------
 meta/conf/uboot.conf                   |  3 ++
 2 files changed, 16 insertions(+), 48 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/uboot-sign.bbclass b/meta/classes-recipe/uboot-sign.bbclass
index c46a0d5f04..1aa7e04f4d 100644
--- a/meta/classes-recipe/uboot-sign.bbclass
+++ b/meta/classes-recipe/uboot-sign.bbclass
@@ -11,8 +11,7 @@ 
 # certificate in a directory and to define the following variable:
 #
 #   UBOOT_SIGN_KEYDIR = "/keys/directory"
-#   UBOOT_SIGN_KEYNAME = "dev" # keys name in keydir (eg. "dev.crt", "dev.key")
-#   UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
+#   UBOOT_SIGN_KEYNAME = "dev" # key name in keydir (eg. "dev.crt")
 #   UBOOT_SIGN_ENABLE = "1"
 #
 # As verified boot depends on fitImage generation, following is also required:
@@ -200,58 +199,24 @@  concat_dtb() {
 		# support is kept to avoid breakage of existing layers, but
 		# it is highly recommended to avoid FIT_SIGN_INDIVIDUAL = "1",
 		# i.e. set FIT_SIGN_INDIVIDUAL = "0" .
+		# Add the public keys of the kernel FIT signing keys to the
+		# U-Boot DTB. Only the certificates (<keyname>.crt) are needed.
 		if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then
-			# Sign dummy image images in order to
-			# add the image signing keys to our dtb
-			${UBOOT_MKIMAGE_SIGN} \
-				${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
-				-f auto \
+			${UBOOT_FDT_ADD_PUBKEY} \
+				-a "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
 				-k "${UBOOT_SIGN_KEYDIR}" \
-				-o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
-				-g "${UBOOT_SIGN_IMG_KEYNAME}" \
-				-K "${UBOOT_DTB_BINARY}" \
-				-d /dev/null \
-				-r ${B}/unused.itb \
-				${UBOOT_MKIMAGE_SIGN_ARGS}
+				-n "${UBOOT_SIGN_IMG_KEYNAME}" \
+				-r image \
+				"${UBOOT_DTB_BINARY}"
 		fi
 
-		# Sign dummy image configurations in order to
-		# add the configuration signing keys to our dtb
-		${UBOOT_MKIMAGE_SIGN} \
-			${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
-			-f auto-conf \
+		${UBOOT_FDT_ADD_PUBKEY} \
+			-a "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
 			-k "${UBOOT_SIGN_KEYDIR}" \
-			-o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
-			-g "${UBOOT_SIGN_KEYNAME}" \
-			-K "${UBOOT_DTB_BINARY}" \
-			-d /dev/null \
-			-r ${B}/unused.itb \
-			${UBOOT_MKIMAGE_SIGN_ARGS}
+			-n "${UBOOT_SIGN_KEYNAME}" \
+			-r conf \
+			"${UBOOT_DTB_BINARY}"
 
-		# Verify the dummy fitImage signature against u-boot.dtb
-		# augmented using public key material.
-		#
-		# This only works for FIT_SIGN_INDIVIDUAL = "0", because
-		# mkimage -f auto-conf does not support -F to extend the
-		# existing unused.itb , and instead rewrites unused.itb
-		# from scratch.
-		#
-		# Using two separate unused.itb for mkimage -f auto and
-		# mkimage -f auto-conf invocation above would not help, as
-		# the signature verification process below checks whether
-		# all keys inserted into u-boot.dtb /signature node pass
-		# the verification. Separate unused.itb would each miss one
-		# of the signatures.
-		#
-		# The FIT_SIGN_INDIVIDUAL = "1" support is kept to avoid
-		# breakage of existing layers, but it is highly recommended
-		# to not use FIT_SIGN_INDIVIDUAL = "1", i.e. set
-		# FIT_SIGN_INDIVIDUAL = "0" .
-		if [ "${FIT_SIGN_INDIVIDUAL}" != "1" ] ; then
-			${UBOOT_FIT_CHECK_SIGN} \
-				-k "${UBOOT_DTB_BINARY}" \
-				-f ${B}/unused.itb
-		fi
 		cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED}
 	fi
 
diff --git a/meta/conf/uboot.conf b/meta/conf/uboot.conf
index 01e0b6cc7e..e08a3c46bb 100644
--- a/meta/conf/uboot.conf
+++ b/meta/conf/uboot.conf
@@ -32,3 +32,6 @@  SPL_MKIMAGE_SIGN_ARGS ?= ""
 
 # uboot-fit_check_sign command
 UBOOT_FIT_CHECK_SIGN ?= "uboot-fit_check_sign"
+
+# uboot-fdt_add_pubkey command, adds the public keys (.crt) to the U-Boot DTB
+UBOOT_FDT_ADD_PUBKEY ?= "uboot-fdt_add_pubkey"