From b87064c2496785dde9e33fcdf84175d64163db57 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 24 Aug 2019 07:23:05 -0600 Subject: [PATCH] binman: Allow support for writing a size symbol to binaries It is useful to be able to access the size of an image in SPL, with something like: binman_sym_declare(unsigned long, u_boot_any, size); ... ulong u_boot_size = binman_sym(ulong, u_boot_any, size); Add support for this and update the tests. Signed-off-by: Simon Glass --- tools/binman/elf_test.py | 4 ++-- tools/binman/etype/section.py | 2 ++ tools/binman/ftest.py | 14 +++++++------- tools/binman/test/u_boot_binman_syms.c | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index f05545bcb1..c0c11cb340 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -155,11 +155,11 @@ class TestElf(unittest.TestCase): This should produce -1 values for all thress symbols, taking up the first 16 bytes of the image. """ - entry = FakeEntry(20) + entry = FakeEntry(24) section = FakeSection(sym_value=None) elf_fname = self.ElfTestFile('u_boot_binman_syms') syms = elf.LookupAndWriteSymbols(elf_fname, entry, section) - self.assertEqual(tools.GetBytes(255, 16) + tools.GetBytes(ord('a'), 4), + self.assertEqual(tools.GetBytes(255, 20) + tools.GetBytes(ord('a'), 4), entry.data) def testDebug(self): diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 8fea6e0b24..ab0c42cee0 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -344,6 +344,8 @@ class Entry_section(Entry): return entry.offset elif prop_name == 'image_pos': return entry.image_pos + if prop_name == 'size': + return entry.size else: raise ValueError("%s: No such property '%s'" % (msg, prop_name)) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 5433c80e8e..6d59fa4874 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1236,10 +1236,10 @@ class TestFunctional(unittest.TestCase): self._SetupSplElf('u_boot_binman_syms') data = self._DoReadFile('053_symbols.dts') - sym_values = struct.pack('