@@ -158,6 +158,19 @@ UBOOT_FIT_CONF_USER_LOADABLES ?= ''
# as a space separated list of node names
UBOOT_FIT_CONF_LOADABLES ?= ""
+# Additional configurations for the U-Boot fitImage, written after the
+# default one, as a space separated list of configuration node names. Each
+# one is described by varflags named after its node:
+# UBOOT_FIT_CONFIGURATION_LOADABLES[name] images it loads, as a space
+# separated list of image node
+# names (required)
+# UBOOT_FIT_CONFIGURATION_FIRMWARE[name] image to boot first, if any
+# UBOOT_FIT_CONFIGURATION_DESCRIPTION[name]
+# description, the node name if
+# not set
+# They are signed like the default configuration.
+UBOOT_FIT_CONFIGURATIONS ?= ""
+
UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}"
UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}"
@@ -490,19 +503,107 @@ def uboot_fitimage_loadables(d):
cmds.append('uboot_fitimage_loadable ' + ' '.join(shlex.quote(a) for a in args))
return '\n'.join(cmds)
-# The calls to uboot_fitimage_loadable only appear once the image list is
+# Create a ITS configuration node, given its name, description, firmware,
+# loadables and fdt image, signed as SPL_SIGN_CONF asks for it
+uboot_fitimage_configuration() {
+ conf_firmware=""
+ conf_fdt=""
+ conf_sign_images="\"loadables\""
+
+ if [ -n "$3" ] ; then
+ conf_firmware="firmware = \"$3\";"
+ conf_sign_images="\"firmware\", ${conf_sign_images}"
+ fi
+
+ if [ -n "$5" ] ; then
+ conf_fdt="fdt = \"$5\";"
+ conf_sign_images="${conf_sign_images}, \"fdt\""
+ fi
+
+ cat << EOF >> ${UBOOT_ITS}
+ $1 {
+ description = "$2";
+ ${conf_firmware}
+ loadables = $4;
+ ${conf_fdt}
+EOF
+
+ if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ "${SPL_SIGN_CONF}" = "1" ] ; then
+ cat << EOF >> ${UBOOT_ITS}
+ signature {
+ algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
+ key-name-hint = "${SPL_SIGN_KEYNAME}";
+ sign-images = ${conf_sign_images};
+ };
+EOF
+ fi
+
+ cat << EOF >> ${UBOOT_ITS}
+ };
+EOF
+}
+
+# Create a ITS configuration node for a configuration from
+# UBOOT_FIT_CONFIGURATIONS, given its name, description, firmware and
+# loadables
+uboot_fitimage_user_configuration() {
+ images="uboot fdt ${UBOOT_FIT_LOADABLES}"
+ if [ "${UBOOT_FIT_TEE}" = "1" ] ; then
+ images="$images tee"
+ fi
+ if [ "${UBOOT_FIT_ARM_TRUSTED_FIRMWARE}" = "1" ] ; then
+ images="$images atf"
+ fi
+
+ if [ -z "$4" ] ; then
+ bbfatal "UBOOT_FIT_CONFIGURATIONS: $1 needs UBOOT_FIT_CONFIGURATION_LOADABLES[$1]"
+ fi
+
+ loadables=""
+ for image in $3 $4 ; do
+ case " $images " in
+ *" $image "*)
+ ;;
+ *)
+ bbfatal "UBOOT_FIT_CONFIGURATIONS: $1 has no $image image to load"
+ ;;
+ esac
+ done
+ for image in $4 ; do
+ loadables="${loadables}${loadables:+, }\"$image\""
+ done
+
+ uboot_fitimage_configuration "$1" "$2" "$3" "$loadables" ""
+}
+
+# The uboot_fitimage_user_configuration calls for UBOOT_FIT_CONFIGURATIONS
+def uboot_fitimage_user_configurations(d):
+ import shlex
+ cmds = []
+ for name in (d.getVar('UBOOT_FIT_CONFIGURATIONS') or '').split():
+ args = [name,
+ d.getVarFlag('UBOOT_FIT_CONFIGURATION_DESCRIPTION', name) or name,
+ d.getVarFlag('UBOOT_FIT_CONFIGURATION_FIRMWARE', name) or '',
+ ' '.join((d.getVarFlag('UBOOT_FIT_CONFIGURATION_LOADABLES', name) or '').split())]
+ cmds.append('uboot_fitimage_user_configuration ' + ' '.join(shlex.quote(a) for a in args))
+ return '\n'.join(cmds)
+
+# The calls to uboot_fitimage_loadable and
+# uboot_fitimage_user_configuration only appear once the lists are
# expanded, and the varflags are read through a name
uboot_fitimage_assemble[vardeps] += "uboot_fitimage_loadable \
+ uboot_fitimage_user_configuration \
UBOOT_FIT_LOADABLE_FILENAME UBOOT_FIT_LOADABLE_LOADADDRESS \
UBOOT_FIT_LOADABLE_ENTRYPOINT UBOOT_FIT_LOADABLE_TYPE \
UBOOT_FIT_LOADABLE_ARCH UBOOT_FIT_LOADABLE_OS \
- UBOOT_FIT_LOADABLE_COMPRESSION UBOOT_FIT_LOADABLE_DESCRIPTION"
+ UBOOT_FIT_LOADABLE_COMPRESSION UBOOT_FIT_LOADABLE_DESCRIPTION \
+ UBOOT_FIT_CONFIGURATION_LOADABLES UBOOT_FIT_CONFIGURATION_FIRMWARE \
+ UBOOT_FIT_CONFIGURATION_DESCRIPTION"
# Create a ITS file for the U-boot FIT, for use when
# we want to sign it so that the SPL can verify it
uboot_fitimage_assemble() {
conf_loadables="\"uboot\""
- conf_firmware=""
rm -f ${UBOOT_ITS} ${UBOOT_FITIMAGE_BINARY}
# First we create the ITS script
@@ -576,45 +677,19 @@ EOF
esac
done
- conf_sign_images=""
- conf_sign_images_sep=""
-
- if [ -n "${UBOOT_FIT_CONF_FIRMWARE}" ] ; then
- conf_firmware="firmware = \"${UBOOT_FIT_CONF_FIRMWARE}\";"
- conf_sign_images="${conf_sign_images}${conf_sign_images_sep}\"firmware\""
- conf_sign_images_sep=", "
- fi
-
- if [ -n "${conf_loadables}" ] ; then
- conf_sign_images="${conf_sign_images}${conf_sign_images_sep}\"loadables\""
- conf_sign_images_sep=", "
- fi
- conf_sign_images="${conf_sign_images}${conf_sign_images_sep}\"fdt\""
-
cat << EOF >> ${UBOOT_ITS}
};
configurations {
default = "conf";
- conf {
- description = "${UBOOT_FIT_CONF_DESC}";
- ${conf_firmware}
- loadables = ${conf_loadables};
- fdt = "fdt";
EOF
- if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ "${SPL_SIGN_CONF}" = "1" ] ; then
- cat << EOF >> ${UBOOT_ITS}
- signature {
- algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}";
- key-name-hint = "${SPL_SIGN_KEYNAME}";
- sign-images = ${conf_sign_images};
- };
-EOF
- fi
+ uboot_fitimage_configuration "conf" "${UBOOT_FIT_CONF_DESC}" \
+ "${UBOOT_FIT_CONF_FIRMWARE}" "${conf_loadables}" "fdt"
+
+ ${@uboot_fitimage_user_configurations(d)}
cat << EOF >> ${UBOOT_ITS}
- };
};
};
EOF
@@ -663,6 +738,15 @@ EOF
${UBOOT_FIT_CHECK_SIGN} \
-k "${SPL_DIR}/${SPL_DTB_SIGNED}" \
-f ${UBOOT_FITIMAGE_BINARY}
+
+ # fit_check_sign only checks the default configuration
+ # unless told otherwise, so check the others too
+ for conf in ${UBOOT_FIT_CONFIGURATIONS} ; do
+ ${UBOOT_FIT_CHECK_SIGN} \
+ -k "${SPL_DIR}/${SPL_DTB_SIGNED}" \
+ -f ${UBOOT_FITIMAGE_BINARY} \
+ -c "$conf"
+ done
else
# Sign the U-boot FIT image
${UBOOT_MKIMAGE_SIGN} \
@@ -1710,6 +1710,7 @@ class UBootFitImageTests(FitImageTestCase):
'UBOOT_FIT_CONF_FIRMWARE',
'UBOOT_FIT_CONF_LOADABLES',
'UBOOT_FIT_CONF_USER_LOADABLES',
+ 'UBOOT_FIT_CONFIGURATIONS',
'UBOOT_FIT_DESC',
'UBOOT_FIT_HASH_ALG',
'UBOOT_FIT_LOADABLES',
@@ -1773,6 +1774,29 @@ class UBootFitImageTests(FitImageTestCase):
'description': flag('UBOOT_FIT_LOADABLE_DESCRIPTION', '%s loadable' % loadable),
}
+ # The varflags describing each UBOOT_FIT_CONFIGURATIONS entry
+ UBOOT_FIT_CONFIGURATION_FLAGS = [
+ 'UBOOT_FIT_CONFIGURATION_DESCRIPTION',
+ 'UBOOT_FIT_CONFIGURATION_FIRMWARE',
+ 'UBOOT_FIT_CONFIGURATION_LOADABLES',
+ ]
+
+ @staticmethod
+ def _get_uboot_configurations(bb_vars):
+ """Return the configuration node names: the default one, then UBOOT_FIT_CONFIGURATIONS"""
+ return ['conf'] + (bb_vars.get('UBOOT_FIT_CONFIGURATIONS') or '').split()
+
+ @staticmethod
+ def _get_uboot_configuration_settings(bb_vars, configuration):
+ """Return the settings of an UBOOT_FIT_CONFIGURATIONS entry, defaults applied as by the class"""
+ def flag(var, default=None):
+ return (bb_vars.get(var) or {}).get(configuration) or default
+ return {
+ 'description': flag('UBOOT_FIT_CONFIGURATION_DESCRIPTION', configuration),
+ 'firmware': flag('UBOOT_FIT_CONFIGURATION_FIRMWARE'),
+ 'loadables': flag('UBOOT_FIT_CONFIGURATION_LOADABLES', '').split(),
+ }
+
def _gen_uboot_loadable_dummy_images(self, bb_vars):
"""Generate dummy files for the UBOOT_FIT_LOADABLES images"""
for loadable in UBootFitImageTests._get_uboot_loadables(bb_vars):
@@ -1821,7 +1845,7 @@ class UBootFitImageTests(FitImageTestCase):
# if bb_vars['UBOOT_FIT_USER_SETTINGS']:
# configuration nodes
- configurations = [ 'conf']
+ configurations = UBootFitImageTests._get_uboot_configurations(bb_vars)
spl_sign_enable = bb_vars['SPL_SIGN_ENABLE'] == "1"
spl_sign_individual = spl_sign_enable and bb_vars['SPL_SIGN_INDIVIDUAL'] == "1"
@@ -1918,6 +1942,20 @@ class UBootFitImageTests(FitImageTestCase):
sign_images.append("firmware")
sign_images += ["loadables", "fdt"]
its_field_check.append('sign-images = "%s";' % '", "'.join(sign_images))
+ for configuration in UBootFitImageTests._get_uboot_configurations(bb_vars)[1:]:
+ settings = UBootFitImageTests._get_uboot_configuration_settings(bb_vars, configuration)
+ its_field_check += [
+ '%s {' % configuration,
+ 'description = "%s";' % settings['description'],
+ ]
+ sign_images = []
+ if settings['firmware']:
+ its_field_check.append('firmware = "%s";' % settings['firmware'])
+ sign_images.append("firmware")
+ its_field_check.append('loadables = "%s";' % '", "'.join(settings['loadables']))
+ sign_images.append("loadables")
+ if bb_vars['SPL_SIGN_ENABLE'] == "1" and bb_vars['SPL_SIGN_CONF'] == "1":
+ its_field_check.append('sign-images = "%s";' % '", "'.join(sign_images))
return its_field_check
def _get_req_sigvalues_config(self, bb_vars):
@@ -1982,6 +2020,16 @@ class UBootFitImageTests(FitImageTestCase):
"FDT": "fdt",
"Loadables": ','.join(loadables),
}
+ configurations = UBootFitImageTests._get_uboot_configurations(bb_vars)
+ for configuration in configurations[1:]:
+ settings = UBootFitImageTests._get_uboot_configuration_settings(bb_vars, configuration)
+ req_sections[configuration] = {
+ "Description": settings['description'],
+ "Kernel": "unavailable",
+ "Loadables": ','.join(settings['loadables']),
+ }
+ if settings['firmware']:
+ req_sections[configuration]["Firmware"] = settings['firmware']
# Add signing related properties if needed
uboot_fit_hash_alg = bb_vars['UBOOT_FIT_HASH_ALG']
@@ -1993,7 +2041,7 @@ class UBootFitImageTests(FitImageTestCase):
num_signatures = 0
if spl_sign_enable == "1":
for section in req_sections:
- if section.startswith('conf'):
+ if section in configurations:
if spl_sign_conf == "1":
req_sections[section]['Sign algo'] = "%s,%s:%s" % \
(uboot_fit_hash_alg, uboot_fit_sign_alg, spl_sign_keyname)
@@ -2040,6 +2088,11 @@ class UBootFitImageTests(FitImageTestCase):
"%s,%s" % (uboot_fit_hash_alg, uboot_fit_sign_alg))
self._verify_dtb_property(dtc_bindir, spl_dtb_path, key_dtb_path, "key-name-hint", spl_sign_keyname)
+ # Check the signature of each configuration with the key in the SPL DTB
+ if bb_vars['SPL_SIGN_CONF'] == "1":
+ for configuration in UBootFitImageTests._get_uboot_configurations(bb_vars):
+ self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, spl_dtb_path, configuration)
+
# Search for the string passed to mkimage in each signed section of the FIT image.
# Looks like mkimage supports to add a comment but does not support to read it back.
a_comment = FitImageTestCase._get_uboot_mkimage_sign_args(bb_vars['SPL_MKIMAGE_SIGN_ARGS'])
@@ -2360,6 +2413,68 @@ UBOOT_FIT_HASH_ALG = "sha256"
self._test_fitimage(bb_vars)
self._check_uboot_loadable_defaults(bb_vars)
+ def test_sign_uboot_fit_image_configurations(self):
+ """
+ Summary: Check if the configurations from UBOOT_FIT_CONFIGURATIONS
+ are added to the U-Boot FIT image and Image Tree Source
+ (its) and signed like the default configuration.
+ Expected: 1) U-Boot its and FIT image are built and signed
+ successfully
+ 2) Each UBOOT_FIT_CONFIGURATIONS entry has a configuration
+ node after the default one, with the firmware,
+ loadables and description from its
+ UBOOT_FIT_CONFIGURATION_* varflags, the description
+ defaulting to the node name, and no fdt property
+ 3) Each configuration has a signature node covering its
+ firmware and loadables
+ 4) Dumping the FIT image shows signatures for all the
+ configurations, and fit_check_sign verifies each of
+ them with the key in the SPL DTB
+ 5) SPL_MKIMAGE_SIGN_ARGS is passed to mkimage for each
+ signed configuration
+ Product: oe-core
+ Author: Viswanath Kraleti <viswanath.kraleti@oss.qualcomm.com>
+ """
+ machine = self._get_machine_or_skip()
+ config = """
+# Enable creation and signing of the U-Boot fitImage
+UBOOT_FITIMAGE_ENABLE = "1"
+SPL_SIGN_ENABLE = "1"
+SPL_SIGN_KEYNAME = "spl-configurations-oe-selftest"
+SPL_SIGN_KEYDIR = "${TOPDIR}/signing-keys"
+UBOOT_ENTRYPOINT = "0x80000000"
+UBOOT_LOADADDRESS = "0x80000000"
+UBOOT_DTB_LOADADDRESS = "0x82000000"
+SPL_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
+SPL_MKIMAGE_SIGN_ARGS = "-c 'a smart U-Boot configurations comment'"
+UBOOT_EXTLINUX = "0"
+UBOOT_FIT_GENERATE_KEYS = "1"
+UBOOT_FIT_HASH_ALG = "sha256"
+
+# Two more configurations: pre-ddr boots loadable1 and loads loadable2,
+# minimal only loads U-Boot and has no description set
+UBOOT_FIT_CONFIGURATIONS = "pre-ddr minimal"
+UBOOT_FIT_CONFIGURATION_FIRMWARE[pre-ddr] = "loadable1"
+UBOOT_FIT_CONFIGURATION_LOADABLES[pre-ddr] = "loadable2"
+UBOOT_FIT_CONFIGURATION_DESCRIPTION[pre-ddr] = "Boot ahead of the DDR init"
+UBOOT_FIT_CONFIGURATION_LOADABLES[minimal] = "uboot"
+""" + UBootFitImageTests.UBOOT_FIT_LOADABLES_CONFIG
+ config = FitImageTestCase._config_add_machine_settings(config, machine, keys=["UBOOT_MACHINE", "SPL_BINARY", "UBOOT_DTB_BINARY", "UBOOT_ARCH"])
+ config = self._require_machine_capability(config, machine, '_cap_spl_dtb')
+ self.write_config(config)
+ configurations = ['pre-ddr', 'minimal']
+ flags = {flag: ['loadable1', 'loadable2'] for flag in UBootFitImageTests.UBOOT_FIT_LOADABLE_FLAGS}
+ flags.update({flag: configurations for flag in UBootFitImageTests.UBOOT_FIT_CONFIGURATION_FLAGS})
+ bb_vars = self._fit_get_bb_vars(flags=flags)
+ self._gen_uboot_loadable_dummy_images(bb_vars)
+ self._test_fitimage(bb_vars)
+
+ # The additional configurations load no device tree
+ fitimage_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "u-boot-fitImage-%s" % bb_vars['MACHINE'])
+ dtc_bindir = FitImageTestCase._setup_native('dtc-native')
+ for configuration in configurations:
+ self._verify_dtb_property(dtc_bindir, fitimage_path, '/configurations/%s' % configuration, 'fdt', None, absent=True)
+
def test_sign_cascaded_uboot_fit_image(self):
"""
Summary: Check if U-Boot FIT image and Image Tree Source (its) are
The U-Boot FIT only ever has the one configuration. An SPL that loads its images in stages, such as one loading firmware from a "pre-ddr" configuration ahead of DDR init and the rest from a "post-ddr" one, cannot get the other configurations into it, short of writing them as ITS text along with their signature nodes. Add UBOOT_FIT_CONFIGURATIONS, a list of configuration node names written after the default configuration, each described by UBOOT_FIT_CONFIGURATION_LOADABLES, _FIRMWARE and _DESCRIPTION varflags named after the node. Write every configuration, the default one included, from uboot_fitimage_configuration, so that they are all signed alike, and run fit_check_sign with -c for each of the additional configurations, as it otherwise only checks the default one. Teach the U-Boot FIT selftests about the additional configurations, have them check every configuration with fit_check_sign, and add a test signing two additional configurations. AI-Generated: Uses Claude Code Signed-off-by: Viswanath Kraleti <viswanath.kraleti@oss.qualcomm.com> --- meta/classes-recipe/uboot-sign.bbclass | 150 ++++++++++++++++++----- meta/lib/oeqa/selftest/cases/fitimage.py | 119 +++++++++++++++++- 2 files changed, 234 insertions(+), 35 deletions(-)