From c1157860c5e9ca45e41859e013ed83919e7397f0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 11 Jan 2023 16:10:17 -0700 Subject: binman: Provide general support for updating ELF symbols The current support for updating variables in a binary is hard-coded to work with U-Boot: - It assumes the image starts at __image_copy_start - It uses the existing U-Boot-specific entry types It is useful for other projects to use these feature. Add properties to enable writing symbols for any blob, a way of specifying the base symbol and a way of providing the ELF filename to allow symbol lookup to take place. With this it is possible to update a Zephyr image, such as zephyr.bin after it has been built. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index aea8a5f7589..17b0431d4f3 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6262,6 +6262,25 @@ fdt fdtmap Extract the devicetree blob from the fdtmap "Node '/binman/inset': 'fill' entry is missing properties: size", str(exc.exception)) + def testBlobSymbol(self): + """Test a blob with symbols read from an ELF file""" + elf_fname = self.ElfTestFile('blob_syms') + TestFunctional._MakeInputFile('blob_syms', tools.read_file(elf_fname)) + TestFunctional._MakeInputFile('blob_syms.bin', + tools.read_file(self.ElfTestFile('blob_syms.bin'))) + + data = self._DoReadFile('273_blob_symbol.dts') + + syms = elf.GetSymbols(elf_fname, ['binman', 'image']) + addr = elf.GetSymbolAddress(elf_fname, '__my_start_sym') + self.assertEqual(syms['_binman_sym_magic'].address, addr) + self.assertEqual(syms['_binman_inset_prop_offset'].address, addr + 4) + self.assertEqual(syms['_binman_inset_prop_size'].address, addr + 8) + + sym_values = struct.pack('