Patchwork [U-Boot,v4,1/4] mx31pdk: copy SPL directly, not using relocate_code.

login
register
mail settings
Submitter Albert ARIBAUD
Date May 19, 2013, 11:48 a.m.
Message ID <1368964095-1003-2-git-send-email-albert.u.boot@aribaud.net>
Download mbox | patch
Permalink /patch/244808/
State Accepted
Delegated to: Albert ARIBAUD
Headers show

Comments

Albert ARIBAUD - May 19, 2013, 11:48 a.m.
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4: None
Changes in v3: None
Changes in v2:
- dropped relocate_code() call from mx31pdk SPL

 board/freescale/mx31pdk/mx31pdk.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Patch

diff --git a/board/freescale/mx31pdk/mx31pdk.c b/board/freescale/mx31pdk/mx31pdk.c
index 49158bd..4f6cfee 100644
--- a/board/freescale/mx31pdk/mx31pdk.c
+++ b/board/freescale/mx31pdk/mx31pdk.c
@@ -39,7 +39,21 @@  DECLARE_GLOBAL_DATA_PTR;
 #ifdef CONFIG_SPL_BUILD
 void board_init_f(ulong bootflag)
 {
-	relocate_code(CONFIG_SPL_TEXT_BASE);
+	/*
+	 * copy ourselves from where we are running to where we were
+	 * linked at. Use ulong pointers as all addresses involved
+	 * are 4-byte-aligned.
+	 */
+	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
+	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
+	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
+	asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr));
+	asm volatile ("adr %0, board_init_f" : "=r"(run_ptr));
+	for (dst = start_ptr; dst < end_ptr; dst++)
+		*dst = *(dst+(run_ptr-link_ptr));
+	/*
+	 * branch to nand_boot's link-time address.
+	 */
 	asm volatile("ldr pc, =nand_boot");
 }
 #endif