diff options
author | Adrian Freihofer <adrian.freihofer@gmail.com> | 2025-02-06 23:56:06 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-02-11 11:44:19 +0000 |
commit | d29786839f086afbf90a0a8cc746aa7eb252507a (patch) | |
tree | e3e58bec4f0b1aee7d0410c1b95d3762e6f81fcc | |
parent | 9ea3f0e4cdaa32e5d3af5e52b6990bac9618ea48 (diff) | |
download | poky-d29786839f086afbf90a0a8cc746aa7eb252507a.tar.gz |
oe-selftest: fitimage split run_dumpimage function
Provide a re-usable function which calls the dumpimage utiliy.
This is a refactoring.
(From OE-Core rev: f69f54d72d89fb381ea1945ea52f4c9963552e9f)
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>
-rw-r--r-- | meta/lib/oeqa/selftest/cases/fitimage.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/meta/lib/oeqa/selftest/cases/fitimage.py b/meta/lib/oeqa/selftest/cases/fitimage.py index 0b5f4602fb..a0ec406a0e 100644 --- a/meta/lib/oeqa/selftest/cases/fitimage.py +++ b/meta/lib/oeqa/selftest/cases/fitimage.py | |||
@@ -12,17 +12,22 @@ import re | |||
12 | class FitImageTests(OESelftestTestCase): | 12 | class FitImageTests(OESelftestTestCase): |
13 | 13 | ||
14 | def _setup_uboot_tools_native(self): | 14 | def _setup_uboot_tools_native(self): |
15 | """build u-boot-tools-native and return RECIPE_SYSROOT_NATIVE""" | 15 | """build u-boot-tools-native and return ${RECIPE_SYSROOT_NATIVE}/${bindir}""" |
16 | bitbake("u-boot-tools-native -c addto_recipe_sysroot") | 16 | bitbake("u-boot-tools-native -c addto_recipe_sysroot") |
17 | return get_bb_var('RECIPE_SYSROOT_NATIVE', 'u-boot-tools-native') | 17 | vars = get_bb_vars(['RECIPE_SYSROOT_NATIVE', 'bindir'], 'u-boot-tools-native') |
18 | return os.path.join(vars['RECIPE_SYSROOT_NATIVE'], vars['bindir']) | ||
18 | 19 | ||
19 | def _verify_fit_image_signature(self, uboot_tools_sysroot_native, fitimage_path, dtb_path, conf_name=None): | 20 | def _run_dumpimage(self, fitimage_path, uboot_tools_bindir): |
21 | dumpimage_path = os.path.join(uboot_tools_bindir, 'dumpimage') | ||
22 | return runCmd('%s -l %s' % (dumpimage_path, fitimage_path)) | ||
23 | |||
24 | def _verify_fit_image_signature(self, uboot_tools_bindir, fitimage_path, dtb_path, conf_name=None): | ||
20 | """Verify the signature of a fit contfiguration | 25 | """Verify the signature of a fit contfiguration |
21 | 26 | ||
22 | The fit_check_sign utility from u-boot-tools-native is called. | 27 | The fit_check_sign utility from u-boot-tools-native is called. |
23 | uboot-fit_check_sign -f fitImage -k $dtb_name -c conf-$dtb_name | 28 | uboot-fit_check_sign -f fitImage -k $dtb_name -c conf-$dtb_name |
24 | """ | 29 | """ |
25 | fit_check_sign_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'uboot-fit_check_sign') | 30 | fit_check_sign_path = os.path.join(uboot_tools_bindir, 'uboot-fit_check_sign') |
26 | cmd = '%s -f %s -k %s' % (fit_check_sign_path, fitimage_path, dtb_path) | 31 | cmd = '%s -f %s -k %s' % (fit_check_sign_path, fitimage_path, dtb_path) |
27 | if conf_name: | 32 | if conf_name: |
28 | cmd += ' -c %s' % conf_name | 33 | cmd += ' -c %s' % conf_name |
@@ -238,12 +243,11 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'" | |||
238 | self.assertEqual(value, reqvalue) | 243 | self.assertEqual(value, reqvalue) |
239 | 244 | ||
240 | # Dump the image to see if it really got signed | 245 | # Dump the image to see if it really got signed |
241 | uboot_tools_sysroot_native = self._setup_uboot_tools_native() | 246 | uboot_tools_bindir = self._setup_uboot_tools_native() |
242 | dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage') | 247 | dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir) |
243 | result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path)) | ||
244 | in_signed = None | 248 | in_signed = None |
245 | signed_sections = {} | 249 | signed_sections = {} |
246 | for line in result.output.splitlines(): | 250 | for line in dumpimage_result.output.splitlines(): |
247 | if line.startswith((' Configuration', ' Image')): | 251 | if line.startswith((' Configuration', ' Image')): |
248 | in_signed = re.search(r'\((.*)\)', line).groups()[0] | 252 | in_signed = re.search(r'\((.*)\)', line).groups()[0] |
249 | elif re.match('^ *', line) in (' ', ''): | 253 | elif re.match('^ *', line) in (' ', ''): |
@@ -272,7 +276,7 @@ UBOOT_MKIMAGE_SIGN_ARGS = "-c '%s'" | |||
272 | 276 | ||
273 | # Verify the signature for all configurations = DTBs | 277 | # Verify the signature for all configurations = DTBs |
274 | for dtb in ['am335x-bone.dtb', 'am335x-boneblack.dtb', 'am335x-bonegreen.dtb']: | 278 | for dtb in ['am335x-bone.dtb', 'am335x-boneblack.dtb', 'am335x-bonegreen.dtb']: |
275 | self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, | 279 | self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, |
276 | os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], dtb), 'conf-' + dtb) | 280 | os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], dtb), 'conf-' + dtb) |
277 | 281 | ||
278 | def test_uboot_fit_image(self): | 282 | def test_uboot_fit_image(self): |
@@ -548,12 +552,11 @@ UBOOT_FIT_HASH_ALG = "sha256" | |||
548 | self.assertEqual(value, reqvalue) | 552 | self.assertEqual(value, reqvalue) |
549 | 553 | ||
550 | # Dump the image to see if it really got signed | 554 | # Dump the image to see if it really got signed |
551 | uboot_tools_sysroot_native = self._setup_uboot_tools_native() | 555 | uboot_tools_bindir = self._setup_uboot_tools_native() |
552 | dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage') | 556 | dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir) |
553 | result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path)) | ||
554 | in_signed = None | 557 | in_signed = None |
555 | signed_sections = {} | 558 | signed_sections = {} |
556 | for line in result.output.splitlines(): | 559 | for line in dumpimage_result.output.splitlines(): |
557 | if line.startswith((' Image')): | 560 | if line.startswith((' Image')): |
558 | in_signed = re.search(r'\((.*)\)', line).groups()[0] | 561 | in_signed = re.search(r'\((.*)\)', line).groups()[0] |
559 | elif re.match(' \w', line): | 562 | elif re.match(' \w', line): |
@@ -577,7 +580,7 @@ UBOOT_FIT_HASH_ALG = "sha256" | |||
577 | self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.") | 580 | self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.") |
578 | 581 | ||
579 | # Verify the signature | 582 | # Verify the signature |
580 | self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, | 583 | self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, |
581 | os.path.join(deploy_dir_image, 'u-boot-spl.dtb')) | 584 | os.path.join(deploy_dir_image, 'u-boot-spl.dtb')) |
582 | 585 | ||
583 | 586 | ||
@@ -696,12 +699,11 @@ FIT_SIGN_INDIVIDUAL = "1" | |||
696 | self.assertEqual(value, reqvalue) | 699 | self.assertEqual(value, reqvalue) |
697 | 700 | ||
698 | # Dump the image to see if it really got signed | 701 | # Dump the image to see if it really got signed |
699 | uboot_tools_sysroot_native = self._setup_uboot_tools_native() | 702 | uboot_tools_bindir = self._setup_uboot_tools_native() |
700 | dumpimage_path = os.path.join(uboot_tools_sysroot_native, 'usr', 'bin', 'dumpimage') | 703 | dumpimage_result = self._run_dumpimage(fitimage_path, uboot_tools_bindir) |
701 | result = runCmd('%s -l %s' % (dumpimage_path, fitimage_path)) | ||
702 | in_signed = None | 704 | in_signed = None |
703 | signed_sections = {} | 705 | signed_sections = {} |
704 | for line in result.output.splitlines(): | 706 | for line in dumpimage_result.output.splitlines(): |
705 | if line.startswith((' Image')): | 707 | if line.startswith((' Image')): |
706 | in_signed = re.search(r'\((.*)\)', line).groups()[0] | 708 | in_signed = re.search(r'\((.*)\)', line).groups()[0] |
707 | elif re.match(' \w', line): | 709 | elif re.match(' \w', line): |
@@ -725,7 +727,7 @@ FIT_SIGN_INDIVIDUAL = "1" | |||
725 | self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.") | 727 | self.assertEqual(found_comments, 2, "Expected 2 signed and commented section in the fitImage.") |
726 | 728 | ||
727 | # Verify the signature | 729 | # Verify the signature |
728 | self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, | 730 | self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, |
729 | os.path.join(deploy_dir_image, 'u-boot-spl.dtb')) | 731 | os.path.join(deploy_dir_image, 'u-boot-spl.dtb')) |
730 | 732 | ||
731 | 733 | ||
@@ -850,5 +852,5 @@ FIT_HASH_ALG = "sha256" | |||
850 | self.assertEqual(len(list(filter(rx_sign_line.match, node))), 1, "kernel hash not signed") | 852 | self.assertEqual(len(list(filter(rx_sign_line.match, node))), 1, "kernel hash not signed") |
851 | 853 | ||
852 | # Verify the signature | 854 | # Verify the signature |
853 | uboot_tools_sysroot_native = self._setup_uboot_tools_native() | 855 | uboot_tools_bindir = self._setup_uboot_tools_native() |
854 | self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], 'am335x-bone.dtb')) | 856 | self._verify_fit_image_signature(uboot_tools_bindir, fitimage_path, os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], 'am335x-bone.dtb')) |