From 7d77ad906146f2fb0811e5780a0109679e7556b5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 26 Aug 2024 13:11:29 -0600 Subject: binman: Fix up test coverage for mkeficapsule Add tests for missing tools to complete the test coverage for this etype. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 2577c0016c0..6f515960c85 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -403,8 +403,10 @@ class TestFunctional(unittest.TestCase): test_section_timeout: True to force the first time to timeout, as used in testThreadTimeout() update_fdt_in_elf: Value to pass with --update-fdt-in-elf=xxx - force_missing_tools (str): comma-separated list of bintools to + force_missing_bintools (str): comma-separated list of bintools to regard as missing + ignore_missing (bool): True to return success even if there are + missing blobs or bintools output_dir: Specific output directory to use for image using -O Returns: @@ -7690,6 +7692,24 @@ fdt fdtmap Extract the devicetree blob from the fdtmap # Make sure the other node is gone self.assertIsNone(dtb.GetNode('/node/other-node')) + def testMkeficapsuleMissing(self): + """Test that binman complains if mkeficapsule is missing""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('311_capsule.dts', + force_missing_bintools='mkeficapsule') + self.assertIn("Node '/binman/efi-capsule': Missing tool: 'mkeficapsule'", + str(e.exception)) + + def testMkeficapsuleMissingOk(self): + """Test that binman deals with mkeficapsule being missing""" + with test_util.capture_sys_output() as (stdout, stderr): + ret = self._DoTestFile('311_capsule.dts', + force_missing_bintools='mkeficapsule', + allow_missing=True) + self.assertEqual(103, ret) + err = stderr.getvalue() + self.assertRegex(err, "Image 'image'.*missing bintools.*: mkeficapsule") + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 52983ff54b3eca3485dcd54060bdb65423dac7ac Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 26 Aug 2024 13:11:34 -0600 Subject: binman: Update fdt-list-dir to use the provided directory Since the files are known to be in the provided directory, use that instead of requiring it to be added to the list of input directories. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 6f515960c85..3f05559501d 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -7626,7 +7626,12 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testFitFdtListDir(self): """Test an image with an FIT with FDT images using fit,fdt-list-dir""" - self.CheckFitFdt('333_fit_fdt_dir.dts', False) + old_dir = os.getcwd() + try: + os.chdir(self._indir) + self.CheckFitFdt('333_fit_fdt_dir.dts', False) + finally: + os.chdir(old_dir) def testFitFdtCompat(self): """Test an image with an FIT with compatible in the config nodes""" -- cgit v1.2.3 From c8b7d72b43c649070d29228899277ac3b39ccf29 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 26 Aug 2024 13:11:37 -0600 Subject: binman: fit: Refine handling of devicetrees for OF_UPSTREAM With OF_UPSTREAM the dts files are in an SoC-specific subdirectory, meaning that the resulting dtb files all end up in a similar subdirectory. We don't want the subdirectory name to appear as a node name in the FIT, so handle this as a special case. Also the default devicetree may have a directory-name prefix, so handle that when searching through the available devicetree files. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 3f05559501d..b133c76188c 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -4183,7 +4183,8 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('172_scp.dts') self.assertEqual(SCP_DATA, data[:len(SCP_DATA)]) - def CheckFitFdt(self, dts='170_fit_fdt.dts', use_fdt_list=True): + def CheckFitFdt(self, dts='170_fit_fdt.dts', use_fdt_list=True, + default_dt=None): """Check an image with an FIT with multiple FDT images""" def _CheckFdt(seq, expected_data): """Check the FDT nodes @@ -4227,6 +4228,8 @@ class TestFunctional(unittest.TestCase): } if use_fdt_list: entry_args['of-list'] = 'test-fdt1 test-fdt2' + if default_dt: + entry_args['default-dt'] = default_dt data = self._DoReadFileDtb( dts, entry_args=entry_args, @@ -7633,6 +7636,16 @@ fdt fdtmap Extract the devicetree blob from the fdtmap finally: os.chdir(old_dir) + def testFitFdtListDirDefault(self): + """Test an FIT fit,fdt-list-dir where the default DT in is a subdir""" + old_dir = os.getcwd() + try: + os.chdir(self._indir) + self.CheckFitFdt('333_fit_fdt_dir.dts', False, + default_dt='rockchip/test-fdt2') + finally: + os.chdir(old_dir) + def testFitFdtCompat(self): """Test an image with an FIT with compatible in the config nodes""" entry_args = { -- cgit v1.2.3 From 01a609930b996499b36418108125ee53ab7094b5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 26 Aug 2024 13:11:39 -0600 Subject: binman: Add minor improvements to symbol-writing Add a clarification to the documentation and add a missing comment. Also update the test so that when it fails it is easier to see what is going on, rather than having to decode hex strings. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index b133c76188c..7b4454bd342 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1526,18 +1526,40 @@ class TestFunctional(unittest.TestCase): # The image should contain the symbols from u_boot_binman_syms.c # Note that image_pos is adjusted by the base address of the image, # which is 0x10 in our test image - sym_values = struct.pack(' Date: Mon, 26 Aug 2024 13:11:40 -0600 Subject: binman: Provide a way to set the symbol base address The base address of the ELF containing symbols is normally added to any symbols written, so that the value points to the correct address in memory when everything is loaded. When the binary resides on disk, a different offset may be needed, typically 0. Provide a way to specify this. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 7b4454bd342..ecfcd6bd915 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1500,7 +1500,8 @@ class TestFunctional(unittest.TestCase): self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)]) def checkSymbols(self, dts, base_data, u_boot_offset, entry_args=None, - use_expanded=False, no_write_symbols=False): + use_expanded=False, no_write_symbols=False, + symbols_base=None): """Check the image contains the expected symbol values Args: @@ -1512,6 +1513,8 @@ class TestFunctional(unittest.TestCase): value: value of that arg use_expanded: True to use expanded entries where available, e.g. 'u-boot-expanded' instead of 'u-boot' + symbols_base (int): Value to expect for symbols-base in u-boot-spl, + None if none """ elf_fname = self.ElfTestFile('u_boot_binman_syms') syms = elf.GetSymbols(elf_fname, ['binman', 'image']) @@ -1526,10 +1529,19 @@ class TestFunctional(unittest.TestCase): # The image should contain the symbols from u_boot_binman_syms.c # Note that image_pos is adjusted by the base address of the image, # which is 0x10 in our test image - vals = (elf.BINMAN_SYM_MAGIC_VALUE, 0x00, + vals2 = (elf.BINMAN_SYM_MAGIC_VALUE, 0x00, u_boot_offset + len(U_BOOT_DATA), 0x10 + u_boot_offset, 0x04) + + # u-boot-spl has a symbols-base property, so take that into account if + # required. The caller must supply the value + vals = list(vals2) + if symbols_base is not None: + vals[3] = symbols_base + u_boot_offset + vals = tuple(vals) + sym_values = struct.pack(' Date: Mon, 26 Aug 2024 13:11:42 -0600 Subject: binman: Allow image_pos to be None when writing symbols Some images do not have an image_pos value, for example an image which is part of a compressed section and therefore cannot be accessed directly. Handle this case, returning None as the value. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index ecfcd6bd915..58f9d8256e8 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -505,8 +505,9 @@ class TestFunctional(unittest.TestCase): return dtb.GetContents() def _DoReadFileDtb(self, fname, use_real_dtb=False, use_expanded=False, - map=False, update_dtb=False, entry_args=None, - reset_dtbs=True, extra_indirs=None, threads=None): + verbosity=None, map=False, update_dtb=False, + entry_args=None, reset_dtbs=True, extra_indirs=None, + threads=None): """Run binman and return the resulting image This runs binman with a given test file and then reads the resulting @@ -523,6 +524,7 @@ class TestFunctional(unittest.TestCase): But in some test we need the real contents. use_expanded: True to use expanded entries where available, e.g. 'u-boot-expanded' instead of 'u-boot' + verbosity: Verbosity level to use (0-3, None=don't set it) map: True to output map files for the images update_dtb: Update the offset and size of each entry in the device tree before packing it into the image @@ -559,7 +561,8 @@ class TestFunctional(unittest.TestCase): try: retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb, entry_args=entry_args, use_real_dtb=use_real_dtb, - use_expanded=use_expanded, extra_indirs=extra_indirs, + use_expanded=use_expanded, verbosity=verbosity, + extra_indirs=extra_indirs, threads=threads) self.assertEqual(0, retcode) out_dtb_fname = tools.get_output_filename('u-boot.dtb.out') @@ -1507,7 +1510,8 @@ class TestFunctional(unittest.TestCase): Args: dts: Device tree file to use for test base_data: Data before and after 'u-boot' section - u_boot_offset: Offset of 'u-boot' section in image + u_boot_offset (int): Offset of 'u-boot' section in image, or None if + the offset not available due to it being in a compressed section entry_args: Dict of entry args to supply to binman key: arg name value: value of that arg @@ -1525,13 +1529,20 @@ class TestFunctional(unittest.TestCase): self._SetupSplElf('u_boot_binman_syms') data = self._DoReadFileDtb(dts, entry_args=entry_args, - use_expanded=use_expanded)[0] + use_expanded=use_expanded, + verbosity=None if u_boot_offset else 3)[0] + + # The lz4-compressed version of the U-Boot data is 19 bytes long + comp_uboot_len = 19 + # The image should contain the symbols from u_boot_binman_syms.c # Note that image_pos is adjusted by the base address of the image, # which is 0x10 in our test image + # If u_boot_offset is None, Binman should write -1U into the image vals2 = (elf.BINMAN_SYM_MAGIC_VALUE, 0x00, - u_boot_offset + len(U_BOOT_DATA), - 0x10 + u_boot_offset, 0x04) + u_boot_offset + len(U_BOOT_DATA) if u_boot_offset else + len(U_BOOT_SPL_DATA) + 1 + comp_uboot_len, + 0x10 + u_boot_offset if u_boot_offset else 0xffffffff, 0x04) # u-boot-spl has a symbols-base property, so take that into account if # required. The caller must supply the value @@ -1561,17 +1572,21 @@ class TestFunctional(unittest.TestCase): self.assertEqual(base_data[24:], data[24:blen]) self.assertEqual(0xff, data[blen]) - ofs = blen + 1 + len(U_BOOT_DATA) - self.assertEqual(U_BOOT_DATA, data[blen + 1:ofs]) + if u_boot_offset: + ofs = blen + 1 + len(U_BOOT_DATA) + self.assertEqual(U_BOOT_DATA, data[blen + 1:ofs]) + else: + ofs = blen + 1 + comp_uboot_len self.assertEqual(sym_values2, data[ofs:ofs + 24]) self.assertEqual(base_data[24:], data[ofs + 24:]) # Just repeating the above asserts all at once, for clarity - expected = (sym_values + base_data[24:] + - tools.get_bytes(0xff, 1) + U_BOOT_DATA + sym_values2 + - base_data[24:]) - self.assertEqual(expected, data) + if u_boot_offset: + expected = (sym_values + base_data[24:] + + tools.get_bytes(0xff, 1) + U_BOOT_DATA + + sym_values2 + base_data[24:]) + self.assertEqual(expected, data) def testSymbols(self): """Test binman can assign symbols embedded in U-Boot""" @@ -7777,6 +7792,14 @@ fdt fdtmap Extract the devicetree blob from the fdtmap entry_args=entry_args, use_expanded=True, symbols_base=0) + def testSymbolsCompressed(self): + """Test binman complains about symbols from a compressed section""" + with test_util.capture_sys_output() as (stdout, stderr): + self.checkSymbols('338_symbols_comp.dts', U_BOOT_SPL_DATA, None) + out = stdout.getvalue() + self.assertIn('Symbol-writing: no value for /binman/section/u-boot', + out) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From ac0876c890c2dcaa4e21ce36bfa2ea3e02139a01 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 26 Aug 2024 13:11:43 -0600 Subject: binman: Make a start on an iMX8 test This patch is for Marek, to provide a starting point. To try it, use 'binman test -T' and see the missing coverage. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 58f9d8256e8..e3f231e4bcc 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -7800,6 +7800,10 @@ fdt fdtmap Extract the devicetree blob from the fdtmap self.assertIn('Symbol-writing: no value for /binman/section/u-boot', out) + def testNxpImx8Image(self): + """Test that binman can produce an iMX8 image""" + self._DoTestFile('339_nxp_imx8.dts') + if __name__ == "__main__": unittest.main() -- cgit v1.2.3