]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
oe-selftest: fitimage split run_dumpimage function
authorAdrian Freihofer <adrian.freihofer@gmail.com>
Thu, 6 Feb 2025 22:56:06 +0000 (23:56 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 11 Feb 2025 11:42:23 +0000 (11:42 +0000)
Provide a re-usable function which calls the dumpimage utiliy.
This is a refactoring.

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>
meta/lib/oeqa/selftest/cases/fitimage.py

index 0b5f4602fbccc850a89fcbc5f14d11b40a61cf5d..a0ec406a0eb098cadaa88d39be50aaab4c0ac5ce 100644 (file)
@@ -12,17 +12,22 @@ import re
 class FitImageTests(OESelftestTestCase):
 
     def _setup_uboot_tools_native(self):
-        """build u-boot-tools-native and return RECIPE_SYSROOT_NATIVE"""
+        """build u-boot-tools-native and return ${RECIPE_SYSROOT_NATIVE}/${bindir}"""
         bitbake("u-boot-tools-native -c addto_recipe_sysroot")
-        return get_bb_var('RECIPE_SYSROOT_NATIVE', 'u-boot-tools-native')
+        vars = get_bb_vars(['RECIPE_SYSROOT_NATIVE', 'bindir'], 'u-boot-tools-native')
+        return os.path.join(vars['RECIPE_SYSROOT_NATIVE'], vars['bindir'])
 
-    def _verify_fit_image_signature(self, uboot_tools_sysroot_native, fitimage_path, dtb_path, conf_name=None):
+    def _run_dumpimage(self, fitimage_path, uboot_tools_bindir):
+        dumpimage_path = os.path.join(uboot_tools_bindir, 'dumpimage')
+        return runCmd('%s -l %s' % (dumpimage_path, fitimage_path))
+
+    def _verify_fit_image_signature(self, uboot_tools_bindir, fitimage_path, dtb_path, conf_name=None):
         """Verify the signature of a fit contfiguration
 
         The fit_check_sign utility from u-boot-tools-native is called.
         uboot-fit_check_sign -f fitImage -k $dtb_name -c conf-$dtb_name
         """
-        fit_check_sign_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'uboot-fit_check_sign')
+        fit_check_sign_path = os.path.join(uboot_tools_bindir, 'uboot-fit_check_sign')
         cmd = '%s -f %s -k %s' % (fit_check_sign_path, fitimage_path, dtb_path)
         if conf_name:
             cmd += ' -c %s' % conf_name
@@ -238,12 +243,11 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'"
                 self.assertEqual(value, reqvalue)
 
         # Dump the image to see if it really got signed
-        uboot_tools_sysroot_native = self._setup_uboot_tools_native()
-        dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage')
-        result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path))
+        uboot_tools_bindir = self._setup_uboot_tools_native()
+        dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir)
         in_signed = None
         signed_sections = {}
-        for line in result.output.splitlines():
+        for line in dumpimage_result.output.splitlines():
             if line.startswith((' Configuration', ' Image')):
                 in_signed = re.search(r'\((.*)\)', line).groups()[0]
             elif re.match('^ *', line) in (' ', ''):
@@ -272,7 +276,7 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'"
 
         # Verify the signature for all configurations = DTBs
         for dtb in ['am335x-bone.dtb', 'am335x-boneblack.dtb', 'am335x-bonegreen.dtb']:
-            self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path,
+            self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path,
                                              os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], dtb), 'conf-' + dtb)
 
     def test_uboot_fit_image(self):
@@ -548,12 +552,11 @@ UBOOT_FIT_HASH_ALG = "sha256"
                 self.assertEqual(value, reqvalue)
 
         # Dump the image to see if it really got signed
-        uboot_tools_sysroot_native = self._setup_uboot_tools_native()
-        dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage')
-        result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path))
+        uboot_tools_bindir = self._setup_uboot_tools_native()
+        dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir)
         in_signed = None
         signed_sections = {}
-        for line in result.output.splitlines():
+        for line in dumpimage_result.output.splitlines():
             if line.startswith((' Image')):
                 in_signed = re.search(r'\((.*)\)', line).groups()[0]
             elif re.match(' \w', line):
@@ -577,7 +580,7 @@ UBOOT_FIT_HASH_ALG = "sha256"
         self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.")
 
         # Verify the signature
-        self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path,
+        self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path,
                                          os.path.join(deploy_dir_image, 'u-boot-spl.dtb'))
 
 
@@ -696,12 +699,11 @@ FIT_SIGN_INDIVIDUAL = "1"
                 self.assertEqual(value, reqvalue)
 
         # Dump the image to see if it really got signed
-        uboot_tools_sysroot_native = self._setup_uboot_tools_native()
-        dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage')
-        result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path))
+        uboot_tools_bindir = self._setup_uboot_tools_native()
+        dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir)
         in_signed = None
         signed_sections = {}
-        for line in result.output.splitlines():
+        for line in dumpimage_result.output.splitlines():
             if line.startswith((' Image')):
                 in_signed = re.search(r'\((.*)\)', line).groups()[0]
             elif re.match(' \w', line):
@@ -725,7 +727,7 @@ FIT_SIGN_INDIVIDUAL = "1"
         self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.")
 
         # Verify the signature
-        self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path,
+        self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path,
                                          os.path.join(deploy_dir_image, 'u-boot-spl.dtb'))
 
 
@@ -850,5 +852,5 @@ FIT_HASH_ALG = "sha256"
             self.assertEqual(len(list(filter(rx_sign_line.match, node))), 1, "kernel hash not signed")
 
         # Verify the signature
-        uboot_tools_sysroot_native = self._setup_uboot_tools_native()
-        self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], 'am335x-bone.dtb'))
+        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'))