[PATCH 5/9] ARM startup: calculate offset instead of runtime address

Sascha Hauer s.hauer at pengutronix.de
Thu Jul 19 04:12:58 EDT 2012


Calculating the offset between runtime and linked address makes the
intention of the binary copy function a bit more clear.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/cpu/start.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 523179d..cabe4d2 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -104,7 +104,7 @@ void __naked __bare_init reset(void)
  */
 void __naked __section(.text_ll_return) board_init_lowlevel_return(void)
 {
-	uint32_t r, addr;
+	uint32_t r, addr, offset;
 
 	/*
 	 * Get runtime address of this function. Do not
@@ -116,13 +116,13 @@ void __naked __section(.text_ll_return) board_init_lowlevel_return(void)
 	r = STACK_BASE + STACK_SIZE - 16;
 	__asm__ __volatile__("mov sp, %0" : : "r"(r));
 
-	/* Get start of binary image */
-	addr -= (uint32_t)&__ll_return - TEXT_BASE;
+	/* Get offset between linked address and runtime address */
+	offset = (uint32_t)__ll_return - addr;
 
 	/* relocate to link address if necessary */
-	if (addr != TEXT_BASE)
-		memcpy((void *)TEXT_BASE, (void *)addr,
-				(unsigned int)&__bss_start - TEXT_BASE);
+	if (offset)
+		memcpy((void *)_text, (void *)(_text - offset),
+				__bss_start - _text);
 
 	/* clear bss */
 	memset(__bss_start, 0, __bss_stop - __bss_start);
-- 
1.7.10.4




More information about the barebox mailing list