@@ -121,6 +121,28 @@ UBOOT_FIT_TEE_IMAGE ?= "tee-raw.bin"
# User specific settings
UBOOT_FIT_USER_SETTINGS ?= ""
+# Additional images for the U-Boot fitImage, as a space separated list of
+# image node names, like FIT_LOADABLES for the kernel FIT image. Each one is
+# described by varflags named after its node, e.g.:
+#
+# UBOOT_FIT_LOADABLES = "fw"
+# UBOOT_FIT_LOADABLE_FILENAME[fw] = "fw.bin"
+# UBOOT_FIT_LOADABLE_LOADADDRESS[fw] = "0x80400000"
+# UBOOT_FIT_LOADABLE_ENTRYPOINT[fw] = "0x80400000"
+# UBOOT_FIT_LOADABLE_TYPE[fw] = "firmware"
+# UBOOT_FIT_LOADABLE_ARCH[fw] = "arm64"
+# UBOOT_FIT_LOADABLE_OS[fw] = "elf"
+# UBOOT_FIT_LOADABLE_COMPRESSION[fw] = "none"
+# UBOOT_FIT_LOADABLE_DESCRIPTION[fw] = "Firmware image"
+#
+# FILENAME and LOADADDRESS are required. FILENAME is absolute or relative to
+# the U-Boot build directory, as the images are packed from there rather than
+# from DEPLOY_DIR_IMAGE. ENTRYPOINT and OS are left out if not set, TYPE
+# defaults to "firmware", ARCH to ${UBOOT_ARCH}, COMPRESSION to "none" and
+# DESCRIPTION to "<name> loadable". The nodes get the same hash and signature
+# nodes as the class's own.
+UBOOT_FIT_LOADABLES ?= ""
+
# U-Boot fitImage configuration description
UBOOT_FIT_CONF_DESC ?= "Boot with signed U-Boot FIT"
@@ -132,6 +154,10 @@ UBOOT_FIT_CONF_FIRMWARE ?= ""
# It is a comma-separated list of strings.
UBOOT_FIT_CONF_USER_LOADABLES ?= ''
+# Images from UBOOT_FIT_LOADABLES loaded by the configuration, after its own,
+# as a space separated list of node names
+UBOOT_FIT_CONF_LOADABLES ?= ""
+
UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}"
UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}"
@@ -413,6 +439,65 @@ EOF
EOF
}
+# Create a ITS image node for an image from UBOOT_FIT_LOADABLES, given its
+# name, file, load address, entry point, type, arch, os, compression and
+# description
+uboot_fitimage_loadable() {
+ if [ -z "$2" ] || [ -z "$3" ] ; then
+ bbfatal "UBOOT_FIT_LOADABLES: $1 needs UBOOT_FIT_LOADABLE_FILENAME[$1] and UBOOT_FIT_LOADABLE_LOADADDRESS[$1]"
+ fi
+
+ cat << EOF >> ${UBOOT_ITS}
+ $1 {
+ description = "$9";
+ data = /incbin/("$2");
+ type = "$5";
+ arch = "$6";
+EOF
+ if [ -n "$7" ] ; then
+ echo " os = \"$7\";" >> ${UBOOT_ITS}
+ fi
+ echo " load = <$3>;" >> ${UBOOT_ITS}
+ if [ -n "$4" ] ; then
+ echo " entry = <$4>;" >> ${UBOOT_ITS}
+ fi
+ echo " compression = \"$8\";" >> ${UBOOT_ITS}
+
+ uboot_fitimage_image_signing
+
+ cat << EOF >> ${UBOOT_ITS}
+ };
+EOF
+}
+
+# The uboot_fitimage_loadable calls for UBOOT_FIT_LOADABLES. The varflags are
+# read as the task runs, so that a prefunc can still set them.
+def uboot_fitimage_loadables(d):
+ import shlex
+ cmds = []
+ for name in (d.getVar('UBOOT_FIT_LOADABLES') or '').split():
+ def flag(var, default=''):
+ return d.getVarFlag(var, name) or default
+ args = [name,
+ flag('UBOOT_FIT_LOADABLE_FILENAME'),
+ flag('UBOOT_FIT_LOADABLE_LOADADDRESS'),
+ flag('UBOOT_FIT_LOADABLE_ENTRYPOINT'),
+ flag('UBOOT_FIT_LOADABLE_TYPE', 'firmware'),
+ flag('UBOOT_FIT_LOADABLE_ARCH', d.getVar('UBOOT_ARCH')),
+ flag('UBOOT_FIT_LOADABLE_OS'),
+ flag('UBOOT_FIT_LOADABLE_COMPRESSION', 'none'),
+ flag('UBOOT_FIT_LOADABLE_DESCRIPTION', '%s loadable' % name)]
+ 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
+# expanded, and the varflags are read through a name
+uboot_fitimage_assemble[vardeps] += "uboot_fitimage_loadable \
+ 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"
+
# 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() {
@@ -474,10 +559,23 @@ EOF
printf "%b" "${UBOOT_FIT_USER_SETTINGS}" >> ${UBOOT_ITS}
fi
+ ${@uboot_fitimage_loadables(d)}
+
if [ -n "${UBOOT_FIT_CONF_USER_LOADABLES}" ] ; then
conf_loadables="${conf_loadables}${UBOOT_FIT_CONF_USER_LOADABLES}"
fi
+ for image in ${UBOOT_FIT_CONF_LOADABLES} ; do
+ case " ${UBOOT_FIT_LOADABLES} " in
+ *" $image "*)
+ conf_loadables="${conf_loadables}, \"$image\""
+ ;;
+ *)
+ bbfatal "UBOOT_FIT_CONF_LOADABLES: $image is not in UBOOT_FIT_LOADABLES"
+ ;;
+ esac
+ done
+
conf_sign_images=""
conf_sign_images_sep=""
@@ -1674,10 +1674,12 @@ class UBootFitImageTests(FitImageTestCase):
BOOTLOADER_RECIPE = "virtual/bootloader"
- def _fit_get_bb_vars(self, additional_vars=[]):
+ def _fit_get_bb_vars(self, additional_vars=[], flags=None):
"""Get bb_vars as needed by _test_sign_fit_image
- Call the get_bb_vars function once and get all variables needed by the test case.
+ Call the get_bb_vars_flags function once and get all variables needed by
+ the test case. flags maps variable names to lists of flag names. The
+ flags are returned as dict {flag name: value} for their variable name.
"""
internal_used = {
'DEPLOY_DIR_IMAGE',
@@ -1706,9 +1708,11 @@ class UBootFitImageTests(FitImageTestCase):
'UBOOT_FIT_ARM_TRUSTED_FIRMWARE',
'UBOOT_FIT_CONF_DESC',
'UBOOT_FIT_CONF_FIRMWARE',
+ 'UBOOT_FIT_CONF_LOADABLES',
'UBOOT_FIT_CONF_USER_LOADABLES',
'UBOOT_FIT_DESC',
'UBOOT_FIT_HASH_ALG',
+ 'UBOOT_FIT_LOADABLES',
'UBOOT_FIT_SIGN_ALG',
'UBOOT_FIT_TEE_ENTRYPOINT',
'UBOOT_FIT_TEE_IMAGE',
@@ -1724,10 +1728,60 @@ class UBootFitImageTests(FitImageTestCase):
'UBOOT_SIGN_KEYDIR',
'UBOOT_SIGN_KEYNAME',
}
- bb_vars = get_bb_vars(list(internal_used | set(additional_vars)), UBootFitImageTests.BOOTLOADER_RECIPE)
+ bb_vars, bb_flags = get_bb_vars_flags(list(internal_used | set(additional_vars)), flags,
+ UBootFitImageTests.BOOTLOADER_RECIPE)
+ bb_vars.update(bb_flags)
self.logger.debug("bb_vars: %s" % pprint.pformat(bb_vars, indent=4))
return bb_vars
+ # The varflags describing each UBOOT_FIT_LOADABLES entry
+ UBOOT_FIT_LOADABLE_FLAGS = [
+ 'UBOOT_FIT_LOADABLE_ARCH',
+ 'UBOOT_FIT_LOADABLE_COMPRESSION',
+ 'UBOOT_FIT_LOADABLE_DESCRIPTION',
+ 'UBOOT_FIT_LOADABLE_ENTRYPOINT',
+ 'UBOOT_FIT_LOADABLE_FILENAME',
+ 'UBOOT_FIT_LOADABLE_LOADADDRESS',
+ 'UBOOT_FIT_LOADABLE_OS',
+ 'UBOOT_FIT_LOADABLE_TYPE',
+ ]
+
+ # dumpimage names of the image types used by the UBOOT_FIT_LOADABLES tests
+ UBOOT_FIT_LOADABLE_TYPE_NAMES = {
+ 'firmware': 'Firmware',
+ 'standalone': 'Standalone Program',
+ }
+
+ @staticmethod
+ def _get_uboot_loadables(bb_vars):
+ """Return the image node names in UBOOT_FIT_LOADABLES"""
+ return (bb_vars.get('UBOOT_FIT_LOADABLES') or '').split()
+
+ @staticmethod
+ def _get_uboot_loadable_settings(bb_vars, loadable):
+ """Return the settings of an UBOOT_FIT_LOADABLES image, defaults applied as by the class"""
+ def flag(var, default=None):
+ return (bb_vars.get(var) or {}).get(loadable) or default
+ return {
+ 'filename': flag('UBOOT_FIT_LOADABLE_FILENAME'),
+ 'loadaddress': flag('UBOOT_FIT_LOADABLE_LOADADDRESS'),
+ 'entrypoint': flag('UBOOT_FIT_LOADABLE_ENTRYPOINT'),
+ 'type': flag('UBOOT_FIT_LOADABLE_TYPE', 'firmware'),
+ 'arch': flag('UBOOT_FIT_LOADABLE_ARCH', bb_vars['UBOOT_ARCH']),
+ 'os': flag('UBOOT_FIT_LOADABLE_OS'),
+ 'compression': flag('UBOOT_FIT_LOADABLE_COMPRESSION', 'none'),
+ 'description': flag('UBOOT_FIT_LOADABLE_DESCRIPTION', '%s loadable' % loadable),
+ }
+
+ 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):
+ filename = UBootFitImageTests._get_uboot_loadable_settings(bb_vars, loadable)['filename']
+ self.assertTrue(os.path.isabs(filename),
+ "The test images need an absolute UBOOT_FIT_LOADABLE_FILENAME[%s]" % loadable)
+ with open(filename, 'wb') as f:
+ f.write(os.urandom(256))
+
def _bitbake_fit_image(self, bb_vars):
"""Bitbake the bootloader and return the paths to the its file and the FIT image"""
machine = bb_vars['MACHINE']
@@ -1763,6 +1817,7 @@ class UBootFitImageTests(FitImageTestCase):
images.append('tee')
if bb_vars['UBOOT_FIT_ARM_TRUSTED_FIRMWARE'] == "1":
images.append('atf')
+ images += UBootFitImageTests._get_uboot_loadables(bb_vars)
# if bb_vars['UBOOT_FIT_USER_SETTINGS']:
# configuration nodes
@@ -1835,6 +1890,22 @@ class UBootFitImageTests(FitImageTestCase):
'compression = "none";',
]
loadables.insert(0, "atf")
+ for loadable in UBootFitImageTests._get_uboot_loadables(bb_vars):
+ settings = UBootFitImageTests._get_uboot_loadable_settings(bb_vars, loadable)
+ its_field_check += [
+ '%s {' % loadable,
+ 'description = "%s";' % settings['description'],
+ 'data = /incbin/("%s");' % settings['filename'],
+ 'type = "%s";' % settings['type'],
+ 'arch = "%s";' % settings['arch'],
+ ]
+ if settings['os']:
+ its_field_check.append('os = "%s";' % settings['os'])
+ its_field_check.append('load = <%s>;' % settings['loadaddress'])
+ if settings['entrypoint']:
+ its_field_check.append('entry = <%s>;' % settings['entrypoint'])
+ its_field_check.append('compression = "%s";' % settings['compression'])
+ loadables += (bb_vars.get('UBOOT_FIT_CONF_LOADABLES') or '').split()
its_field_check += [
'default = "conf";',
'description = "%s";' % bb_vars['UBOOT_FIT_CONF_DESC'],
@@ -1894,6 +1965,18 @@ class UBootFitImageTests(FitImageTestCase):
"Load Address": bb_vars['UBOOT_FIT_ARM_TRUSTED_FIRMWARE_LOADADDRESS'],
# "Entry Point": bb_vars['UBOOT_FIT_ARM_TRUSTED_FIRMWARE_ENTRYPOINT'], not printed by mkimage?
}
+ for loadable in UBootFitImageTests._get_uboot_loadables(bb_vars):
+ settings = UBootFitImageTests._get_uboot_loadable_settings(bb_vars, loadable)
+ req_sections[loadable] = {
+ "Load Address": settings['loadaddress'],
+ }
+ type_name = UBootFitImageTests.UBOOT_FIT_LOADABLE_TYPE_NAMES.get(settings['type'])
+ if type_name:
+ req_sections[loadable]["Type"] = type_name
+ # dumpimage prints the entry point of standalone images, not of firmware ones
+ if settings['entrypoint'] and settings['type'] == 'standalone':
+ req_sections[loadable]["Entry Point"] = settings['entrypoint']
+ loadables += (bb_vars.get('UBOOT_FIT_CONF_LOADABLES') or '').split()
req_sections["conf"] = {
"Kernel": "unavailable",
"FDT": "fdt",
@@ -2177,6 +2260,106 @@ UBOOT_FIT_MKIMAGE_EXTRA_OPTS = "-E"
result = runCmd('%s %s %s data-offset' % (fdtget_path, fitimage_path, node))
self.logger.debug("%s data-offset: %s" % (node, result.output))
+ UBOOT_FIT_LOADABLES_CONFIG = """
+# Two images from UBOOT_FIT_LOADABLES: loadable1 with only the required
+# settings, loadable2 with all of them, loaded by the configuration
+UBOOT_FIT_LOADABLES = "loadable1 loadable2"
+UBOOT_FIT_LOADABLE_FILENAME[loadable1] = "${TOPDIR}/loadable1-dummy.bin"
+UBOOT_FIT_LOADABLE_LOADADDRESS[loadable1] = "0x80400000"
+UBOOT_FIT_LOADABLE_FILENAME[loadable2] = "${TOPDIR}/loadable2-dummy.bin"
+UBOOT_FIT_LOADABLE_LOADADDRESS[loadable2] = "0x80500000"
+UBOOT_FIT_LOADABLE_ENTRYPOINT[loadable2] = "0x80500100"
+UBOOT_FIT_LOADABLE_TYPE[loadable2] = "standalone"
+UBOOT_FIT_LOADABLE_ARCH[loadable2] = "arm"
+UBOOT_FIT_LOADABLE_OS[loadable2] = "elf"
+UBOOT_FIT_LOADABLE_COMPRESSION[loadable2] = "gzip"
+UBOOT_FIT_LOADABLE_DESCRIPTION[loadable2] = "The second loadable"
+UBOOT_FIT_CONF_LOADABLES = "loadable2"
+"""
+
+ def _fit_get_bb_vars_loadables(self, loadables=['loadable1', 'loadable2']):
+ """Get bb_vars including the varflags of UBOOT_FIT_LOADABLES_CONFIG"""
+ return self._fit_get_bb_vars(flags={flag: loadables for flag in UBootFitImageTests.UBOOT_FIT_LOADABLE_FLAGS})
+
+ def _check_uboot_loadable_defaults(self, bb_vars):
+ """Check that loadable1 of UBOOT_FIT_LOADABLES_CONFIG has no entry and os property"""
+ 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 prop in ('entry', 'os'):
+ self._verify_dtb_property(dtc_bindir, fitimage_path, '/images/loadable1', prop, None, absent=True)
+
+ def test_uboot_fit_image_loadables(self):
+ """
+ Summary: Check if the images from UBOOT_FIT_LOADABLES are added
+ to the U-Boot FIT image and Image Tree Source (its).
+ Expected: 1) U-Boot its and FIT image are built successfully
+ 2) Each UBOOT_FIT_LOADABLES entry has an image node with
+ the properties from its UBOOT_FIT_LOADABLE_* varflags,
+ or their defaults when not set: type "firmware",
+ arch UBOOT_ARCH, compression "none", description
+ "<name> loadable" and no entry or os property
+ 3) The configuration loads the images listed in
+ UBOOT_FIT_CONF_LOADABLES after its own ones
+ 4) Dumping the FIT image shows the image nodes
+ Product: oe-core
+ Author: Viswanath Kraleti <viswanath.kraleti@oss.qualcomm.com>
+ """
+ machine = self._get_machine_or_skip()
+ config = """
+# Enable creation of the U-Boot fitImage
+UBOOT_FITIMAGE_ENABLE = "1"
+UBOOT_LOADADDRESS = "0x80080000"
+UBOOT_ENTRYPOINT = "0x80080000"
+""" + UBootFitImageTests.UBOOT_FIT_LOADABLES_CONFIG
+ config = FitImageTestCase._config_add_machine_settings(config, machine, keys=["UBOOT_MACHINE", "SPL_BINARY"])
+ self.write_config(config)
+ bb_vars = self._fit_get_bb_vars_loadables()
+ self._gen_uboot_loadable_dummy_images(bb_vars)
+ self._test_fitimage(bb_vars)
+ self._check_uboot_loadable_defaults(bb_vars)
+
+ def test_sign_uboot_fit_image_loadables_individual(self):
+ """
+ Summary: Check if the images from UBOOT_FIT_LOADABLES are signed
+ like the other images of the U-Boot FIT image when the
+ individual images are signed (SPL_SIGN_INDIVIDUAL = "1").
+ Expected: 1) U-Boot its and FIT image are built and signed
+ successfully
+ 2) The its file has a signature node in each image node,
+ those from UBOOT_FIT_LOADABLES included
+ 3) Dumping the FIT image shows signatures for all the
+ images
+ 4) SPL_MKIMAGE_SIGN_ARGS is passed to mkimage for each
+ signed image
+ Product: oe-core
+ Author: Viswanath Kraleti <viswanath.kraleti@oss.qualcomm.com>
+ """
+ machine = self._get_machine_or_skip()
+ config = """
+# Enable creation and signing of the individual U-Boot fitImage images
+UBOOT_FITIMAGE_ENABLE = "1"
+SPL_SIGN_ENABLE = "1"
+SPL_SIGN_CONF = "0"
+SPL_SIGN_INDIVIDUAL = "1"
+SPL_SIGN_KEYNAME = "spl-loadables-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 loadables comment'"
+UBOOT_EXTLINUX = "0"
+UBOOT_FIT_GENERATE_KEYS = "1"
+UBOOT_FIT_HASH_ALG = "sha256"
+""" + 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)
+ bb_vars = self._fit_get_bb_vars_loadables()
+ self._gen_uboot_loadable_dummy_images(bb_vars)
+ self._test_fitimage(bb_vars)
+ self._check_uboot_loadable_defaults(bb_vars)
+
def test_sign_cascaded_uboot_fit_image(self):
"""
Summary: Check if U-Boot FIT image and Image Tree Source (its) are
A machine adding firmware images to the U-Boot FIT has to write their nodes itself, as ITS text in UBOOT_FIT_USER_SETTINGS, together with the hash and signature nodes the class would give them. Those copies of the signing logic go stale: they miss SPL_SIGN_INDIVIDUAL, or keep their hash nodes when signing is off. Add UBOOT_FIT_LOADABLES, a list of image node names, each described by UBOOT_FIT_LOADABLE_FILENAME, _LOADADDRESS, _ENTRYPOINT, _TYPE, _ARCH, _OS, _COMPRESSION and _DESCRIPTION varflags named after the node, as FIT_LOADABLES does for the kernel FIT image, and UBOOT_FIT_CONF_LOADABLES to load them from the configuration. The class writes their nodes like its own, hash and signature nodes included. The varflags are read as the task runs, so a prefunc can still set addresses only known once a dependency has deployed. Teach the U-Boot FIT selftests about the loadable images, and add tests for them both unsigned and individually signed. AI-Generated: Uses Claude Code Signed-off-by: Viswanath Kraleti <viswanath.kraleti@oss.qualcomm.com> --- meta/classes-recipe/uboot-sign.bbclass | 98 ++++++++++++ meta/lib/oeqa/selftest/cases/fitimage.py | 189 ++++++++++++++++++++++- 2 files changed, 284 insertions(+), 3 deletions(-)