Patchwork [U-Boot,RFC,31/36] x86 - Fix incorrect usage of relocation offset

login
register
mail settings
Submitter Graeme Russ
Date Jan. 3, 2011, 7:46 p.m.
Message ID <1294084016-2674-32-git-send-email-graeme.russ@gmail.com>
Download mbox | patch
Permalink /patch/77338/
State Superseded
Delegated to: Graeme Russ
Headers show

Comments

Graeme Russ - Jan. 3, 2011, 7:46 p.m.
--
x86 has always used relocation offset in the opposite sense
to the ELF standard - Fix this
---
 arch/i386/cpu/start.S |    2 +-
 arch/i386/lib/board.c |   10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

--
1.7.1.422.g049e9

Patch

diff --git a/arch/i386/cpu/start.S b/arch/i386/cpu/start.S
index fd018bf..0031389 100644
--- a/arch/i386/cpu/start.S
+++ b/arch/i386/cpu/start.S
@@ -120,7 +120,7 @@  relocate_code:

 	/* Setup call address of in-RAM copy of board_init_r() */
 	movl	$board_init_r, %ebp
-	subl	(GD_RELOC_OFF * 4)(%edx), %ebp
+	addl	(GD_RELOC_OFF * 4)(%edx), %ebp

 	/* Setup parameters to board_init_r() */
 	movl	%edx, %eax
diff --git a/arch/i386/lib/board.c b/arch/i386/lib/board.c
index 2b06900..c77c206 100644
--- a/arch/i386/lib/board.c
+++ b/arch/i386/lib/board.c
@@ -216,7 +216,7 @@  void board_init_f (ulong boot_flags)
 	addr_sp = dest_addr;
 	dest_addr -= CONFIG_SYS_STACK_SIZE;
 	dest_addr -= (bss_end - text_start);
-	rel_offset = text_start - dest_addr;
+	rel_offset = dest_addr - text_start;

 	/* First stage CPU initialization */
 	if (cpu_init_f() != 0)
@@ -235,8 +235,8 @@  void board_init_f (ulong boot_flags)
 		*dst_addr++ = *src_addr++;

 	/* Clear BSS */
-	dst_addr = (ulong *)(bss_start - rel_offset);
-	end_addr = (ulong *)(bss_end - rel_offset);
+	dst_addr = (ulong *)(bss_start + rel_offset);
+	end_addr = (ulong *)(bss_end + rel_offset);

 	while (dst_addr < end_addr)
 		*dst_addr++ = 0x00000000;
@@ -247,8 +247,8 @@  void board_init_f (ulong boot_flags)

 	do {
 		if (re_src->r_offset >= CONFIG_SYS_TEXT_BASE)
-			if (*(Elf32_Addr *)(re_src->r_offset - rel_offset) >= CONFIG_SYS_TEXT_BASE)
-				*(Elf32_Addr *)(re_src->r_offset - rel_offset) -= rel_offset;
+			if (*(Elf32_Addr *)(re_src->r_offset + rel_offset) >= CONFIG_SYS_TEXT_BASE)
+				*(Elf32_Addr *)(re_src->r_offset + rel_offset) += rel_offset;
 	} while (re_src++ < re_end);

 	gd->reloc_off = rel_offset;