summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/binman/elf.py10
-rw-r--r--tools/binman/elf_test.py16
2 files changed, 20 insertions, 6 deletions
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 4219001fea..2ecc95f7eb 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -447,13 +447,15 @@ def DecodeElf(data, location):
Returns:
ElfInfo object containing information about the decoded ELF file
"""
+ if not ELF_TOOLS:
+ raise ValueError("Python: No module named 'elftools'")
file_size = len(data)
with io.BytesIO(data) as fd:
elf = ELFFile(fd)
- data_start = 0xffffffff;
- data_end = 0;
- mem_end = 0;
- virt_to_phys = 0;
+ data_start = 0xffffffff
+ data_end = 0
+ mem_end = 0
+ virt_to_phys = 0
for i in range(elf.num_segments()):
segment = elf.get_segment(i)
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index cc95b424b3..e3dee79d06 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -255,8 +255,20 @@ class TestElf(unittest.TestCase):
fname = self.ElfTestFile('embed_data')
with self.assertRaises(ValueError) as e:
elf.GetSymbolFileOffset(fname, ['embed_start', 'embed_end'])
- self.assertIn("Python: No module named 'elftools'",
- str(e.exception))
+ with self.assertRaises(ValueError) as e:
+ elf.DecodeElf(tools.read_file(fname), 0xdeadbeef)
+ with self.assertRaises(ValueError) as e:
+ elf.GetFileOffset(fname, 0xdeadbeef)
+ with self.assertRaises(ValueError) as e:
+ elf.GetSymbolFromAddress(fname, 0xdeadbeef)
+ with self.assertRaises(ValueError) as e:
+ entry = FakeEntry(10)
+ section = FakeSection()
+ elf.LookupAndWriteSymbols(fname, entry, section, True)
+
+ self.assertIn(
+ "Section 'section_path': entry 'entry_path': Cannot write symbols to an ELF file without Python elftools",
+ str(e.exception))
finally:
elf.ELF_TOOLS = old_val