[PATCH v3 06/26] elf: Rename load_segments() and module failure
Simon Glass
sjg at chromium.org
Sun Mar 6 04:18:57 CET 2022
Rename this function to make it clear that it only reads loadable
segments. Also update the error for missing module to better match the
message emitted by Python.
Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
Suggested-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
---
(no changes since v2)
Changes in v2:
- Add new patch to rename load_segments() and module failure
tools/binman/elf.py | 6 +++---
tools/binman/elf_test.py | 18 +++++++++---------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 5e7d6ae7b9..016e9b2885 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -105,7 +105,7 @@ def GetSymbolFileOffset(fname, patterns):
return addr - seg['p_vaddr'] + seg['p_offset']
if not ELF_TOOLS:
- raise ValueError('Python elftools package is not available')
+ raise ValueError("Python: No module named 'elftools'")
syms = {}
with open(fname, 'rb') as fd:
@@ -371,7 +371,7 @@ def UpdateFile(infile, outfile, start_sym, end_sym, insert):
tools.write_file(outfile, newdata)
tout.info('Written to offset %#x' % syms[start_sym].offset)
-def read_segments(data):
+def read_loadable_segments(data):
"""Read segments from an ELF file
Args:
@@ -389,7 +389,7 @@ def read_segments(data):
ValueError: elftools is not available
"""
if not ELF_TOOLS:
- raise ValueError('Python elftools package is not available')
+ raise ValueError("Python: No module named 'elftools'")
with io.BytesIO(data) as inf:
try:
elf = ELFFile(inf)
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 5084838b91..555117d33a 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -243,7 +243,7 @@ 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 elftools package is not available',
+ self.assertIn("Python: No module named 'elftools'",
str(e.exception))
finally:
elf.ELF_TOOLS = old_val
@@ -257,31 +257,31 @@ class TestElf(unittest.TestCase):
offset = elf.GetSymbolFileOffset(fname, ['missing_sym'])
self.assertEqual({}, offset)
- def test_read_segments(self):
- """Test for read_segments()"""
+ def test_read_loadable_segments(self):
+ """Test for read_loadable_segments()"""
if not elf.ELF_TOOLS:
self.skipTest('Python elftools not available')
fname = self.ElfTestFile('embed_data')
- segments, entry = elf.read_segments(tools.read_file(fname))
+ segments, entry = elf.read_loadable_segments(tools.read_file(fname))
def test_read_segments_fail(self):
- """Test for read_segments() without elftools"""
+ """Test for read_loadable_segments() without elftools"""
try:
old_val = elf.ELF_TOOLS
elf.ELF_TOOLS = False
fname = self.ElfTestFile('embed_data')
with self.assertRaises(ValueError) as e:
- elf.read_segments(tools.read_file(fname))
- self.assertIn('Python elftools package is not available',
+ elf.read_loadable_segments(tools.read_file(fname))
+ self.assertIn("Python: No module named 'elftools'",
str(e.exception))
finally:
elf.ELF_TOOLS = old_val
def test_read_segments_bad_data(self):
- """Test for read_segments() with an invalid ELF file"""
+ """Test for read_loadable_segments() with an invalid ELF file"""
fname = self.ElfTestFile('embed_data')
with self.assertRaises(ValueError) as e:
- elf.read_segments(tools.get_bytes(100, 100))
+ elf.read_loadable_segments(tools.get_bytes(100, 100))
self.assertIn('Magic number does not match', str(e.exception))
--
2.35.1.616.g0bdcbb4464-goog
More information about the U-Boot
mailing list