From d8d40748dd6f202948a8173073cf34f3b6468b6d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 8 Jul 2019 13:18:35 -0600 Subject: 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 --- tools/binman/elf_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tools/binman/elf_test.py') diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index 3172982427..e2506377f2 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -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() -- cgit v1.2.3