return None
return sym.address
+def GetPackString(sym, msg):
+ """Get the struct.pack/unpack string to use with a given symbol
+
+ Args:
+ sym (Symbol): Symbol to check. Only the size member is checked
+ @msg (str): String which indicates the entry being processed, used for
+ errors
+
+ Returns:
+ str: struct string to use, .e.g. '<I'
+
+ Raises:
+ ValueError: Symbol has an unexpected size
+ """
+ if sym.size == 4:
+ return '<I'
+ elif sym.size == 8:
+ return '<Q'
+ else:
+ raise ValueError('%s has size %d: only 4 and 8 are supported' %
+ (msg, sym.size))
+
def LookupAndWriteSymbols(elf_fname, entry, section):
"""Replace all symbols in an entry with their correct values
raise ValueError('%s has offset %x (size %x) but the contents '
'size is %x' % (entry.GetPath(), offset,
sym.size, entry.contents_size))
- if sym.size == 4:
- pack_string = '<I'
- elif sym.size == 8:
- pack_string = '<Q'
- else:
- raise ValueError('%s has size %d: only 4 and 8 are supported' %
- (msg, sym.size))
-
+ pack_string = GetPackString(sym, msg)
if name == '_binman_sym_magic':
value = BINMAN_SYM_MAGIC_VALUE
else:
entry.data = (entry.data[:offset] + value_bytes +
entry.data[offset + sym.size:])
+def GetSymbolValue(sym, data, msg):
+ """Get the value of a symbol
+
+ This can only be used on symbols with an integer value.
+
+ Args:
+ sym (Symbol): Symbol to check
+ data (butes): Data for the ELF file - the symbol data appears at offset
+ sym.offset
+ @msg (str): String which indicates the entry being processed, used for
+ errors
+
+ Returns:
+ int: Value of the symbol
+
+ Raises:
+ ValueError: Symbol has an unexpected size
+ """
+ pack_string = GetPackString(sym, msg)
+ value = struct.unpack(pack_string, data[sym.offset:sym.offset + sym.size])
+ return value[0]
+
def MakeElf(elf_fname, text, data):
"""Make an elf file with the given data in a single section