diff mbox series

[5/8] uboot.conf, image-fitimage.conf: add FIT signing key name defaults

Message ID 20261203143044.592073-6-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>

UBOOT_SIGN_KEYNAME and UBOOT_SIGN_IMG_KEYNAME had no default, so signing
without setting them used an empty key name. Default them to
"fit-conf-key" and "fit-img-key" in conf/uboot.conf, so U-Boot, the kernel
and kernel-signing-keys-native all agree on the key names.

Move the FIT_KERNEL_SIGN_* defaults from kernel-fit-image.bbclass to
conf/image-fitimage.conf and require conf/uboot.conf in
kernel-signing-keys-native, so the key recipe sees the same values as the
kernel. Add FIT_KERNEL_SIGN_IMG_KEYNAME, used by the kernel instead of
UBOOT_SIGN_IMG_KEYNAME, so the kernel's image key can be set independently
of U-Boot.

The selftests now read the FIT_KERNEL_SIGN_* variables, which are what
kernel-fit-image actually uses.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/classes-recipe/kernel-fit-image.bbclass  |  6 +----
 meta/conf/image-fitimage.conf                 |  8 ++++++
 meta/conf/uboot.conf                          |  8 ++++++
 meta/lib/oeqa/selftest/cases/fitimage.py      | 27 ++++++++++---------
 .../kernel-signing-keys-native.bb             |  1 +
 5 files changed, 33 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass
index 3098573560..6cfb049b9b 100644
--- a/meta/classes-recipe/kernel-fit-image.bbclass
+++ b/meta/classes-recipe/kernel-fit-image.bbclass
@@ -51,10 +51,6 @@  INITRAMFS_DEPLOY_DIR_IMAGE ?= "${DEPLOY_DIR_IMAGE}"
 UBOOT_MKIMAGE_KERNEL_TYPE ?= "kernel"
 KERNEL_IMAGEDEST ?= "/boot"
 
-FIT_KERNEL_SIGN_ENABLE ?= "${UBOOT_SIGN_ENABLE}"
-FIT_KERNEL_SIGN_KEYNAME ?= "${UBOOT_SIGN_KEYNAME}"
-FIT_KERNEL_SIGN_KEYDIR ?= "${UBOOT_SIGN_KEYDIR}"
-
 def apply_dtbvendored(d,dtb):
     if d.getVar('KERNEL_DTBVENDORED') != "1":
         mapped_name = os.path.basename(dtb)
@@ -84,7 +80,7 @@  python do_compile() {
         d.getVar("UBOOT_MKIMAGE_SIGN"), d.getVar("UBOOT_MKIMAGE_SIGN_ARGS"),
         d.getVar('FIT_HASH_ALG'), d.getVar('FIT_SIGN_ALG'), d.getVar('FIT_PAD_ALG'),
         d.getVar('FIT_KERNEL_SIGN_KEYNAME'),
-        oe.types.boolean(d.getVar('FIT_SIGN_INDIVIDUAL')), d.getVar('UBOOT_SIGN_IMG_KEYNAME')
+        oe.types.boolean(d.getVar('FIT_SIGN_INDIVIDUAL')), d.getVar('FIT_KERNEL_SIGN_IMG_KEYNAME')
     )
 
     # Prepare a kernel image section.
diff --git a/meta/conf/image-fitimage.conf b/meta/conf/image-fitimage.conf
index 24a2458cc9..e712e8bae5 100644
--- a/meta/conf/image-fitimage.conf
+++ b/meta/conf/image-fitimage.conf
@@ -32,6 +32,14 @@  FIT_KEY_SIGN_PKCS ?= "-x509"
 # Sign individual images as well
 FIT_SIGN_INDIVIDUAL ?= "0"
 
+# Kernel FIT image signing: these mirror the U-Boot signing variables so that
+# kernel recipes can independently enable/override signing without affecting
+# the U-Boot recipe's own UBOOT_SIGN_* settings.
+FIT_KERNEL_SIGN_ENABLE ?= "${UBOOT_SIGN_ENABLE}"
+FIT_KERNEL_SIGN_KEYNAME ?= "${UBOOT_SIGN_KEYNAME}"
+FIT_KERNEL_SIGN_IMG_KEYNAME ?= "${UBOOT_SIGN_IMG_KEYNAME}"
+FIT_KERNEL_SIGN_KEYDIR ?= "${UBOOT_SIGN_KEYDIR}"
+
 FIT_CONF_PREFIX ?= "conf-"
 FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name"
 
diff --git a/meta/conf/uboot.conf b/meta/conf/uboot.conf
index ef71edc3d1..01e0b6cc7e 100644
--- a/meta/conf/uboot.conf
+++ b/meta/conf/uboot.conf
@@ -18,6 +18,14 @@  UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}"
 # Signature activation
 UBOOT_SIGN_ENABLE ?= "0"
 
+# Base name of the key pair used to sign FIT configuration nodes
+# (files: <UBOOT_SIGN_KEYDIR>/<name>.key and .crt).
+UBOOT_SIGN_KEYNAME ?= "fit-conf-key"
+
+# Base name of the key pair used to sign individual image nodes
+# (FIT_SIGN_INDIVIDUAL = "1" only).
+UBOOT_SIGN_IMG_KEYNAME ?= "fit-img-key"
+
 # Arguments passed to mkimage for signing
 UBOOT_MKIMAGE_SIGN_ARGS ?= ""
 SPL_MKIMAGE_SIGN_ARGS ?= ""
diff --git a/meta/lib/oeqa/selftest/cases/fitimage.py b/meta/lib/oeqa/selftest/cases/fitimage.py
index 7e39d60929..0180a3c962 100644
--- a/meta/lib/oeqa/selftest/cases/fitimage.py
+++ b/meta/lib/oeqa/selftest/cases/fitimage.py
@@ -711,6 +711,9 @@  class KernelFitImageBase(FitImageTestCase):
             'UBOOT_FIT_TEE_IMAGE',
             'UBOOT_FIT_TEE_LOADADDRESS',
             'UBOOT_FIT_TEE_ENTRYPOINT',
+            'FIT_KERNEL_SIGN_ENABLE',
+            'FIT_KERNEL_SIGN_KEYNAME',
+            'FIT_KERNEL_SIGN_IMG_KEYNAME',
         }
         bb_vars, bb_flags = get_bb_vars_flags([*internal_used, *additional_vars], flags, self.kernel_recipe)
         bb_vars = {var: val or None for var, val in bb_vars.items()}
@@ -806,7 +809,7 @@  class KernelFitImageBase(FitImageTestCase):
         initramfs_image = bb_vars['INITRAMFS_IMAGE']
         initramfs_image_bundle = bb_vars['INITRAMFS_IMAGE_BUNDLE']
         loadables = FitImageTestCase._get_loadables(bb_vars)
-        uboot_sign_enable = bb_vars.get('UBOOT_SIGN_ENABLE')
+        uboot_sign_enable = bb_vars.get('FIT_KERNEL_SIGN_ENABLE')
 
         # image nodes
         images = ['kernel-1']
@@ -957,7 +960,7 @@  class KernelFitImageBase(FitImageTestCase):
 
     def _get_req_sigvalues_config(self, bb_vars):
         """Generate a dictionary of expected configuration signature nodes"""
-        if bb_vars.get('UBOOT_SIGN_ENABLE') != "1":
+        if bb_vars.get('FIT_KERNEL_SIGN_ENABLE') != "1":
             return {}
         sign_images = '"kernel"'
         dtb_files, _ = FitImageTestCase._get_dtb_files(bb_vars)
@@ -971,7 +974,7 @@  class KernelFitImageBase(FitImageTestCase):
             sign_images += ', "setup"'
         req_sigvalues_config = {
             'algo': '"%s,%s"' % (bb_vars['FIT_HASH_ALG'], bb_vars['FIT_SIGN_ALG']),
-            'key-name-hint': '"%s"' % bb_vars['UBOOT_SIGN_KEYNAME'],
+            'key-name-hint': '"%s"' % bb_vars['FIT_KERNEL_SIGN_KEYNAME'],
             'sign-images': sign_images,
         }
         return req_sigvalues_config
@@ -982,7 +985,7 @@  class KernelFitImageBase(FitImageTestCase):
             return {}
         req_sigvalues_image = {
             'algo': '"%s,%s"' % (bb_vars['FIT_HASH_ALG'], bb_vars['FIT_SIGN_ALG']),
-            'key-name-hint': '"%s"' % bb_vars['UBOOT_SIGN_IMG_KEYNAME'],
+            'key-name-hint': '"%s"' % bb_vars['FIT_KERNEL_SIGN_IMG_KEYNAME'],
         }
         return req_sigvalues_image
 
@@ -996,9 +999,9 @@  class KernelFitImageBase(FitImageTestCase):
         initramfs_image = bb_vars['INITRAMFS_IMAGE']
         initramfs_image_bundle = bb_vars['INITRAMFS_IMAGE_BUNDLE']
         loadables = FitImageTestCase._get_loadables(bb_vars)
-        uboot_sign_enable = bb_vars['UBOOT_SIGN_ENABLE']
-        uboot_sign_img_keyname = bb_vars['UBOOT_SIGN_IMG_KEYNAME']
-        uboot_sign_keyname = bb_vars['UBOOT_SIGN_KEYNAME']
+        uboot_sign_enable = bb_vars['FIT_KERNEL_SIGN_ENABLE']
+        uboot_sign_img_keyname = bb_vars['FIT_KERNEL_SIGN_IMG_KEYNAME']
+        uboot_sign_keyname = bb_vars['FIT_KERNEL_SIGN_KEYNAME']
         num_signatures = 0
         req_sections = {
             "kernel-1": {
@@ -1080,7 +1083,7 @@  class KernelFitImageBase(FitImageTestCase):
 
     def _check_signing(self, bb_vars, sections, req_sections, num_signatures, uboot_tools_bindir, fitimage_path):
         """Verify the signature nodes in the FIT image"""
-        if bb_vars['UBOOT_SIGN_ENABLE'] == "1":
+        if bb_vars['FIT_KERNEL_SIGN_ENABLE'] == "1":
             self.logger.debug("Verifying signatures in the FIT image")
         else:
             self.logger.debug("FIT image is not signed. Signature verification is not needed.")
@@ -1088,8 +1091,8 @@  class KernelFitImageBase(FitImageTestCase):
 
         fit_hash_alg = bb_vars['FIT_HASH_ALG']
         fit_sign_alg = bb_vars['FIT_SIGN_ALG']
-        uboot_sign_keyname = bb_vars['UBOOT_SIGN_KEYNAME']
-        uboot_sign_img_keyname = bb_vars['UBOOT_SIGN_IMG_KEYNAME']
+        uboot_sign_keyname = bb_vars['FIT_KERNEL_SIGN_KEYNAME']
+        uboot_sign_img_keyname = bb_vars['FIT_KERNEL_SIGN_IMG_KEYNAME']
         deploy_dir_image = bb_vars['DEPLOY_DIR_IMAGE']
         kernel_deploysubdir = bb_vars['KERNEL_DEPLOYSUBDIR']
         fit_sign_individual = bb_vars['FIT_SIGN_INDIVIDUAL']
@@ -1535,7 +1538,7 @@  class FitImagePyTests(KernelFitImageBase):
             'UBOOT_MKIMAGE': "uboot-mkimage",
             'UBOOT_MKIMAGE_SIGN': "uboot-mkimage",
             'UBOOT_MKIMAGE_SIGN_ARGS': "",
-            'UBOOT_SIGN_ENABLE': "0",
+            'FIT_KERNEL_SIGN_ENABLE': "0",
             'UBOOT_SIGN_KEYDIR': None,
             'UBOOT_SIGN_KEYNAME': None,
             'UBOOT_SIGN_IMG_KEYNAME': None,
@@ -1557,7 +1560,7 @@  class FitImagePyTests(KernelFitImageBase):
             bb_vars["FIT_DESC"], bb_vars["FIT_ADDRESS_CELLS"],
             bb_vars['HOST_PREFIX'], bb_vars['UBOOT_ARCH'], bb_vars['FIT_OS'],
             bb_vars["FIT_CONF_PREFIX"],
-            oe.types.boolean(bb_vars['UBOOT_SIGN_ENABLE']), bb_vars["UBOOT_SIGN_KEYDIR"],
+            oe.types.boolean(bb_vars['FIT_KERNEL_SIGN_ENABLE']), bb_vars["UBOOT_SIGN_KEYDIR"],
             bb_vars["UBOOT_MKIMAGE"], bb_vars["UBOOT_MKIMAGE_DTCOPTS"],
             bb_vars["UBOOT_MKIMAGE_SIGN"], bb_vars["UBOOT_MKIMAGE_SIGN_ARGS"],
             bb_vars['FIT_HASH_ALG'], bb_vars['FIT_SIGN_ALG'], bb_vars['FIT_PAD_ALG'],
diff --git a/meta/recipes-kernel/kernel-signing-keys/kernel-signing-keys-native.bb b/meta/recipes-kernel/kernel-signing-keys/kernel-signing-keys-native.bb
index f346f1648a..4f066a1789 100644
--- a/meta/recipes-kernel/kernel-signing-keys/kernel-signing-keys-native.bb
+++ b/meta/recipes-kernel/kernel-signing-keys/kernel-signing-keys-native.bb
@@ -15,6 +15,7 @@  SUMMARY = "Signing keys for the kernel FIT image"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
 
+require conf/uboot.conf
 require conf/image-fitimage.conf
 
 DEPENDS += "openssl-native"