oe-selftest: fitimage add u-boot env script

Extend all kernel-fitimage tests to add a boot.cmd script to the
fitImage and verify the script ends up in the fitImage.

The test covers the use case which is documented here:
https://docs.u-boot.org/en/latest/usage/cmd/source.html#fit-image.
But instead of adding the sctip inline a script file is generated.

(From OE-Core rev: 816f25359935f54881b557d55c29a390dd991609)

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Adrian Freihofer
2025-02-06 23:56:07 +01:00
committed by Richard Purdie
parent d29786839f
commit 4558f1b722

View File

@@ -60,6 +60,32 @@ class FitImageTests(OESelftestTestCase):
byte = file.read(1)
return found_positions
def _config_add_uboot_env(self, config):
"""Generate an u-boot environment
Create a boot.cmd file that is packed into the FitImage as a source-able text file.
"""
fit_uenv_file = "boot.cmd"
test_files_dir = "test-files"
fit_uenv_path = os.path.join(self.builddir, test_files_dir, fit_uenv_file)
config += '# Add an u-boot script to the fitImage' + os.linesep
config += 'FIT_UBOOT_ENV = "%s"' % fit_uenv_file + os.linesep
config += 'FILESEXTRAPATHS:prepend := "${TOPDIR}/%s:"' % test_files_dir + os.linesep
config += 'SRC_URI:append:pn-linux-yocto = " file://${FIT_UBOOT_ENV}"' + os.linesep
if not os.path.isdir(test_files_dir):
os.mkdir(test_files_dir)
self.logger.debug("Writing to: %s" % fit_uenv_path)
with open(fit_uenv_path, "w") as f:
f.write('echo "hello world"')
return config
def _verify_fitimage_uboot_env(self, dumpimage_result):
"""Check if the boot.cmd script is part of the fitImage"""
num_scr_images = len(re.findall(r"^ *Image +[0-9]+ +\(bootscr-boot\.cmd\)$", dumpimage_result.output, re.MULTILINE))
self.assertEqual(1, num_scr_images, msg="Expected exactly 1 bootscr-boot.cmd image section in the fitImage")
def test_fit_image(self):
"""
@@ -91,6 +117,7 @@ UBOOT_LOADADDRESS = "0x80080000"
UBOOT_ENTRYPOINT = "0x80080000"
FIT_DESC = "A model description"
"""
config = self._config_add_uboot_env(config)
self.write_config(config)
# fitImage is created as part of linux recipe
@@ -137,6 +164,10 @@ FIT_DESC = "A model description"
"Fields in Image Tree Source File %s did not match, error in finding %s"
% (fitimage_its_path, its_field_check[field_index]))
uboot_tools_bindir = self._setup_uboot_tools_native()
dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir)
self._verify_fitimage_uboot_env(dumpimage_result)
def test_sign_fit_image(self):
"""
@@ -171,6 +202,7 @@ FIT_SIGN_INDIVIDUAL = "1"
UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'"
""" % a_comment
config = self._config_add_uboot_env(config)
self.write_config(config)
# fitImage is created as part of linux recipe
@@ -228,7 +260,7 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'"
reqsigvalues_config = {
'algo': '"sha256,rsa2048"',
'key-name-hint': '"cfg-oe-selftest"',
'sign-images': '"kernel", "fdt"',
'sign-images': '"kernel", "fdt", "bootscr"',
}
for itspath, values in sigs.items():
@@ -269,10 +301,13 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'"
value = values.get('Sign value', None)
self.assertEqual(len(value), 512, 'Signature value for section %s not expected length' % signed_section)
# Check if the u-boot boot.scr script is in the fitImage
self._verify_fitimage_uboot_env(dumpimage_result)
# Search for the string passed to mkimage: 1 kernel + 3 DTBs + config per DTB = 7 sections
# Looks like mkimage supports to add a comment but does not support to read it back.
found_comments = FitImageTests._find_string_in_bin_file(fitimage_path, a_comment)
self.assertEqual(found_comments, 7, "Expected 7 signed and commented section in the fitImage.")
self.assertEqual(found_comments, 8, "Expected 8 signed and commented section in the fitImage.")
# Verify the signature for all configurations = DTBs
for dtb in ['am335x-bone.dtb', 'am335x-boneblack.dtb', 'am335x-bonegreen.dtb']:
@@ -771,6 +806,7 @@ KERNEL_IMAGETYPE_REPLACEMENT = "zImage"
FIT_KERNEL_COMP_ALG = "none"
FIT_HASH_ALG = "sha256"
"""
config = self._config_add_uboot_env(config)
self.write_config(config)
# fitImage is created as part of linux recipe
@@ -854,3 +890,7 @@ FIT_HASH_ALG = "sha256"
# Verify the signature
uboot_tools_bindir = self._setup_uboot_tools_native()
self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], 'am335x-bone.dtb'))
# Check if the u-boot boot.scr script is in the fitImage
dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir)
self._verify_fitimage_uboot_env(dumpimage_result)