binman: Support positioning an entry by and ELF symbol

In some cases it is useful to position an entry over the top of a symbol
in an ELF file. For example, if the symbol holds a version string then it
allows the string to be accessed from the fdtmap.

Add support for this.

Suggested-by: Pali Rohár <pali@kernel.org>
Suggested-by: Keith Short <keithshort@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2023-01-11 16:10:19 -07:00
parent 8f5afe21ae
commit 571bc4e67d
5 changed files with 106 additions and 1 deletions

View file

@ -210,6 +210,29 @@ def GetPackString(sym, msg):
raise ValueError('%s has size %d: only 4 and 8 are supported' %
(msg, sym.size))
def GetSymbolOffset(elf_fname, sym_name, base_sym=None):
"""Read the offset of a symbol compared to base symbol
This is useful for obtaining the value of a single symbol relative to the
base of a binary blob.
Args:
elf_fname: Filename of the ELF file to read
sym_name (str): Name of symbol to read
base_sym (str): Base symbol to sue to calculate the offset (or None to
use '__image_copy_start'
Returns:
int: Offset of the symbol relative to the base symbol
"""
if not base_sym:
base_sym = '__image_copy_start'
fname = tools.get_input_filename(elf_fname)
syms = GetSymbols(fname, [base_sym, sym_name])
base = syms[base_sym].address
val = syms[sym_name].address
return val - base
def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False,
base_sym=None):
"""Replace all symbols in an entry with their correct values