kallsyms.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include <common.h>
  8. /* We need the weak marking as this symbol is provided specially */
  9. extern const char system_map[] __attribute__((weak));
  10. /* Given an address, return a pointer to the symbol name and store
  11. * the base address in caddr. So if the symbol map had an entry:
  12. * 03fb9b7c_spi_cs_deactivate
  13. * Then the following call:
  14. * unsigned long base;
  15. * const char *sym = symbol_lookup(0x03fb9b80, &base);
  16. * Would end up setting the variables like so:
  17. * base = 0x03fb9b7c;
  18. * sym = "_spi_cs_deactivate";
  19. */
  20. const char *symbol_lookup(unsigned long addr, unsigned long *caddr)
  21. {
  22. const char *sym, *csym;
  23. char *esym;
  24. unsigned long sym_addr;
  25. sym = system_map;
  26. csym = NULL;
  27. *caddr = 0;
  28. while (*sym) {
  29. sym_addr = simple_strtoul(sym, &esym, 16);
  30. sym = esym;
  31. if (sym_addr > addr)
  32. break;
  33. *caddr = sym_addr;
  34. csym = sym;
  35. sym += strlen(sym) + 1;
  36. }
  37. return csym;
  38. }