From 01a609930b996499b36418108125ee53ab7094b5 Mon Sep 17 00:00:00 2001 From: Simon Glass <sjg@chromium.org> Date: Mon, 26 Aug 2024 13:11:39 -0600 Subject: [PATCH] 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 <sjg@chromium.org> --- tools/binman/binman.rst | 4 +++- tools/binman/elf.py | 3 ++- tools/binman/ftest.py | 36 +++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index 0cafc36bdc..04564f4f66 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -494,7 +494,9 @@ point into the image. For example, say SPL is at the start of the image and linked to start at address 80108000. If U-Boot's image-pos is 0x8000 then binman will write an image-pos for U-Boot of 80110000 into the SPL binary, since it assumes the image is loaded -to 80108000, with SPL at 80108000 and U-Boot at 80110000. +to 80108000, with SPL at 80108000 and U-Boot at 80110000. In other words, the +positions are calculated relative to the start address of the image to which +they are being written. For x86 devices (with the end-at-4gb property) this base address is not added since it is assumed that images are XIP and the offsets already include the diff --git a/tools/binman/elf.py b/tools/binman/elf.py index 1c3b1e225f..73394830eb 100644 --- a/tools/binman/elf.py +++ b/tools/binman/elf.py @@ -247,7 +247,8 @@ def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False, entry entry: Entry to process section: Section which can be used to lookup symbol values - base_sym: Base symbol marking the start of the image + base_sym: Base symbol marking the start of the image (__image_copy_start + by default) Returns: int: Number of symbols written diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index b133c76188..7b4454bd34 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('<LLQLL', elf.BINMAN_SYM_MAGIC_VALUE, - 0x00, u_boot_offset + len(U_BOOT_DATA), - 0x10 + u_boot_offset, 0x04) + vals = (elf.BINMAN_SYM_MAGIC_VALUE, 0x00, + u_boot_offset + len(U_BOOT_DATA), + 0x10 + u_boot_offset, 0x04) + sym_values = struct.pack('<LLQLL', *vals) if no_write_symbols: - expected = (base_data + - tools.get_bytes(0xff, 0x38 - len(base_data)) + - U_BOOT_DATA + base_data) + self.assertEqual( + base_data + + tools.get_bytes(0xff, 0x38 - len(base_data)) + + U_BOOT_DATA + base_data, data) else: + got_vals = struct.unpack('<LLQLL', data[:24]) + + # For debugging: + #print('expect:', list(f'{v:x}' for v in vals)) + #print(' got:', list(f'{v:x}' for v in got_vals)) + + self.assertEqual(vals, got_vals) + self.assertEqual(sym_values, data[:24]) + + blen = len(base_data) + 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]) + + self.assertEqual(sym_values, 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_values + base_data[24:]) - self.assertEqual(expected, data) + self.assertEqual(expected, data) def testSymbols(self): """Test binman can assign symbols embedded in U-Boot""" -- 2.39.5