binman: Adjust naming for reading symbols

These functions get the value of a symbol. The reference to ELF files
is confusing since they are reading the position/size of entries, not
ELF symbols. Rename the functions and adjust the comments also.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2024-08-26 13:11:38 -06:00
parent c8b7d72b43
commit f2154c30f6
5 changed files with 19 additions and 21 deletions

View File

@@ -301,8 +301,8 @@ def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False,
value = BINMAN_SYM_MAGIC_VALUE value = BINMAN_SYM_MAGIC_VALUE
else: else:
# Look up the symbol in our entry tables. # Look up the symbol in our entry tables.
value = section.GetImage().LookupImageSymbol(name, sym.weak, value = section.GetImage().GetImageSymbolValue(name, sym.weak,
msg, base_addr) msg, base_addr)
if value is None: if value is None:
value = -1 value = -1
pack_string = pack_string.lower() pack_string = pack_string.lower()

View File

@@ -37,7 +37,7 @@ class FakeSection:
"""A fake Section object, used for testing """A fake Section object, used for testing
This has the minimum feature set needed to support testing elf functions. This has the minimum feature set needed to support testing elf functions.
A LookupSymbol() function is provided which returns a fake value for amu A GetSymbolValue() function is provided which returns a fake value for any
symbol requested. symbol requested.
""" """
def __init__(self, sym_value=1): def __init__(self, sym_value=1):
@@ -46,7 +46,7 @@ class FakeSection:
def GetPath(self): def GetPath(self):
return 'section_path' return 'section_path'
def LookupImageSymbol(self, name, weak, msg, base_addr): def GetImageSymbolValue(self, name, weak, msg, base_addr):
"""Fake implementation which returns the same value for all symbols""" """Fake implementation which returns the same value for all symbols"""
return self.sym_value return self.sym_value

View File

@@ -563,13 +563,13 @@ class Entry_section(Entry):
return entry.GetData(required) return entry.GetData(required)
def LookupEntry(self, entries, sym_name, msg): def LookupEntry(self, entries, sym_name, msg):
"""Look up the entry for an ENF symbol """Look up the entry for a binman symbol
Args: Args:
entries (dict): entries to search: entries (dict): entries to search:
key: entry name key: entry name
value: Entry object value: Entry object
sym_name: Symbol name in the ELF file to look up in the format sym_name: Symbol name to look up in the format
_binman_<entry>_prop_<property> where <entry> is the name of _binman_<entry>_prop_<property> where <entry> is the name of
the entry and <property> is the property to find (e.g. the entry and <property> is the property to find (e.g.
_binman_u_boot_prop_offset). As a special case, you can append _binman_u_boot_prop_offset). As a special case, you can append
@@ -606,11 +606,10 @@ class Entry_section(Entry):
entry = entries[name] entry = entries[name]
return entry, entry_name, prop_name return entry, entry_name, prop_name
def LookupSymbol(self, sym_name, optional, msg, base_addr, entries=None): def GetSymbolValue(self, sym_name, optional, msg, base_addr, entries=None):
"""Look up a symbol in an ELF file """Get the value of a Binman symbol
Looks up a symbol in an ELF file. Only entry types which come from an Look up a Binman symbol and obtain its value.
ELF image can be used by this function.
At present the only entry properties supported are: At present the only entry properties supported are:
offset offset
@@ -618,7 +617,7 @@ class Entry_section(Entry):
size size
Args: Args:
sym_name: Symbol name in the ELF file to look up in the format sym_name: Symbol name to look up in the format
_binman_<entry>_prop_<property> where <entry> is the name of _binman_<entry>_prop_<property> where <entry> is the name of
the entry and <property> is the property to find (e.g. the entry and <property> is the property to find (e.g.
_binman_u_boot_prop_offset). As a special case, you can append _binman_u_boot_prop_offset). As a special case, you can append

View File

@@ -381,11 +381,10 @@ class Image(section.Entry_section):
selected_entries.append(entry) selected_entries.append(entry)
return selected_entries, lines, widths return selected_entries, lines, widths
def LookupImageSymbol(self, sym_name, optional, msg, base_addr): def GetImageSymbolValue(self, sym_name, optional, msg, base_addr):
"""Look up a symbol in an ELF file """Get the value of a Binman symbol
Looks up a symbol in an ELF file. Only entry types which come from an Look up a Binman symbol and obtain its value.
ELF image can be used by this function.
This searches through this image including all of its subsections. This searches through this image including all of its subsections.
@@ -423,8 +422,8 @@ class Image(section.Entry_section):
entries = OrderedDict() entries = OrderedDict()
entries_by_name = {} entries_by_name = {}
self._CollectEntries(entries, entries_by_name, self) self._CollectEntries(entries, entries_by_name, self)
return self.LookupSymbol(sym_name, optional, msg, base_addr, return self.GetSymbolValue(sym_name, optional, msg, base_addr,
entries_by_name) entries_by_name)
def CollectBintools(self): def CollectBintools(self):
"""Collect all the bintools used by this image """Collect all the bintools used by this image

View File

@@ -13,7 +13,7 @@ class TestImage(unittest.TestCase):
def testInvalidFormat(self): def testInvalidFormat(self):
image = Image('name', 'node', test=True) image = Image('name', 'node', test=True)
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
image.LookupSymbol('_binman_something_prop_', False, 'msg', 0) image.GetSymbolValue('_binman_something_prop_', False, 'msg', 0)
self.assertIn( self.assertIn(
"msg: Symbol '_binman_something_prop_' has invalid format", "msg: Symbol '_binman_something_prop_' has invalid format",
str(e.exception)) str(e.exception))
@@ -22,7 +22,7 @@ class TestImage(unittest.TestCase):
image = Image('name', 'node', test=True) image = Image('name', 'node', test=True)
image._entries = {} image._entries = {}
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
image.LookupSymbol('_binman_type_prop_pname', False, 'msg', 0) image.GetSymbolValue('_binman_type_prop_pname', False, 'msg', 0)
self.assertIn("msg: Entry 'type' not found in list ()", self.assertIn("msg: Entry 'type' not found in list ()",
str(e.exception)) str(e.exception))
@@ -30,7 +30,7 @@ class TestImage(unittest.TestCase):
image = Image('name', 'node', test=True) image = Image('name', 'node', test=True)
image._entries = {} image._entries = {}
with capture_sys_output() as (stdout, stderr): with capture_sys_output() as (stdout, stderr):
val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg', 0) val = image.GetSymbolValue('_binman_type_prop_pname', True, 'msg', 0)
self.assertEqual(val, None) self.assertEqual(val, None)
self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n", self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
stderr.getvalue()) stderr.getvalue())
@@ -40,5 +40,5 @@ class TestImage(unittest.TestCase):
image = Image('name', 'node', test=True) image = Image('name', 'node', test=True)
image._entries = {'u-boot': 1} image._entries = {'u-boot': 1}
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
image.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg', 0) image.GetSymbolValue('_binman_u_boot_prop_bad', False, 'msg', 0)
self.assertIn("msg: No such property 'bad", str(e.exception)) self.assertIn("msg: No such property 'bad", str(e.exception))