spl: binman: Check at runtime if binman symbols were filled in
Binman lets us declare symbols in SPL/TPL that refer to other entries in the same binman image as them. These symbols are filled in with the correct values while binman assembles the images, but this is done in-memory only. Symbols marked as optional can be filled with BINMAN_SYM_MISSING as an error value if their referred entry is missing. However, the unmodified SPL/TPL binaries are still available on disk, and can be used by people. For these files, nothing ensures that the symbols are set to this error value, and they will be considered valid when they are not. Empirically, all symbols show up as zero in a sandbox_vpl build when we run e.g. tpl/u-boot-tpl directly. On the other hand, zero is a perfectly fine value for a binman-written symbol, so we cannot say the symbols have wrong values based on that. Declare a magic symbol that binman always fills in with a fixed value. Check this value as an indicator that symbols were filled in correctly. Return the error value for all symbols when this magic symbol has the wrong value. For binman tests, we need to make room for the new symbol in the mocked SPL/TPL data by extending them by four bytes. This messes up some test image layouts. Fix the affected values, and check the magic symbol wherever it makes sense. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:

committed by
Simon Glass

parent
3a7d327876
commit
367ecbf2d3
@@ -127,7 +127,7 @@ class TestElf(unittest.TestCase):
|
||||
elf_fname = self.ElfTestFile('u_boot_binman_syms')
|
||||
with self.assertRaises(ValueError) as e:
|
||||
elf.LookupAndWriteSymbols(elf_fname, entry, section)
|
||||
self.assertIn('entry_path has offset 4 (size 8) but the contents size '
|
||||
self.assertIn('entry_path has offset 8 (size 8) but the contents size '
|
||||
'is a', str(e.exception))
|
||||
|
||||
def testMissingImageStart(self):
|
||||
@@ -161,18 +161,20 @@ class TestElf(unittest.TestCase):
|
||||
This should produce -1 values for all thress symbols, taking up the
|
||||
first 16 bytes of the image.
|
||||
"""
|
||||
entry = FakeEntry(24)
|
||||
entry = FakeEntry(28)
|
||||
section = FakeSection(sym_value=None)
|
||||
elf_fname = self.ElfTestFile('u_boot_binman_syms')
|
||||
elf.LookupAndWriteSymbols(elf_fname, entry, section)
|
||||
self.assertEqual(tools.get_bytes(255, 20) + tools.get_bytes(ord('a'), 4),
|
||||
entry.data)
|
||||
expected = (struct.pack('<L', elf.BINMAN_SYM_MAGIC_VALUE) +
|
||||
tools.get_bytes(255, 20) +
|
||||
tools.get_bytes(ord('a'), 4))
|
||||
self.assertEqual(expected, entry.data)
|
||||
|
||||
def testDebug(self):
|
||||
"""Check that enabling debug in the elf module produced debug output"""
|
||||
try:
|
||||
tout.init(tout.DEBUG)
|
||||
entry = FakeEntry(20)
|
||||
entry = FakeEntry(24)
|
||||
section = FakeSection()
|
||||
elf_fname = self.ElfTestFile('u_boot_binman_syms')
|
||||
with test_util.capture_sys_output() as (stdout, stderr):
|
||||
|
Reference in New Issue
Block a user