diff options
author | Simon Glass <sjg@chromium.org> | 2023-01-11 16:10:19 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2023-01-18 14:55:41 -0700 |
commit | 571bc4e67d39e4c376f8bab0d6518ab5ee832d9e (patch) | |
tree | 0d52288bc4298572fa2db76458a6d55eb95e788d /tools/binman/elf.py | |
parent | 8f5afe21aed8b8ed4d75678a4e8972e7d8a23a6b (diff) |
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>
Diffstat (limited to 'tools/binman/elf.py')
-rw-r--r-- | tools/binman/elf.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/binman/elf.py b/tools/binman/elf.py index 9ac00ed9cc..3cc8a38449 100644 --- a/tools/binman/elf.py +++ b/tools/binman/elf.py @@ -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 |