binman: Rename ELF parameters to 'section'

We now pass a Section object to these functions rather than an Image.
Rename the parameters to avoid confusion.

Signed-off-by: Simon Glass <sjg@chromium.org>
lime2-spi
Simon Glass 6 years ago
parent 8f1da50ccc
commit f55382b5e5
  1. 10
      tools/binman/elf.py
  2. 28
      tools/binman/elf_test.py
  3. 4
      tools/binman/etype/entry.py
  4. 4
      tools/binman/etype/u_boot_spl.py

@ -75,7 +75,7 @@ def GetSymbolAddress(fname, sym_name):
return None return None
return sym.address return sym.address
def LookupAndWriteSymbols(elf_fname, entry, image): def LookupAndWriteSymbols(elf_fname, entry, section):
"""Replace all symbols in an entry with their correct values """Replace all symbols in an entry with their correct values
The entry contents is updated so that values for referenced symbols will be The entry contents is updated so that values for referenced symbols will be
@ -87,7 +87,7 @@ def LookupAndWriteSymbols(elf_fname, entry, image):
elf_fname: Filename of ELF image containing the symbol information for elf_fname: Filename of ELF image containing the symbol information for
entry entry
entry: Entry to process entry: Entry to process
image: Image which can be used to lookup symbol values section: Section which can be used to lookup symbol values
""" """
fname = tools.GetInputFilename(elf_fname) fname = tools.GetInputFilename(elf_fname)
syms = GetSymbols(fname, ['image', 'binman']) syms = GetSymbols(fname, ['image', 'binman'])
@ -98,8 +98,8 @@ def LookupAndWriteSymbols(elf_fname, entry, image):
return return
for name, sym in syms.iteritems(): for name, sym in syms.iteritems():
if name.startswith('_binman'): if name.startswith('_binman'):
msg = ("Image '%s': Symbol '%s'\n in entry '%s'" % msg = ("Section '%s': Symbol '%s'\n in entry '%s'" %
(image.GetPath(), name, entry.GetPath())) (section.GetPath(), name, entry.GetPath()))
offset = sym.address - base.address offset = sym.address - base.address
if offset < 0 or offset + sym.size > entry.contents_size: if offset < 0 or offset + sym.size > entry.contents_size:
raise ValueError('%s has offset %x (size %x) but the contents ' raise ValueError('%s has offset %x (size %x) but the contents '
@ -114,7 +114,7 @@ def LookupAndWriteSymbols(elf_fname, entry, image):
(msg, sym.size)) (msg, sym.size))
# Look up the symbol in our entry tables. # Look up the symbol in our entry tables.
value = image.LookupSymbol(name, sym.weak, msg) value = section.LookupSymbol(name, sym.weak, msg)
if value is not None: if value is not None:
value += base.address value += base.address
else: else:

@ -40,12 +40,12 @@ class FakeEntry:
def GetPath(self): def GetPath(self):
return 'entry_path' return 'entry_path'
class FakeImage: class FakeSection:
def __init__(self, sym_value=1): def __init__(self, sym_value=1):
self.sym_value = sym_value self.sym_value = sym_value
def GetPath(self): def GetPath(self):
return 'image_path' return 'section_path'
def LookupSymbol(self, name, weak, msg): def LookupSymbol(self, name, weak, msg):
return self.sym_value return self.sym_value
@ -67,51 +67,51 @@ class TestElf(unittest.TestCase):
def testMissingFile(self): def testMissingFile(self):
entry = FakeEntry(10) entry = FakeEntry(10)
image = FakeImage() section = FakeSection()
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
syms = elf.LookupAndWriteSymbols('missing-file', entry, image) syms = elf.LookupAndWriteSymbols('missing-file', entry, section)
self.assertIn("Filename 'missing-file' not found in input path", self.assertIn("Filename 'missing-file' not found in input path",
str(e.exception)) str(e.exception))
def testOutsideFile(self): def testOutsideFile(self):
entry = FakeEntry(10) entry = FakeEntry(10)
image = FakeImage() section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms') elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
syms = elf.LookupAndWriteSymbols(elf_fname, entry, image) syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
self.assertIn('entry_path has offset 4 (size 8) but the contents size ' self.assertIn('entry_path has offset 4 (size 8) but the contents size '
'is a', str(e.exception)) 'is a', str(e.exception))
def testMissingImageStart(self): def testMissingImageStart(self):
entry = FakeEntry(10) entry = FakeEntry(10)
image = FakeImage() section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_bad') elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_bad')
self.assertEqual(elf.LookupAndWriteSymbols(elf_fname, entry, image), self.assertEqual(elf.LookupAndWriteSymbols(elf_fname, entry, section),
None) None)
def testBadSymbolSize(self): def testBadSymbolSize(self):
entry = FakeEntry(10) entry = FakeEntry(10)
image = FakeImage() section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_size') elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_size')
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
syms = elf.LookupAndWriteSymbols(elf_fname, entry, image) syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
self.assertIn('has size 1: only 4 and 8 are supported', self.assertIn('has size 1: only 4 and 8 are supported',
str(e.exception)) str(e.exception))
def testNoValue(self): def testNoValue(self):
entry = FakeEntry(20) entry = FakeEntry(20)
image = FakeImage(sym_value=None) section = FakeSection(sym_value=None)
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms') elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
syms = elf.LookupAndWriteSymbols(elf_fname, entry, image) syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
self.assertEqual(chr(255) * 16 + 'a' * 4, entry.data) self.assertEqual(chr(255) * 16 + 'a' * 4, entry.data)
def testDebug(self): def testDebug(self):
elf.debug = True elf.debug = True
entry = FakeEntry(20) entry = FakeEntry(20)
image = FakeImage() section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms') elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
with capture_sys_output() as (stdout, stderr): with capture_sys_output() as (stdout, stderr):
syms = elf.LookupAndWriteSymbols(elf_fname, entry, image) syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
elf.debug = False elf.debug = False
self.assertTrue(len(stdout.getvalue()) > 0) self.assertTrue(len(stdout.getvalue()) > 0)

@ -203,10 +203,10 @@ class Entry(object):
def ProcessContents(self): def ProcessContents(self):
pass pass
def WriteSymbols(self, image): def WriteSymbols(self, section):
"""Write symbol values into binary files for access at run time """Write symbol values into binary files for access at run time
Args: Args:
image: Image containing the entry section: Section containing the entry
""" """
pass pass

@ -18,5 +18,5 @@ class Entry_u_boot_spl(Entry_blob):
def GetDefaultFilename(self): def GetDefaultFilename(self):
return 'spl/u-boot-spl.bin' return 'spl/u-boot-spl.bin'
def WriteSymbols(self, image): def WriteSymbols(self, section):
elf.LookupAndWriteSymbols(self.elf_fname, self, image) elf.LookupAndWriteSymbols(self.elf_fname, self, section)

Loading…
Cancel
Save