binman: Add a function to decode an ELF file

Add a function which decodes an ELF file, working out where in memory each
part of the data should be written.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2019-07-08 13:18:35 -06:00
parent f58558a5ae
commit d8d40748dd
3 changed files with 102 additions and 0 deletions

View File

@@ -156,6 +156,27 @@ class TestElf(unittest.TestCase):
self.assertEqual(expected_text + expected_data, data)
shutil.rmtree(outdir)
def testDecodeElf(self):
"""Test for the MakeElf function"""
if not elf.ELF_TOOLS:
self.skipTest('Python elftools not available')
outdir = tempfile.mkdtemp(prefix='elf.')
expected_text = b'1234'
expected_data = b'wxyz'
elf_fname = os.path.join(outdir, 'elf')
elf.MakeElf(elf_fname, expected_text, expected_data)
data = tools.ReadFile(elf_fname)
load = 0xfef20000
entry = load + 2
expected = expected_text + expected_data
self.assertEqual(elf.ElfInfo(expected, load, entry, len(expected)),
elf.DecodeElf(data, 0))
self.assertEqual(elf.ElfInfo(b'\0\0' + expected[2:],
load, entry, len(expected)),
elf.DecodeElf(data, load + 2))
#shutil.rmtree(outdir)
if __name__ == '__main__':
unittest.main()