]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
Add support for Linux-like kallsysms
authorMike Frysinger <vapier@gentoo.org>
Wed, 20 May 2009 08:35:14 +0000 (04:35 -0400)
committerWolfgang Denk <wd@denx.de>
Fri, 12 Jun 2009 18:45:48 +0000 (20:45 +0200)
The kernel stores address<->symbol names in it so things can be decoded at
runtime.  Do it in U-Boot, and we get nice symbol decoding when crashing.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Makefile
common/Makefile
common/kallsyms.c [new file with mode: 0644]
common/system_map.c [new file with mode: 0644]
cpu/blackfin/system_map.S [deleted file]
cpu/blackfin/traps.c
include/common.h
include/configs/bfin_adi_common.h

index d14678070e8fca61eb6b5246e951a939b934206c..4445b4b6a3529e2060879ffb49ad02a0363f70b5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -344,12 +344,19 @@ $(obj)u-boot.sha1:        $(obj)u-boot.bin
 $(obj)u-boot.dis:      $(obj)u-boot
                $(OBJDUMP) -d $< > $@
 
-$(obj)u-boot:          depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
+GEN_UBOOT = \
                UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
                sed  -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
                cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
                        --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
                        -Map u-boot.map -o u-boot
+$(obj)u-boot:          depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
+               $(GEN_UBOOT)
+ifeq ($(CONFIG_KALLSYMS),y)
+               smap=`$(call SYSTEM_MAP,u-boot) | awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\0"}'` ; \
+               $(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" -c common/system_map.c -o $(obj)common/system_map.o
+               $(GEN_UBOOT) $(obj)common/system_map.o
+endif
 
 $(OBJS):       depend
                $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
@@ -448,10 +455,12 @@ cscope:
                                                > cscope.files
                cscope -b -q -k
 
-$(obj)System.map:      $(obj)u-boot
-               @$(NM) $< | \
+SYSTEM_MAP = \
+               $(NM) $1 | \
                grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
-               sort > $(obj)System.map
+               LC_ALL=C sort
+$(obj)System.map:      $(obj)u-boot
+               @$(call SYSTEM_MAP,$<) > $(obj)System.map
 
 #
 # Auto-generate the autoconf.mk file (which is included by all makefiles)
index 2ca10264c2b4be601b537f047a0f9cf2bdcf0fe7..ee0cb33aca31371eb00592e1de350d5b7020eb33 100644 (file)
@@ -153,6 +153,7 @@ COBJS-$(CONFIG_CMD_DOC) += docecc.o
 COBJS-$(CONFIG_CONSOLE_MUX) += iomux.o
 COBJS-y += flash.o
 COBJS-$(CONFIG_CMD_KGDB) += kgdb.o
+COBJS-$(CONFIG_KALLSYMS) += kallsyms.o
 COBJS-$(CONFIG_LCD) += lcd.o
 COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
 COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
diff --git a/common/kallsyms.c b/common/kallsyms.c
new file mode 100644 (file)
index 0000000..ce42a93
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Helper functions for working with the builtin symbol table
+ *
+ * Copyright (c) 2008-2009 Analog Devices Inc.
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+
+/* We need the weak marking as this symbol is provided specially */
+extern const char system_map[] __attribute__((weak));
+
+/* Given an address, return a pointer to the symbol name and store
+ * the base address in caddr.  So if the symbol map had an entry:
+ *             03fb9b7c_spi_cs_deactivate
+ * Then the following call:
+ *             unsigned long base;
+ *             const char *sym = symbol_lookup(0x03fb9b80, &base);
+ * Would end up setting the variables like so:
+ *             base = 0x03fb9b7c;
+ *             sym = "_spi_cs_deactivate";
+ */
+const char *symbol_lookup(unsigned long addr, unsigned long *caddr)
+{
+       const char *sym, *csym;
+       char *esym;
+       unsigned long sym_addr;
+
+       sym = system_map;
+       csym = NULL;
+       *caddr = 0;
+
+       while (*sym) {
+               sym_addr = simple_strtoul(sym, &esym, 16);
+               sym = esym;
+               if (sym_addr > addr)
+                       break;
+               *caddr = sym_addr;
+               csym = sym;
+               sym += strlen(sym) + 1;
+       }
+
+       return csym;
+}
diff --git a/common/system_map.c b/common/system_map.c
new file mode 100644 (file)
index 0000000..8307293
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * The builtin symbol table for use with kallsyms
+ *
+ * Copyright (c) 2008-2009 Analog Devices Inc.
+ * Licensed under the GPL-2 or later.
+ */
+
+const char const system_map[] = SYSTEM_MAP;
diff --git a/cpu/blackfin/system_map.S b/cpu/blackfin/system_map.S
deleted file mode 100644 (file)
index 286d7f3..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * system_map.S - optional symbol lookup for debugging
- *
- * Copyright (c) 2007 Analog Devices Inc.
- * Licensed under the GPL-2 or later.
- */
-
-#include <config.h>
-
-#ifdef CONFIG_DEBUG_DUMP_SYMS
-.data
-.global _system_map
-.type _system_map,@object
-_system_map:
-#include SYM_FILE
-.asciz ""
-.size _system_map,.-_system_map
-#endif
index 2121b0e4cbcb0492b330cf14320ee394e164fbfa..7e7c74ce4736bf8707a0f463cf3bb63d0ae60bad 100644 (file)
@@ -171,38 +171,13 @@ void trap_c(struct pt_regs *regs)
 # define ENABLE_DUMP 0
 #endif
 
-#ifdef CONFIG_DEBUG_DUMP_SYMS
-# define ENABLE_DUMP_SYMS 1
-#else
-# define ENABLE_DUMP_SYMS 0
-#endif
-
-static const char *symbol_lookup(unsigned long addr, unsigned long *caddr)
+#ifndef CONFIG_KALLSYMS
+const char *symbol_lookup(unsigned long addr, unsigned long *caddr)
 {
-       if (!ENABLE_DUMP_SYMS)
-               return NULL;
-
-       extern const char system_map[] __attribute__((__weak__));
-       const char *sym, *csym;
-       char *esym;
-       unsigned long sym_addr;
-
-       sym = system_map;
-       csym = NULL;
-       *caddr = 0;
-
-       while (*sym) {
-               sym_addr = simple_strtoul(sym, &esym, 16);
-               sym = esym;
-               if (sym_addr > addr)
-                       break;
-               *caddr = sym_addr;
-               csym = sym;
-               sym += strlen(sym) + 1;
-       }
-
-       return csym;
+       *caddr = addr;
+       return "N/A";
 }
+#endif
 
 static void decode_address(char *buf, unsigned long address)
 {
index 30fff7d65ee29d4bb723c51a583c72ad5b89ec50..df0f5a01e1a2c206a35fb2dc36365c8baf5cfd9f 100644 (file)
@@ -300,6 +300,9 @@ int misc_init_r   (void);
 /* common/exports.c */
 void   jumptable_init(void);
 
+/* common/kallsysm.c */
+const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
+
 /* api/api.c */
 void   api_init (void);
 
index bfe53762c397a08d5a1c674dbfb2132541e1c49f..e0be07b477ede93dd3ef79ed2114a8365fdbb958 100644 (file)
@@ -91,7 +91,7 @@
  */
 #define CONFIG_ENV_OVERWRITE   1
 #define CONFIG_DEBUG_DUMP      1
-#define CONFIG_DEBUG_DUMP_SYMS 1
+#define CONFIG_KALLSYMS                1
 #define CONFIG_PANIC_HANG      1
 
 /*