[U-Boot] [RFC PATCH 10/19] Add CONFIG_SYS_SYM_OFFSETS to support offset symbols

Simon Glass sjg at chromium.org
Wed Dec 28 07:35:51 CET 2011


Link symbols as created by the link script can either be absolute or
relative to the text start. This option switches between the two options
so that we can support both.

As we convert architectures over to generic board, we can see if this
option is actually needed, or whether it is possible to unify this feature
also.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 common/board_f.c               |    9 +++++++++
 common/reloc.c                 |   17 ++++++++++++++++-
 include/asm-generic/sections.h |   11 +++++++++++
 3 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/common/board_f.c b/common/board_f.c
index 06317ed..17fcf08 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -107,8 +107,13 @@ static int display_banner(void)
 {
 	ulong bss_start, bss_end;
 
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	bss_start = _bss_start_ofs + _TEXT_BASE;
 	bss_end = _bss_end_ofs + _TEXT_BASE;
+#else
+	bss_start = (ulong)&__bss_start;
+	bss_end = (ulong)&__bss_end;
+#endif
 	printf("\n\n%s\n\n", version_string);
 	debug("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
 	      _TEXT_BASE, bss_start, bss_end);
@@ -165,7 +170,11 @@ static int setup_global_data(void)
 	dmb();
 	memset((void *)gd, '\0', sizeof(gd_t));
 
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	gd->mon_len = _bss_end_ofs;
+#else
+	gd->mon_len = (ulong)&__bss_end - (ulong)&__text_start;
+#endif
 	return 0;
 }
 
diff --git a/common/reloc.c b/common/reloc.c
index ec0d72f..564cc67 100644
--- a/common/reloc.c
+++ b/common/reloc.c
@@ -43,11 +43,15 @@ int reloc_make_copy(void)
 	/* TODO: __text_start would be better when we have it */
 	char *src_addr = (char *)_start;
 	/* TODO: switch over to __image_copy_end when we can */
+#ifdef CONFIG_SYS_SYM_OFFSETS
 #ifdef CONFIG_SPL_BUILD
 	char *end_addr = src_addr + _image_copy_end_ofs;
 #else
 	char *end_addr = src_addr + _rel_dyn_start_ofs;
 #endif
+#else
+	char *end_addr = (char *)&__data_end;
+#endif
 
 	if (dst_addr != src_addr) {
 		size_t size = end_addr - src_addr;
@@ -64,14 +68,20 @@ int reloc_elf(void)
 #ifndef CONFIG_SPL_BUILD
 	const Elf32_Rel *ptr, *end;
 	Elf32_Addr *addr;
-	char *src_addr = (char *)_start;
 	Elf32_Sym *dynsym;
 	ulong reloc_ofs = gd->reloc_off;
 
 	/* scan the relocation table for relevant entries */
+#ifdef CONFIG_SYS_SYM_OFFSETS
+	char *src_addr = (char *)_start;
+
 	ptr = (Elf32_Rel *)(src_addr + _rel_dyn_start_ofs);
 	end = (Elf32_Rel *)(src_addr + _rel_dyn_end_ofs);
 	dynsym = (Elf32_Sym *)(src_addr + _dynsym_start_ofs);
+#else
+	ptr = (Elf32_Rel *)(&__rel_dyn_start);
+	end = (Elf32_Rel *)(&__rel_dyn_end);
+#endif
 	debug("%s: process reloc entries %p-%p, dynsym at %p\n", __func__,
 	      ptr, end, dynsym);
 	for (; ptr < end; ptr++) {
@@ -86,8 +96,13 @@ int reloc_elf(void)
 
 int reloc_clear_bss(void)
 {
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	char *dst_addr = (char *)_start + _bss_start_ofs;
 	size_t size = _bss_end_ofs - _bss_start_ofs;
+#else
+	ulong *dst_addr = (ulong *)((ulong)&__bss_start + gd->reloc_off);
+	size_t size = (size_t)&__bss_end - (size_t)&__bss_start;
+#endif
 
 #ifndef CONFIG_SPL_BUILD
 	/* No relocation for SPL (TBD: better to set reloc_off to zero) */
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 2935dc1..0dac424 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -79,6 +79,17 @@ extern char __image_copy_end[];
  */
 extern void _start(void);
 
+/*
+ * ARM needs to use offsets for symbols, since the values of some symbols
+ * are not resolved prior to relocation (and are just 0). Maybe this can be
+ * resolved, or maybe other architectures are similar, iwc this should be
+ * promoted to an architecture option.
+ */
+#ifdef CONFIG_ARM
+#define CONFIG_SYS_SYM_OFFSETS
+#endif
+
+#ifdef CONFIG_SYS_SYM_OFFSETS
 /* Start/end of the relocation entries, as an offset from _start */
 extern ulong _rel_dyn_start_ofs;
 extern ulong _rel_dyn_end_ofs;
-- 
1.7.3.1



More information about the U-Boot mailing list