[U-Boot] [PATCH 2/6] mpc83xx: Make start.S true PIC

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Tue Nov 23 19:48:47 CET 2010


Remove dependencies on link address. Use GOT and
add an new function to calculate the actual address.
---
 arch/powerpc/cpu/mpc83xx/start.S |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index 09c5eac..3cac147 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -69,12 +69,12 @@
  */
 	START_GOT
 	GOT_ENTRY(_GOT2_TABLE_)
+	GOT_ENTRY(_start)
 	GOT_ENTRY(__bss_start)
 	GOT_ENTRY(_end)
 
 #ifndef CONFIG_NAND_SPL
 	GOT_ENTRY(_FIXUP_TABLE_)
-	GOT_ENTRY(_start)
 	GOT_ENTRY(_start_of_vectors)
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
@@ -240,10 +240,12 @@ boot_warm: /* time t 5 */
 	/* there and deflate the flash size back to minimal size      */
 	/*------------------------------------------------------------*/
 	bl map_flash_by_law1
-	lis r4, (CONFIG_SYS_MONITOR_BASE)@h
-	ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
-	addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
-	mtlr r5
+
+	bl	1f
+1:	mflr	r3   /* get current address */
+	addi	r3, r3, in_flash - 1b
+	bl	add_flash_base
+	mtlr r3
 	blr
 in_flash:
 #if 1 /* Remapping flash with LAW0. */
@@ -833,10 +835,12 @@ relocate_code:
 	mr	r10, r5		/* Save copy of Destination Address */
 
 	GET_GOT
-	mr	r3,  r5				/* Destination Address */
-	lis	r4, CONFIG_SYS_MONITOR_BASE at h		/* Source      Address */
-	ori	r4, r4, CONFIG_SYS_MONITOR_BASE at l
+
+	lwz	r4, GOT(_start)	/* Source Address */
+	addi	r4, r4, -EXC_OFF_SYS_RESET
 	lwz	r5, GOT(__bss_start)
+	mr	r3, r10	/* Destination Address */
+
 	sub	r5, r5, r4
 	li	r6, CONFIG_SYS_CACHELINE_SIZE		/* Cache Line Size */
 
@@ -1128,6 +1132,21 @@ unlock_ram_in_cache:
 #endif /* CONFIG_SYS_INIT_RAM_LOCK */
 
 #ifdef CONFIG_SYS_FLASHBOOT
+
+add_flash_base:
+	/* Check if already inside flash address space. */
+	/* if so, do not add CONFIG_SYS_FLASH_BASE */
+	lis	r4, (CONFIG_SYS_FLASH_BASE)@h
+	ori	r4, r4, (CONFIG_SYS_FLASH_BASE)@l
+	cmplw	cr0, r3, r4
+	ble	cr0, 2f /* r3 < r4 ? */
+	lis	r6, (CONFIG_SYS_FLASH_BASE+(CONFIG_SYS_FLASH_SIZE*1024*1024-1))@h
+	ori	r6, r6, (CONFIG_SYS_FLASH_BASE+(CONFIG_SYS_FLASH_SIZE*1024*1024-1))@l
+	cmplw	cr0, r3, r6
+	blelr	cr0	 /* r3 < r6 ? */
+2:	add	r3,r3,r4
+	blr
+
 map_flash_by_law1:
 	/* When booting from ROM (Flash or EPROM), clear the  */
 	/* Address Mask in OR0 so ROM appears everywhere      */
@@ -1179,6 +1198,7 @@ map_flash_by_law1:
 	 */
 remap_flash_by_law0:
 	/* Initialize the BR0 with the boot ROM starting address. */
+	lis r3, (CONFIG_SYS_IMMR)@h  /* r3 <= CONFIG_SYS_IMMR    */
 	lwz r4, BR0(r3)
 	li  r5, 0x7FFF
 	and r4, r4, r5
-- 
1.7.2.2



More information about the U-Boot mailing list