return None
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
The entry contents is updated so that values for referenced symbols will be
elf_fname: Filename of ELF image containing the symbol information for
entry
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)
syms = GetSymbols(fname, ['image', 'binman'])
return
for name, sym in syms.iteritems():
if name.startswith('_binman'):
- msg = ("Image '%s': Symbol '%s'\n in entry '%s'" %
- (image.GetPath(), name, entry.GetPath()))
+ msg = ("Section '%s': Symbol '%s'\n in entry '%s'" %
+ (section.GetPath(), name, entry.GetPath()))
offset = sym.address - base.address
if offset < 0 or offset + sym.size > entry.contents_size:
raise ValueError('%s has offset %x (size %x) but the contents '
(msg, sym.size))
# 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:
value += base.address
else:
def GetPath(self):
return 'entry_path'
-class FakeImage:
+class FakeSection:
def __init__(self, sym_value=1):
self.sym_value = sym_value
def GetPath(self):
- return 'image_path'
+ return 'section_path'
def LookupSymbol(self, name, weak, msg):
return self.sym_value
def testMissingFile(self):
entry = FakeEntry(10)
- image = FakeImage()
+ section = FakeSection()
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",
str(e.exception))
def testOutsideFile(self):
entry = FakeEntry(10)
- image = FakeImage()
+ section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
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 '
'is a', str(e.exception))
def testMissingImageStart(self):
entry = FakeEntry(10)
- image = FakeImage()
+ section = FakeSection()
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)
def testBadSymbolSize(self):
entry = FakeEntry(10)
- image = FakeImage()
+ section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_size')
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',
str(e.exception))
def testNoValue(self):
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')
- syms = elf.LookupAndWriteSymbols(elf_fname, entry, image)
+ syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
self.assertEqual(chr(255) * 16 + 'a' * 4, entry.data)
def testDebug(self):
elf.debug = True
entry = FakeEntry(20)
- image = FakeImage()
+ section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
with capture_sys_output() as (stdout, stderr):
- syms = elf.LookupAndWriteSymbols(elf_fname, entry, image)
+ syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
elf.debug = False
self.assertTrue(len(stdout.getvalue()) > 0)