Patchwork [U-Boot,2/4] ARM: don't relocate if we are already too high

login
register
mail settings
Submitter Alessandro Rubini
Date April 18, 2011, 9:20 a.m.
Message ID <c7fbaf26d50674c4b9cbc4cac86e2d8fdf54d618.1303118067.git.rubini@gnudd.com>
Download mbox | patch
Permalink /patch/91704/
State Rejected
Delegated to: Albert ARIBAUD
Headers show

Comments

Alessandro Rubini - April 18, 2011, 9:20 a.m.
Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
---
 arch/arm/lib/board.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

Patch

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index dc46e21..dab70b5 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -423,8 +423,29 @@  void board_init_f (ulong bootflag)
 	gd->relocaddr = addr;
 	gd->start_addr_sp = addr_sp;
 	gd->reloc_off = addr - _TEXT_BASE;
+
+	/*
+	 * Destination is higher than current address, but may overlap
+	 * our address range. If so, pass the source address as destination
+	 * address so the asm will not relocate and only clear bss
+	 */
+	if ((addr_sp - 256) <  _bss_start_ofs+_TEXT_BASE) {
+		debug("Won't fit above us: disabling relocation\n");
+		if (gd->reloc_off < 0) {
+			printf("Can't relocate to lower ram, currently\n");
+			hang();
+		}
+		addr -= gd->reloc_off;
+		addr_sp -= gd->reloc_off;
+		gd->start_addr_sp = addr_sp;
+		id -= gd->reloc_off;
+		gd->reloc_off = 0;
+	}
+
+
 	debug ("relocation Offset is: %08lx\n", gd->reloc_off);
-	memcpy (id, (void *)gd, sizeof (gd_t));
+	if (id != (void *)gd)
+		memcpy (id, (void *)gd, sizeof (gd_t));
 
 	relocate_code (addr_sp, id, addr);