Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Helper functions for working with the builtin symbol table |
| 3 | * |
| 4 | * Copyright (c) 2008-2009 Analog Devices Inc. |
| 5 | * Licensed under the GPL-2 or later. |
| 6 | */ |
| 7 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 8 | #include <common.h> |
Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 9 | |
| 10 | /* We need the weak marking as this symbol is provided specially */ |
| 11 | extern const char system_map[] __attribute__((weak)); |
| 12 | |
| 13 | /* Given an address, return a pointer to the symbol name and store |
| 14 | * the base address in caddr. So if the symbol map had an entry: |
| 15 | * 03fb9b7c_spi_cs_deactivate |
| 16 | * Then the following call: |
| 17 | * unsigned long base; |
| 18 | * const char *sym = symbol_lookup(0x03fb9b80, &base); |
| 19 | * Would end up setting the variables like so: |
| 20 | * base = 0x03fb9b7c; |
| 21 | * sym = "_spi_cs_deactivate"; |
| 22 | */ |
| 23 | const char *symbol_lookup(unsigned long addr, unsigned long *caddr) |
| 24 | { |
| 25 | const char *sym, *csym; |
| 26 | char *esym; |
| 27 | unsigned long sym_addr; |
| 28 | |
| 29 | sym = system_map; |
| 30 | csym = NULL; |
| 31 | *caddr = 0; |
| 32 | |
| 33 | while (*sym) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 34 | sym_addr = hextoul(sym, &esym); |
Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 35 | sym = esym; |
| 36 | if (sym_addr > addr) |
| 37 | break; |
| 38 | *caddr = sym_addr; |
| 39 | csym = sym; |
| 40 | sym += strlen(sym) + 1; |
| 41 | } |
| 42 | |
| 43 | return csym; |
| 44 | } |