public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v1 0/1] Factorize ARM startup code as mush as possible.
@ 2012-11-04  3:57 Albert ARIBAUD
  2012-11-04  3:57 ` [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S Albert ARIBAUD
  2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  0 siblings, 2 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04  3:57 UTC (permalink / raw)
  To: u-boot


File crt0.S is introduced which contains the C runtime
framework, that is, the assembly code responsible for
setting up the C environments needed by board_init_*()
and relocate_code(). Corresponding code is removed from
all start.S files in arch/arm.

This precedes further factorization, e.g. relocate_code()
and possibly also the exception handlers.

This has the nice side effect of turning board_init_*()
and relocate_code() into normal C functions, too.


Albert ARIBAUD (1):
  arm: move generic startup code in crt0.S

 arch/arm/cpu/arm1136/start.S              |   62 ++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  179 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 20 files changed, 322 insertions(+), 673 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S
  2012-11-04  3:57 [U-Boot] [PATCH v1 0/1] Factorize ARM startup code as mush as possible Albert ARIBAUD
@ 2012-11-04  3:57 ` Albert ARIBAUD
  2012-11-04  7:29   ` Wolfgang Denk
  2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  1 sibling, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04  3:57 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/cpu/arm1136/start.S              |   62 ++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  179 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 20 files changed, 322 insertions(+), 673 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 3752af9..fb1fcab 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -161,13 +161,7 @@ next:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -184,14 +178,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -243,48 +233,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -293,6 +244,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 667a0e0..40df4b1 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -224,12 +224,7 @@ skip_tcmdisable:
 	 */
 	bl	lowlevel_init		/* go setup pll,mux,memory */
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -246,14 +241,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -343,49 +334,9 @@ mmu_enable:
 skip_hw_init:
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#ifndef CONFIG_NAND_SPL
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
-
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add     lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -399,6 +350,11 @@ _mmu_table_base:
 	.word mmu_table
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 #ifndef CONFIG_NAND_SPL
 /*
  * we assume that cache operation is done before. (eg. cleanup_before_linux())
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index c2a7763..771d386 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,43 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -272,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 14c9156..511d21d 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -182,12 +182,7 @@ copyex:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -204,14 +199,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -263,51 +254,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -315,6 +265,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 3a483f6..82f5b8b 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -176,12 +176,7 @@ poll1:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -198,14 +193,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -257,51 +248,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -309,6 +259,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 2188f7e..5dfd49a 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,20 +198,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#else
-#ifdef CONFIG_SPL_BUILD
-	ldr	sp, =(CONFIG_SPL_STACK)
-#else
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#endif
-#endif
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -229,15 +216,11 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	sub	r9, r6, r0		/* r9 <- relocation offset */
 	cmp	r0, r6
-	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	moveq	r9, #0			/* no relocation. offset(r9) = 0 */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -289,56 +272,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
+relocate_done:
 
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-#ifndef CONFIG_SPL_BUILD
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	ldr	r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -346,8 +282,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 30e2183..a7a98a4 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,46 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
+relocate_done:
 
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -275,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index a133d19..c189849 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -143,12 +143,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -165,14 +160,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -224,50 +215,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -276,6 +226,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 7df97c5..dcc1f83 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -155,12 +155,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -177,14 +172,10 @@ ENTRY(relocate_code)
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -233,34 +224,22 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+
+relocate_done:
+
+	bx	lr
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+ENDPROC(relocate_code)
 
-clear_bss:
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+#endif
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-jump_2_ram:
+ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
  */
@@ -279,20 +258,9 @@ jump_2_ram:
 	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
 #endif /* !Tegra20 */
 
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-ENDPROC(relocate_code)
-#endif
+	bx	lr
+
+ENDPROC(c_runtime_cpu_setup)
 
 /*************************************************************************
  *
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index c12f1a7..efb5a40 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -245,12 +245,7 @@ reset:
 	orr	r0,r0,#0x13
 	msr	cpsr,r0
 
-/* Set initial stackpointer in SDRAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -267,14 +262,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -326,42 +317,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -370,6 +328,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /****************************************************************************/
 /*									    */
 /* Interrupt handling							    */
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 536cf5c..72af869 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -164,12 +164,7 @@ reset:
 	bl	lock_cache_for_stack
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0, =0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 #ifndef CONFIG_SPL_BUILD
@@ -186,10 +181,6 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 /* Disable the Dcache RAM lock for stack now */
 #ifdef	CONFIG_CPU_PXA25X
 	bl	cpu_init_crit
@@ -198,7 +189,7 @@ stack_setup:
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -250,48 +241,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_ONENAND_SPL
-	ldr     r0, _onenand_boot_ofs
-	mov	pc, r0
-
-_onenand_boot_ofs:
-	.word onenand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -299,7 +251,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
+
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 323b923..4528c91 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -128,12 +128,7 @@ reset:
 	bl	lowlevel_init
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -150,14 +145,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -209,42 +200,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,6 +211,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 1ea92d1..3144299 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -132,12 +132,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -154,14 +149,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -213,40 +204,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -254,6 +215,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..07baee2 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,6 +36,8 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+SOBJS-y += crt0.o
+
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 92cad9a..ad96d7e 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -272,11 +272,6 @@ void board_init_f(ulong bootflag)
 
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
-	/* compiler optimization barrier needed for GCC >= 3.4 */
-	__asm__ __volatile__("": : :"memory");
-
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
@@ -458,10 +453,6 @@ void board_init_f(ulong bootflag)
 		gd->fdt_blob = new_fdt;
 	}
 	memcpy(id, (void *)gd, sizeof(gd_t));
-
-	relocate_code(addr_sp, id, addr);
-
-	/* NOTREACHED - relocate_code() does not return */
 }
 
 #if !defined(CONFIG_SYS_NO_FLASH)
@@ -486,8 +477,6 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	ulong flash_size;
 #endif
 
-	gd = id;
-
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
new file mode 100644
index 0000000..0874e92
--- /dev/null
+++ b/arch/arm/lib/crt0.S
@@ -0,0 +1,179 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM U-Boot
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+
+/*
+ * This file handles the target-independent stages of the U-Boot
+ * start-up where a C runtime environment is needed. Its entry point
+ * is _main and is branched into from the target's start.S file.
+ *
+ * _main execution sequence is:
+ *
+ * 1. Set up initial environment for calling board_init_f().
+ *    This environment only provides a stack and a place to store
+ *    the GD ('global data') structure. In this context, VARIABLE
+ *    global data, initialized or not (BSS), are UNAVAILABLE; only
+ *    CONSTANT initialized data are available.
+ *
+ * 2. Call board_init_f(). This function prepares the hardware for
+ *    execution from DDR. As DDR may not be available, board_init_f()
+ *    must use GD to store any data which must be passed on to later,
+ *    stages, including the reloction destination and the new stack
+ *    pointer address, below which the stack resides and above it the
+ *    new GD resides.
+ *
+ * 3. Set up intermediate environment where the stack and GD are the
+ *    ones allocated by board_init_f() in DDR, but BSS and initialized
+ *    non-const data are still not available.
+ *
+ * 4. Call relocate_code(). This function relocates U-Boot from its
+ *    current location into the relocation destination computed by
+ *    board_init_f().
+ *
+ * 5. Set up final environment for calling board_init_r(). This
+ *    environment has BSS (initialized to 0), initialized non-const
+ *    data (initialized to their intended value), and stack in DDR.
+ *    GD has but retained values set by board_init_f(). Some CPUs
+ *    have some work to do at this point, so call c_runtime_cpu_setup.
+ *
+ * 6. Call noard_init_r(). If the function returns, reset the board.
+ */
+
+/*
+ * offset of the nand_boot() function for SPL crt
+ */
+
+#if defined(CONFIG_NAND_SPL)
+
+.globl nand_boot
+_nand_boot:
+	.word nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+/*
+ * offset of the board_init_r() function for non-SPL crt
+ */
+
+.globl board_init_r
+_board_init_r:
+	.word board_init_r
+
+#endif
+
+/*
+ * start and end of BSS
+ */
+
+.globl __bss_start
+.globl __bss_end__
+
+/*
+ * entry point of crt0 sequence
+ */
+
+.global _main
+
+_main:
+
+/*
+ * Set up initial C runtime environment and call board_init_f(0).
+ */
+
+#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#elif CONFIG_SPL_BUILD
+	ldr	sp, =(CONFIG_SPL_STACK)
+#else
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#endif
+	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
+	mov	r8, sp		/* GD is above SP */
+	mov	r0, #0
+	bl	board_init_f
+
+/*
+ * Set up intermediate environment (new sp and gd) and call
+ * relocate_code(addr_sp, gd, addr_moni). Trick here is that
+ * we'll return 'here' but relocated.
+ */
+
+	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
+	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
+	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
+
+#ifndef CONFIG_SPL_BUILD
+
+	adr	lr, here
+	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
+	add	lr, lr, r0
+	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
+	mov	r1, r8				/* r1 = gd */
+	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
+	b	relocate_code
+here:
+
+#endif
+
+/* Set up final (full) environment */
+
+	bl	c_runtime_cpu_setup	/* we still call old routine here */
+
+	ldr	r0, =__bss_start	/* this is auto-relocated! */
+	ldr	r1, =__bss_end__	/* this is aotu-relocated! */
+
+	mov	r2, #0x00000000		/* prepare zero to clear BSS */
+
+clbss_l:cmp	r0, r1			/* while not at end of BSS */
+	strlo	r2, [r0]		/* clear 32-bit BSS word */
+	addlo	r0, r0, #4		/* move to next
+	bhs	clbss_l
+
+#ifdef CONFIG_SPL_BUILD
+
+	bl coloured_LED_init
+	bl red_led_on
+
+#endif
+
+	/* call board_init_r(gd_t *id, ulong dest_addr) */
+
+	mov	lr, pc
+
+#if defined(CONFIG_NAND_SPL)
+	ldr     pc, _nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+	/* setup parameters for board_init_r */
+	mov	r0, r8			/* gd_t */
+	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
+	/* call board_init_r */
+	ldr	pc, _board_init_r	/* this is auto-relocated! */
+
+#endif
+
+	/* we should not return. */
diff --git a/include/common.h b/include/common.h
index b23e90b..230bc9f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -300,7 +300,7 @@ int	abortboot(int bootdelay);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
-void	board_init_f  (ulong) __attribute__ ((noreturn));
+void	board_init_f(ulong);
 void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
 int	checkboard    (void);
 int	checkflash    (void);
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c88f5d4..764e27b 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,5 +28,15 @@ int main(void)
 	DEFINE(GENERATED_BD_INFO_SIZE,
 		(sizeof(struct bd_info) + 15) & ~15);
 
+	DEFINE(GD_SIZE, sizeof(struct global_data));
+
+	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+	DEFINE(GD_RELOCADDR, offsetof(struct global_data, relocaddr));
+
+	DEFINE(GD_RELOC_OFF, offsetof(struct global_data, reloc_off));
+
+	DEFINE(GD_START_ADDR_SP, offsetof(struct global_data, start_addr_sp));
+
 	return 0;
 }
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index 43e72c4..2793aef 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -12,11 +12,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm1136/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/freescale/mx31pdk/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -49,6 +50,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm1136/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index becf7fa..825f06d 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -33,11 +33,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm926ejs/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/karo/tx25/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -70,6 +71,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm926ejs/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S
  2012-11-04  3:57 ` [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S Albert ARIBAUD
@ 2012-11-04  7:29   ` Wolfgang Denk
  2012-11-04  8:36     ` Albert ARIBAUD
  0 siblings, 1 reply; 47+ messages in thread
From: Wolfgang Denk @ 2012-11-04  7:29 UTC (permalink / raw)
  To: u-boot

Dear Albert ARIBAUD,

In message <1352001421-25913-2-git-send-email-albert.u.boot@aribaud.net> you wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---

Please move the patch description from the cover letter to this commit
message.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I wrote my name at the top of the page. I wrote down  the  number  of
the  question  ``1''.  After much reflection I put a bracket round it
thus ``(1)''. But thereafter I could not think of anything  connected
with it that was either relevant or true.
                        - Sir Winston Churchill _My Early Life_ ch. 2

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S
  2012-11-04  7:29   ` Wolfgang Denk
@ 2012-11-04  8:36     ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04  8:36 UTC (permalink / raw)
  To: u-boot

Hi Wolfgang,

On Sun, 04 Nov 2012 08:29:53 +0100, Wolfgang Denk <wd@denx.de> wrote:

> Dear Albert ARIBAUD,
> 
> In message <1352001421-25913-2-git-send-email-albert.u.boot@aribaud.net> you wrote:
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > ---
> 
> Please move the patch description from the cover letter to this commit
> message.

Will do. Also, V2 will have a second patch for some start.S scrubbing
and will have fixes for a few targets.

> Best regards,
> 
> Wolfgang Denk

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-04  3:57 [U-Boot] [PATCH v1 0/1] Factorize ARM startup code as mush as possible Albert ARIBAUD
  2012-11-04  3:57 ` [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S Albert ARIBAUD
@ 2012-11-04 11:32 ` Albert ARIBAUD
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                     ` (2 more replies)
  1 sibling, 3 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 11:32 UTC (permalink / raw)
  To: u-boot

The goal of this series is to scrub the start.S files
which have proliferated across arch/arm and eliminate
code redundancy.

Currently this series only factorizes the C runtime
framework, that is, the assembly code responsible for
setting up the C environments needed by board_init_*()
and relocate_code().

Further factorization is possible: relocate_code() can
be moved out and possibly rewritten in C now that it
has plain C function semantics; exception handlers
should also be pretty much cpu-independent.

Eventually, start.S files should disappear or contain
CPU-specific code only.

The new C runtime setup sequence has been validated step by
step on target versatileqemu using toolchain ELDK4.2.

The whole changes have been build-tested across all ARM
targets using MAKEALL -a arm.

Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
- introduced in V2

Albert ARIBAUD (2):
  arm: move C runtime setup code in crt0.S
  arm: remove useless code in start.S files

 arch/arm/cpu/arm1136/start.S              |   62 ++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   65 ++---------
 arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 324 insertions(+), 684 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
@ 2012-11-04 11:32   ` Albert ARIBAUD
  2012-11-04 11:32     ` [U-Boot] [PATCH v2 2/2] arm: remove useless code in start.S files Albert ARIBAUD
                       ` (4 more replies)
  2012-11-04 11:43   ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2 siblings, 5 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 11:32 UTC (permalink / raw)
  To: u-boot

Move all the C runtime setup code from every start.S
in arch/arm into arch/arm/lib/crt0.S. This covers
the code sequence from isetting up the initial stack
to calling into board_init_r().

Also, rewrite the C runtime setup and make functions
board_init_*() and relocate_code() behave according to
normal C semantics (no jumping across the C stack any
more, etc).

Some SPL targets had to be touched because they use
start.S exolicitly or for some reason; the relevant
maintainers and custodians are cc:ed.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

 arch/arm/cpu/arm1136/start.S              |   62 ++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 324 insertions(+), 674 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 3752af9..fb1fcab 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -161,13 +161,7 @@ next:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -184,14 +178,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -243,48 +233,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -293,6 +244,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 667a0e0..40df4b1 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -224,12 +224,7 @@ skip_tcmdisable:
 	 */
 	bl	lowlevel_init		/* go setup pll,mux,memory */
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -246,14 +241,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -343,49 +334,9 @@ mmu_enable:
 skip_hw_init:
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#ifndef CONFIG_NAND_SPL
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
-
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add     lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -399,6 +350,11 @@ _mmu_table_base:
 	.word mmu_table
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 #ifndef CONFIG_NAND_SPL
 /*
  * we assume that cache operation is done before. (eg. cleanup_before_linux())
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index c2a7763..771d386 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,43 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -272,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 14c9156..511d21d 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -182,12 +182,7 @@ copyex:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -204,14 +199,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -263,51 +254,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -315,6 +265,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 3a483f6..82f5b8b 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -176,12 +176,7 @@ poll1:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -198,14 +193,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -257,51 +248,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -309,6 +259,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 2188f7e..5dfd49a 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,20 +198,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#else
-#ifdef CONFIG_SPL_BUILD
-	ldr	sp, =(CONFIG_SPL_STACK)
-#else
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#endif
-#endif
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -229,15 +216,11 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	sub	r9, r6, r0		/* r9 <- relocation offset */
 	cmp	r0, r6
-	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	moveq	r9, #0			/* no relocation. offset(r9) = 0 */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -289,56 +272,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
+relocate_done:
 
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-#ifndef CONFIG_SPL_BUILD
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	ldr	r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -346,8 +282,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 30e2183..a7a98a4 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,46 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
+relocate_done:
 
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -275,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index a133d19..c189849 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -143,12 +143,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -165,14 +160,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -224,50 +215,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -276,6 +226,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 7df97c5..dcc1f83 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -155,12 +155,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -177,14 +172,10 @@ ENTRY(relocate_code)
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -233,34 +224,22 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+
+relocate_done:
+
+	bx	lr
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+ENDPROC(relocate_code)
 
-clear_bss:
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+#endif
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-jump_2_ram:
+ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
  */
@@ -279,20 +258,9 @@ jump_2_ram:
 	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
 #endif /* !Tegra20 */
 
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-ENDPROC(relocate_code)
-#endif
+	bx	lr
+
+ENDPROC(c_runtime_cpu_setup)
 
 /*************************************************************************
  *
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index c12f1a7..efb5a40 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -245,12 +245,7 @@ reset:
 	orr	r0,r0,#0x13
 	msr	cpsr,r0
 
-/* Set initial stackpointer in SDRAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -267,14 +262,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -326,42 +317,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -370,6 +328,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /****************************************************************************/
 /*									    */
 /* Interrupt handling							    */
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 536cf5c..72af869 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -164,12 +164,7 @@ reset:
 	bl	lock_cache_for_stack
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0, =0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 #ifndef CONFIG_SPL_BUILD
@@ -186,10 +181,6 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 /* Disable the Dcache RAM lock for stack now */
 #ifdef	CONFIG_CPU_PXA25X
 	bl	cpu_init_crit
@@ -198,7 +189,7 @@ stack_setup:
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -250,48 +241,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_ONENAND_SPL
-	ldr     r0, _onenand_boot_ofs
-	mov	pc, r0
-
-_onenand_boot_ofs:
-	.word onenand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -299,7 +251,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
+
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 323b923..4528c91 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -128,12 +128,7 @@ reset:
 	bl	lowlevel_init
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -150,14 +145,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -209,42 +200,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,6 +211,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 1ea92d1..3144299 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -132,12 +132,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -154,14 +149,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -213,40 +204,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -254,6 +215,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..07baee2 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,6 +36,8 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+SOBJS-y += crt0.o
+
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 92cad9a..ad96d7e 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -272,11 +272,6 @@ void board_init_f(ulong bootflag)
 
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
-	/* compiler optimization barrier needed for GCC >= 3.4 */
-	__asm__ __volatile__("": : :"memory");
-
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
@@ -458,10 +453,6 @@ void board_init_f(ulong bootflag)
 		gd->fdt_blob = new_fdt;
 	}
 	memcpy(id, (void *)gd, sizeof(gd_t));
-
-	relocate_code(addr_sp, id, addr);
-
-	/* NOTREACHED - relocate_code() does not return */
 }
 
 #if !defined(CONFIG_SYS_NO_FLASH)
@@ -486,8 +477,6 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	ulong flash_size;
 #endif
 
-	gd = id;
-
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
new file mode 100644
index 0000000..fd6bd92
--- /dev/null
+++ b/arch/arm/lib/crt0.S
@@ -0,0 +1,180 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM U-Boot
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+
+/*
+ * This file handles the target-independent stages of the U-Boot
+ * start-up where a C runtime environment is needed. Its entry point
+ * is _main and is branched into from the target's start.S file.
+ *
+ * _main execution sequence is:
+ *
+ * 1. Set up initial environment for calling board_init_f().
+ *    This environment only provides a stack and a place to store
+ *    the GD ('global data') structure. In this context, VARIABLE
+ *    global data, initialized or not (BSS), are UNAVAILABLE; only
+ *    CONSTANT initialized data are available.
+ *
+ * 2. Call board_init_f(). This function prepares the hardware for
+ *    execution from DDR. As DDR may not be available, board_init_f()
+ *    must use GD to store any data which must be passed on to later,
+ *    stages, including the reloction destination and the new stack
+ *    pointer address, below which the stack resides and above it the
+ *    new GD resides.
+ *
+ * 3. Set up intermediate environment where the stack and GD are the
+ *    ones allocated by board_init_f() in DDR, but BSS and initialized
+ *    non-const data are still not available.
+ *
+ * 4. Call relocate_code(). This function relocates U-Boot from its
+ *    current location into the relocation destination computed by
+ *    board_init_f().
+ *
+ * 5. Set up final environment for calling board_init_r(). This
+ *    environment has BSS (initialized to 0), initialized non-const
+ *    data (initialized to their intended value), and stack in DDR.
+ *    GD has but retained values set by board_init_f(). Some CPUs
+ *    have some work to do at this point, so call c_runtime_cpu_setup.
+ *
+ * 6. Call noard_init_r(). If the function returns, reset the board.
+ */
+
+/*
+ * offset of the nand_boot() function for SPL crt
+ */
+
+#if defined(CONFIG_NAND_SPL)
+
+.globl nand_boot
+_nand_boot:
+	.word nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+/*
+ * offset of the board_init_r() function for non-SPL crt
+ */
+
+.globl board_init_r
+_board_init_r:
+	.word board_init_r
+
+#endif
+
+/*
+ * start and end of BSS
+ */
+
+.globl __bss_start
+.globl __bss_end__
+
+/*
+ * entry point of crt0 sequence
+ */
+
+.global _main
+
+_main:
+
+/*
+ * Set up initial C runtime environment and call board_init_f(0).
+ */
+
+#if defined(CONFIG_NAND_SPL)
+	/* deprecated, use instead CONFIG_SPL_BUILD */
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
+	ldr	sp, =(CONFIG_SPL_STACK)
+#else
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#endif
+	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
+	mov	r8, sp		/* GD is above SP */
+	mov	r0, #0
+	bl	board_init_f
+
+/*
+ * Set up intermediate environment (new sp and gd) and call
+ * relocate_code(addr_sp, gd, addr_moni). Trick here is that
+ * we'll return 'here' but relocated.
+ */
+
+	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
+	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
+	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
+
+#ifndef CONFIG_SPL_BUILD
+
+	adr	lr, here
+	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
+	add	lr, lr, r0
+	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
+	mov	r1, r8				/* r1 = gd */
+	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
+	b	relocate_code
+here:
+
+#endif
+
+/* Set up final (full) environment */
+
+	bl	c_runtime_cpu_setup	/* we still call old routine here */
+
+	ldr	r0, =__bss_start	/* this is auto-relocated! */
+	ldr	r1, =__bss_end__	/* this is aotu-relocated! */
+
+	mov	r2, #0x00000000		/* prepare zero to clear BSS */
+
+clbss_l:cmp	r0, r1			/* while not at end of BSS */
+	strlo	r2, [r0]		/* clear 32-bit BSS word */
+	addlo	r0, r0, #4		/* move to next
+	bhs	clbss_l
+
+#ifdef CONFIG_SPL_BUILD
+
+	bl coloured_LED_init
+	bl red_led_on
+
+#endif
+
+	/* call board_init_r(gd_t *id, ulong dest_addr) */
+
+	mov	lr, pc
+
+#if defined(CONFIG_NAND_SPL)
+	ldr     pc, _nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+	/* setup parameters for board_init_r */
+	mov	r0, r8			/* gd_t */
+	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
+	/* call board_init_r */
+	ldr	pc, _board_init_r	/* this is auto-relocated! */
+
+#endif
+
+	/* we should not return. */
diff --git a/include/common.h b/include/common.h
index b23e90b..230bc9f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -300,7 +300,7 @@ int	abortboot(int bootdelay);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
-void	board_init_f  (ulong) __attribute__ ((noreturn));
+void	board_init_f(ulong);
 void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
 int	checkboard    (void);
 int	checkflash    (void);
diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h
index 42077bd..5633d2a 100644
--- a/include/configs/socfpga_cyclone5.h
+++ b/include/configs/socfpga_cyclone5.h
@@ -65,7 +65,7 @@
 #define CONFIG_SYS_BOOTMAPSZ		((256*1024*1024) - (4*1024))
 
 #define CONFIG_SPL_RAM_DEVICE
-#define CONFIG_SPL_STACK (&__stack_start)
+#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
 #define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
 #define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
 
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c88f5d4..764e27b 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,5 +28,15 @@ int main(void)
 	DEFINE(GENERATED_BD_INFO_SIZE,
 		(sizeof(struct bd_info) + 15) & ~15);
 
+	DEFINE(GD_SIZE, sizeof(struct global_data));
+
+	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+	DEFINE(GD_RELOCADDR, offsetof(struct global_data, relocaddr));
+
+	DEFINE(GD_RELOC_OFF, offsetof(struct global_data, reloc_off));
+
+	DEFINE(GD_START_ADDR_SP, offsetof(struct global_data, start_addr_sp));
+
 	return 0;
 }
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index 43e72c4..2793aef 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -12,11 +12,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm1136/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/freescale/mx31pdk/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -49,6 +50,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm1136/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index becf7fa..825f06d 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -33,11 +33,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm926ejs/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/karo/tx25/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -70,6 +71,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm926ejs/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 2/2] arm: remove useless code in start.S files
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-04 11:32     ` Albert ARIBAUD
  2012-11-04 11:34     ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 11:32 UTC (permalink / raw)
  To: u-boot

Remove code such as unneeded includes or labels.
These removals have no functional effect.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- introduced in V2

 arch/arm/cpu/arm925t/start.S   |    4 ----
 arch/arm/cpu/arm926ejs/start.S |    6 ------
 2 files changed, 10 deletions(-)

diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 82f5b8b..e8d6d71 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -34,10 +34,6 @@
 #include <config.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1510)
-#include <./configs/omap1510.h>
-#endif
-
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 5dfd49a..6b91535 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -36,12 +36,6 @@
 #include <common.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1610)
-#include <./configs/omap1510.h>
-#elif defined(CONFIG_OMAP730)
-#include <./configs/omap730.h>
-#endif
-
 /*
  *************************************************************************
  *
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-04 11:32     ` [U-Boot] [PATCH v2 2/2] arm: remove useless code in start.S files Albert ARIBAUD
@ 2012-11-04 11:34     ` Albert ARIBAUD
  2012-11-04 15:06     ` Vikram Narayanan
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 11:34 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Sun,  4 Nov 2012 12:32:04 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> the code sequence from isetting up the initial stack

Argh. s/isetting/setting/ in V3...

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-04 11:43   ` Albert ARIBAUD
  2012-11-04 17:38     ` Tom Rini
  2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 11:43 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> The goal of this series is to scrub the start.S files
> which have proliferated across arch/arm and eliminate
> code redundancy.

I know this came a bit late in early nov 4th, but I really would like
it to be considered for 2013.01. Would you agree to make an exception
for it? Thanks in advance.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-04 11:32     ` [U-Boot] [PATCH v2 2/2] arm: remove useless code in start.S files Albert ARIBAUD
  2012-11-04 11:34     ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-04 15:06     ` Vikram Narayanan
  2012-11-04 18:01       ` Albert ARIBAUD
  2012-11-05  8:31     ` Andreas Bießmann
  2012-11-10 16:53     ` Albert ARIBAUD
  4 siblings, 1 reply; 47+ messages in thread
From: Vikram Narayanan @ 2012-11-04 15:06 UTC (permalink / raw)
  To: u-boot

Hello Albert,

On 11/4/2012 5:02 PM, Albert ARIBAUD wrote:
> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from isetting up the initial stack
> to calling into board_init_r().
>
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
>
> Some SPL targets had to be touched because they use
> start.S exolicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
>
> Signed-off-by: Albert ARIBAUD<albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

<snip>

> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> new file mode 100644
> index 0000000..fd6bd92
> --- /dev/null
> +++ b/arch/arm/lib/crt0.S
> @@ -0,0 +1,180 @@
> +/*
> + *  crt0 - C-runtime startup Code for ARM U-Boot
> + *
> + *  Copyright (c) 2012  Albert ARIBAUD<albert.u.boot@aribaud.net>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include<config.h>
> +#include<asm-offsets.h>
> +
> +/*
> + * This file handles the target-independent stages of the U-Boot
> + * start-up where a C runtime environment is needed. Its entry point
> + * is _main and is branched into from the target's start.S file.
> + *
> + * _main execution sequence is:
> + *
> + * 1. Set up initial environment for calling board_init_f().
> + *    This environment only provides a stack and a place to store
> + *    the GD ('global data') structure. In this context, VARIABLE
> + *    global data, initialized or not (BSS), are UNAVAILABLE; only
> + *    CONSTANT initialized data are available.
> + *
> + * 2. Call board_init_f(). This function prepares the hardware for
> + *    execution from DDR. As DDR may not be available, board_init_f()
> + *    must use GD to store any data which must be passed on to later,
> + *    stages, including the reloction destination and the new stack
> + *    pointer address, below which the stack resides and above it the
> + *    new GD resides.
> + *
> + * 3. Set up intermediate environment where the stack and GD are the
> + *    ones allocated by board_init_f() in DDR, but BSS and initialized
> + *    non-const data are still not available.
> + *
> + * 4. Call relocate_code(). This function relocates U-Boot from its
> + *    current location into the relocation destination computed by
> + *    board_init_f().
> + *
> + * 5. Set up final environment for calling board_init_r(). This
> + *    environment has BSS (initialized to 0), initialized non-const
> + *    data (initialized to their intended value), and stack in DDR.
> + *    GD has but retained values set by board_init_f(). Some CPUs
> + *    have some work to do at this point, so call c_runtime_cpu_setup.
> + *
> + * 6. Call noard_init_r(). If the function returns, reset the board.
> + */

s/noard_init_r/board_init_r

> +
> +/*
> + * offset of the nand_boot() function for SPL crt
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +
> +.globl nand_boot
> +_nand_boot:
> +	.word nand_boot
> +
> +#elif ! defined(CONFIG_SPL_BUILD)
> +
> +/*
> + * offset of the board_init_r() function for non-SPL crt
> + */
> +
> +.globl board_init_r
> +_board_init_r:
> +	.word board_init_r
> +
> +#endif
> +
> +/*
> + * start and end of BSS
> + */
> +
> +.globl __bss_start
> +.globl __bss_end__
> +
> +/*
> + * entry point of crt0 sequence
> + */
> +
> +.global _main
> +
> +_main:
> +
> +/*
> + * Set up initial C runtime environment and call board_init_f(0).
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +	/* deprecated, use instead CONFIG_SPL_BUILD */
> +	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#elif defined(CONFIG_SPL_BUILD)&&  defined(CONFIG_SPL_STACK)
> +	ldr	sp, =(CONFIG_SPL_STACK)
> +#else
> +	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#endif
> +	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
> +	mov	r8, sp		/* GD is above SP */
> +	mov	r0, #0
> +	bl	board_init_f
> +
> +/*
> + * Set up intermediate environment (new sp and gd) and call
> + * relocate_code(addr_sp, gd, addr_moni). Trick here is that
> + * we'll return 'here' but relocated.
> + */
> +
> +	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
> +	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
> +	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
> +
> +#ifndef CONFIG_SPL_BUILD

In some places the other style is used. "!(defined)".
Any particular reasons for switching b/w these two styles?

> +
> +	adr	lr, here
> +	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
> +	add	lr, lr, r0
> +	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
> +	mov	r1, r8				/* r1 = gd */
> +	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
> +	b	relocate_code
> +here:
> +
> +#endif
> +
> +/* Set up final (full) environment */
> +
> +	bl	c_runtime_cpu_setup	/* we still call old routine here */
> +
> +	ldr	r0, =__bss_start	/* this is auto-relocated! */
> +	ldr	r1, =__bss_end__	/* this is aotu-relocated! */

s/aotu/auto

Regards,
Vikram

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-04 11:43   ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
@ 2012-11-04 17:38     ` Tom Rini
  2012-11-05  7:39       ` Sughosh Ganu
  0 siblings, 1 reply; 47+ messages in thread
From: Tom Rini @ 2012-11-04 17:38 UTC (permalink / raw)
  To: u-boot

On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:

> Hi Tom,
> 
> On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> 
> > The goal of this series is to scrub the start.S files
> > which have proliferated across arch/arm and eliminate
> > code redundancy.
> 
> I know this came a bit late in early nov 4th, but I really would like
> it to be considered for 2013.01. Would you agree to make an exception
> for it? Thanks in advance.

If you can collect a diverse set of Tested-by's, yes.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20121104/191c58ba/attachment.pgp>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 15:06     ` Vikram Narayanan
@ 2012-11-04 18:01       ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-04 18:01 UTC (permalink / raw)
  To: u-boot

Hi Vikram,

On Sun, 04 Nov 2012 20:36:14 +0530, Vikram Narayanan
<vikram186@gmail.com> wrote:

> Hello Albert,

> > diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S

> > +#ifndef CONFIG_SPL_BUILD
> 
> In some places the other style is used. "!(defined)".
> Any particular reasons for switching b/w these two styles?

None except heterogeneity. In V3 I'll make sure 'defined()' is used
everywhere in the new files or added code.

> > +	ldr	r0, =__bss_start	/* this is auto-relocated! */
> > +	ldr	r1, =__bss_end__	/* this is aotu-relocated! */
> 
> s/aotu/auto

Thanks for spotting this. Will fix in V3.

> Regards,
> Vikram

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-04 17:38     ` Tom Rini
@ 2012-11-05  7:39       ` Sughosh Ganu
  2012-11-08 14:20         ` Sughosh Ganu
  0 siblings, 1 reply; 47+ messages in thread
From: Sughosh Ganu @ 2012-11-05  7:39 UTC (permalink / raw)
  To: u-boot

On Sun Nov 04, 2012 at 10:38:32AM -0700, Tom Rini wrote:
> On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:
> 
> > Hi Tom,
> > 
> > On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> > <albert.u.boot@aribaud.net> wrote:
> > 
> > > The goal of this series is to scrub the start.S files
> > > which have proliferated across arch/arm and eliminate
> > > code redundancy.
> > 
> > I know this came a bit late in early nov 4th, but I really would like
> > it to be considered for 2013.01. Would you agree to make an exception
> > for it? Thanks in advance.
> 
> If you can collect a diverse set of Tested-by's, yes.

I have not gone through the patch, but will test it in a day or two on
the hawkboard, and report the findings.

The hawkboard comes with the arm926ejs core, so that part of the code
would be tested.

-sughosh

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                       ` (2 preceding siblings ...)
  2012-11-04 15:06     ` Vikram Narayanan
@ 2012-11-05  8:31     ` Andreas Bießmann
  2012-11-10 16:48       ` Albert ARIBAUD
  2012-11-10 16:53     ` Albert ARIBAUD
  4 siblings, 1 reply; 47+ messages in thread
From: Andreas Bießmann @ 2012-11-05  8:31 UTC (permalink / raw)
  To: u-boot

Dear Albert Aribaud,

On 04.11.2012 12:32, Albert ARIBAUD wrote:
> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from isetting up the initial stack
> to calling into board_init_r().
> 
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
> 
> Some SPL targets had to be touched because they use
> start.S exolicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
> 
>  arch/arm/cpu/arm1136/start.S              |   62 ++--------
>  arch/arm/cpu/arm1176/start.S              |   62 ++--------
>  arch/arm/cpu/arm720t/start.S              |   53 ++-------
>  arch/arm/cpu/arm920t/start.S              |   61 ++--------
>  arch/arm/cpu/arm925t/start.S              |   61 ++--------
>  arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
>  arch/arm/cpu/arm946es/start.S             |   56 ++-------
>  arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
>  arch/arm/cpu/armv7/start.S                |   58 +++-------
>  arch/arm/cpu/ixp/start.S                  |   55 ++-------
>  arch/arm/cpu/pxa/start.S                  |   63 ++--------
>  arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
>  arch/arm/cpu/sa1100/start.S               |   50 ++------
>  arch/arm/lib/Makefile                     |    2 +
>  arch/arm/lib/board.c                      |   11 --
>  arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
>  include/common.h                          |    2 +-
>  include/configs/socfpga_cyclone5.h        |    2 +-
>  lib/asm-offsets.c                         |   10 ++
>  nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
>  nand_spl/board/karo/tx25/Makefile         |    6 +-
>  21 files changed, 324 insertions(+), 674 deletions(-)
>  create mode 100644 arch/arm/lib/crt0.S
> 

<snip>

> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> new file mode 100644
> index 0000000..fd6bd92
> --- /dev/null
> +++ b/arch/arm/lib/crt0.S
> @@ -0,0 +1,180 @@
> +/*
> + *  crt0 - C-runtime startup Code for ARM U-Boot
> + *
> + *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <config.h>
> +#include <asm-offsets.h>
> +
> +/*
> + * This file handles the target-independent stages of the U-Boot
> + * start-up where a C runtime environment is needed. Its entry point
> + * is _main and is branched into from the target's start.S file.
> + *
> + * _main execution sequence is:
> + *
> + * 1. Set up initial environment for calling board_init_f().
> + *    This environment only provides a stack and a place to store
> + *    the GD ('global data') structure. In this context, VARIABLE
> + *    global data, initialized or not (BSS), are UNAVAILABLE; only
> + *    CONSTANT initialized data are available.
> + *
> + * 2. Call board_init_f(). This function prepares the hardware for
> + *    execution from DDR. As DDR may not be available, board_init_f()

DDR means DRAM in general?

> + *    must use GD to store any data which must be passed on to later,
-----------------------------------------------------------------------^

> + *    stages, including the reloction destination and the new stack
> + *    pointer address, below which the stack resides and above it the
------------------------^
Full stop? The rest of the sentence makes no sense to me.

> + *    new GD resides.
> + *
> + * 3. Set up intermediate environment where the stack and GD are the
> + *    ones allocated by board_init_f() in DDR, but BSS and initialized
> + *    non-const data are still not available.
> + *
> + * 4. Call relocate_code(). This function relocates U-Boot from its
> + *    current location into the relocation destination computed by
> + *    board_init_f().
> + *
> + * 5. Set up final environment for calling board_init_r(). This
> + *    environment has BSS (initialized to 0), initialized non-const
> + *    data (initialized to their intended value), and stack in DDR.
> + *    GD has but retained values set by board_init_f(). Some CPUs
> + *    have some work to do at this point, so call c_runtime_cpu_setup.
> + *
> + * 6. Call noard_init_r(). If the function returns, reset the board.
> + */
> +
> +/*
> + * offset of the nand_boot() function for SPL crt
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +
> +.globl nand_boot
> +_nand_boot:
> +	.word nand_boot
> +
> +#elif ! defined(CONFIG_SPL_BUILD)
> +
> +/*
> + * offset of the board_init_r() function for non-SPL crt
> + */
> +
> +.globl board_init_r
> +_board_init_r:
> +	.word board_init_r
> +
> +#endif
> +
> +/*
> + * start and end of BSS
> + */
> +
> +.globl __bss_start
> +.globl __bss_end__
> +
> +/*
> + * entry point of crt0 sequence
> + */
> +
> +.global _main
> +
> +_main:
> +
> +/*
> + * Set up initial C runtime environment and call board_init_f(0).
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +	/* deprecated, use instead CONFIG_SPL_BUILD */
I wonder if we can emit a #warning here

> +	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
> +	ldr	sp, =(CONFIG_SPL_STACK)
> +#else
> +	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#endif
> +	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
> +	mov	r8, sp		/* GD is above SP */
> +	mov	r0, #0
> +	bl	board_init_f
> +
> +/*
> + * Set up intermediate environment (new sp and gd) and call
> + * relocate_code(addr_sp, gd, addr_moni). Trick here is that
> + * we'll return 'here' but relocated.
> + */
> +
> +	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
> +	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
> +	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
> +
> +#ifndef CONFIG_SPL_BUILD
> +
> +	adr	lr, here
> +	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
> +	add	lr, lr, r0
> +	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
> +	mov	r1, r8				/* r1 = gd */
> +	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
> +	b	relocate_code
> +here:
> +
> +#endif
> +
> +/* Set up final (full) environment */
> +
> +	bl	c_runtime_cpu_setup	/* we still call old routine here */
> +
> +	ldr	r0, =__bss_start	/* this is auto-relocated! */
> +	ldr	r1, =__bss_end__	/* this is aotu-relocated! */
> +
> +	mov	r2, #0x00000000		/* prepare zero to clear BSS */
> +
> +clbss_l:cmp	r0, r1			/* while not at end of BSS */
> +	strlo	r2, [r0]		/* clear 32-bit BSS word */
> +	addlo	r0, r0, #4		/* move to next
> +	bhs	clbss_l
> +
> +#ifdef CONFIG_SPL_BUILD

I think this should be negated. The coloured LED stuff was enabled for
non SPL builds before!

> +
> +	bl coloured_LED_init
> +	bl red_led_on
> +
> +#endif
> +
> +	/* call board_init_r(gd_t *id, ulong dest_addr) */
Shouldn't this move down in the #elif path?

> +
> +	mov	lr, pc
> +
> +#if defined(CONFIG_NAND_SPL)
> +	ldr     pc, _nand_boot
> +
> +#elif ! defined(CONFIG_SPL_BUILD)
> +
> +	/* setup parameters for board_init_r */
> +	mov	r0, r8			/* gd_t */
> +	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
> +	/* call board_init_r */
> +	ldr	pc, _board_init_r	/* this is auto-relocated! */
> +
> +#endif
> +
> +	/* we should not return. */

Best regards

Andreas Bie?mann

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-05  7:39       ` Sughosh Ganu
@ 2012-11-08 14:20         ` Sughosh Ganu
  2012-11-10 14:30           ` Albert ARIBAUD
  0 siblings, 1 reply; 47+ messages in thread
From: Sughosh Ganu @ 2012-11-08 14:20 UTC (permalink / raw)
  To: u-boot

hi Albert,

On Mon Nov 05, 2012 at 01:09:25PM +0530, Sughosh Ganu wrote:
> On Sun Nov 04, 2012 at 10:38:32AM -0700, Tom Rini wrote:
> > On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:
> > 
> > > Hi Tom,
> > > 
> > > On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> > > <albert.u.boot@aribaud.net> wrote:
> > > 
> > > > The goal of this series is to scrub the start.S files
> > > > which have proliferated across arch/arm and eliminate
> > > > code redundancy.
> > > 
> > > I know this came a bit late in early nov 4th, but I really would like
> > > it to be considered for 2013.01. Would you agree to make an exception
> > > for it? Thanks in advance.
> > 
> > If you can collect a diverse set of Tested-by's, yes.
> 
> I have not gone through the patch, but will test it in a day or two on
> the hawkboard, and report the findings.
> 
> The hawkboard comes with the arm926ejs core, so that part of the code
> would be tested.

I tried the 1st patch of the series, and with that u-boot does not
come up on the board. It is also printing out some random values for
the dram and nand sizes.

The patch was applied on top of commit 1cc619be8b7. Also, with the
mentioned commit, u-boot boots up fine on the board. Also to be noted
is that the spl image compiled with these changes is booting up fine,
loading the main u-boot image, and jumping to it -- the issue is with
booting the main u-boot image.

-sughosh

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-08 14:20         ` Sughosh Ganu
@ 2012-11-10 14:30           ` Albert ARIBAUD
  2012-11-13  4:10             ` Sughosh Ganu
  0 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 14:30 UTC (permalink / raw)
  To: u-boot

Hi Sughosh,

On Thu, 8 Nov 2012 19:50:28 +0530, Sughosh Ganu
<urwithsughosh@gmail.com> wrote:

> hi Albert,
> 
> On Mon Nov 05, 2012 at 01:09:25PM +0530, Sughosh Ganu wrote:
> > On Sun Nov 04, 2012 at 10:38:32AM -0700, Tom Rini wrote:
> > > On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:
> > > 
> > > > Hi Tom,
> > > > 
> > > > On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> > > > <albert.u.boot@aribaud.net> wrote:
> > > > 
> > > > > The goal of this series is to scrub the start.S files
> > > > > which have proliferated across arch/arm and eliminate
> > > > > code redundancy.
> > > > 
> > > > I know this came a bit late in early nov 4th, but I really would like
> > > > it to be considered for 2013.01. Would you agree to make an exception
> > > > for it? Thanks in advance.
> > > 
> > > If you can collect a diverse set of Tested-by's, yes.
> > 
> > I have not gone through the patch, but will test it in a day or two on
> > the hawkboard, and report the findings.
> > 
> > The hawkboard comes with the arm926ejs core, so that part of the code
> > would be tested.
> 
> I tried the 1st patch of the series, and with that u-boot does not
> come up on the board. It is also printing out some random values for
> the dram and nand sizes.
> 
> The patch was applied on top of commit 1cc619be8b7. Also, with the
> mentioned commit, u-boot boots up fine on the board. Also to be noted
> is that the spl image compiled with these changes is booting up fine,
> loading the main u-boot image, and jumping to it -- the issue is with
> booting the main u-boot image.

Thanks Sughosh. Can you build an U-Boot with the following defined
in the hawkboard.h config file?

#define DEBUG
#if defined(CONFIG_SPL_BUILD) && ! defined (__ASSEMBLY__)
static inline int printf(const char *fmt, ...)
{
        return 0;
}
#endif

Note: only the #define DEBUG matter to me, but with it alone, SPL build
fails due to some code now requiring printf(). This is why I add a
dummy printf definition for C code during SPL build -- ASM code does not
need printf() and actually chokes on the definition, hence the
condition on __ASSEMBLY__.

This debug U-Boot should print a lot more info. Can you please try it
and copy/paste its output here? Thanks in advance.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-05  8:31     ` Andreas Bießmann
@ 2012-11-10 16:48       ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 16:48 UTC (permalink / raw)
  To: u-boot

Hi Andreas,

On Mon, 05 Nov 2012 09:31:55 +0100, "Andreas Bie?mann"
<andreas.devel@googlemail.com> wrote:

> Dear Albert Aribaud,

> DDR means DRAM in general?

Yes -- but DRAM is no better, as it still describes a technology
(class). I'm going tu use "system RAM" to describe it.

> > + *    must use GD to store any data which must be passed on to later,
> -----------------------------------------------------------------------^

Fixed.

> > + *    stages, including the reloction destination and the new stack
> > + *    pointer address, below which the stack resides and above it the
> ------------------------^
> Full stop? The rest of the sentence makes no sense to me.

Rewritten.

> > +#if defined(CONFIG_NAND_SPL)
> > +	/* deprecated, use instead CONFIG_SPL_BUILD */
> I wonder if we can emit a #warning here

Hmm... Will test and let people know how many boards stop compiling
cleanly.

> > +#ifdef CONFIG_SPL_BUILD
> 
> I think this should be negated. The coloured LED stuff was enabled for
> non SPL builds before!

Correct.

> > +
> > +	bl coloured_LED_init
> > +	bl red_led_on
> > +
> > +#endif
> > +
> > +	/* call board_init_r(gd_t *id, ulong dest_addr) */
> Shouldn't this move down in the #elif path?

Moved.

> Best regards
> 
> Andreas Bie?mann

Thanks a lot for your review!

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                       ` (3 preceding siblings ...)
  2012-11-05  8:31     ` Andreas Bießmann
@ 2012-11-10 16:53     ` Albert ARIBAUD
  4 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 16:53 UTC (permalink / raw)
  To: u-boot

Reviewing myself:

On Sun,  4 Nov 2012 12:32:04 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> new file mode 100644
> index 0000000..fd6bd92
> --- /dev/null
> +++ b/arch/arm/lib/crt0.S

> +clbss_l:cmp	r0, r1			/* while not at end of BSS */
> +	strlo	r2, [r0]		/* clear 32-bit BSS word */
> +	addlo	r0, r0, #4		/* move to next

Unclosed comment here. This causes the following code to be ignored:

> +	bhs	clbss_l
> +
> +#ifdef CONFIG_SPL_BUILD
> +
> +	bl coloured_LED_init
> +	bl red_led_on
> +
> +#endif
> +
> +	/* call board_init_r(gd_t *id, ulong dest_addr) */

Which might explain why SPL builds did not complain about LED calls and
why some boards failed.

Also:

> +#if defined(CONFIG_NAND_SPL)
> +	ldr     pc, _nand_boot
> +
> +#elif ! defined(CONFIG_SPL_BUILD)
> +
> +	/* setup parameters for board_init_r */
> +	mov	r0, r8			/* gd_t */
> +	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
> +	/* call board_init_r */
> +	ldr	pc, _board_init_r	/* this is auto-relocated! */
> +
> +#endif

The #elif is wrong, as it causes CONFIG_SPL_BUILD builds to not call
board_init_f() at all; actually, they overrun into whatever follows.
This might have been what Sughosh (Cc:) hit with the hawkboard.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 0/2] Factorize ARM startup code as mush as possible.
  2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-04 11:43   ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
@ 2012-11-10 17:00   ` Albert ARIBAUD
  2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                       ` (2 more replies)
  2 siblings, 3 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 17:00 UTC (permalink / raw)
  To: u-boot

The goal of this series is to scrub the start.S files
which have proliferated across arch/arm and eliminate
code redundancy.

Currently this series only factorizes the C runtime
framework, that is, the assembly code responsible for
setting up the C environments needed by board_init_*()
and relocate_code().

Further factorization is possible: relocate_code() can
be moved out and possibly rewritten in C now that it
has plain C function semantics; exception handlers
should also be pretty much cpu-independent.

Eventually, start.S files should disappear or contain
CPU-specific code only.

The new C runtime setup sequence has been validated step by
step on target versatileqemu using toolchain ELDK4.2.

The whole changes have been build-tested across all ARM
targets using MAKEALL -a arm.

Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case
Series-changes: 2
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
- no change

Changes in v2:
- introduced in V2

Albert ARIBAUD (2):
  arm: move C runtime setup code in crt0.S
  arm: remove useless code in start.S files

 arch/arm/cpu/arm1136/start.S              |   69 +++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   65 ++---------
 arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 329 insertions(+), 686 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S
  2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
@ 2012-11-10 17:00     ` Albert ARIBAUD
  2012-11-10 17:00       ` [U-Boot] [PATCH v3 2/2] arm: remove useless code in start.S files Albert ARIBAUD
  2012-11-15 19:35       ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Simon Glass
  2012-11-10 17:28     ` [U-Boot] [PATCH v3 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
  2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2 siblings, 2 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 17:00 UTC (permalink / raw)
  To: u-boot

Move all the C runtime setup code from every start.S
in arch/arm into arch/arm/lib/crt0.S. This covers
the code sequence from isetting up the initial stack
to calling into board_init_r().

Also, rewrite the C runtime setup and make functions
board_init_*() and relocate_code() behave according to
normal C semantics (no jumping across the C stack any
more, etc).

Some SPL targets had to be touched because they use
start.S exolicitly or for some reason; the relevant
maintainers and custodians are cc:ed.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case
Series-changes: 2
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

 arch/arm/cpu/arm1136/start.S              |   69 +++--------
 arch/arm/cpu/arm1176/start.S              |   62 ++--------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++-------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++--------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 329 insertions(+), 676 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 5d3b4c2..d19c1ed 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -165,13 +165,7 @@ next:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -188,14 +182,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -255,52 +245,21 @@ _dynsym_start_ofs:
 	.word __dynsym_start - _start
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
+relocate_done:
 
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+	bx	lr
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+_rel_dyn_start_ofs:
+	.word __rel_dyn_start - _start
+_rel_dyn_end_ofs:
+	.word __rel_dyn_end - _start
+_dynsym_start_ofs:
+	.word __dynsym_start - _start
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
 
 /*
  *************************************************************************
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 667a0e0..40df4b1 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -224,12 +224,7 @@ skip_tcmdisable:
 	 */
 	bl	lowlevel_init		/* go setup pll,mux,memory */
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -246,14 +241,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -343,49 +334,9 @@ mmu_enable:
 skip_hw_init:
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#ifndef CONFIG_NAND_SPL
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
-
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add     lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -399,6 +350,11 @@ _mmu_table_base:
 	.word mmu_table
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 #ifndef CONFIG_NAND_SPL
 /*
  * we assume that cache operation is done before. (eg. cleanup_before_linux())
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index c2a7763..771d386 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,43 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -272,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 14c9156..511d21d 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -182,12 +182,7 @@ copyex:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -204,14 +199,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -263,51 +254,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -315,6 +265,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 3a483f6..82f5b8b 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -176,12 +176,7 @@ poll1:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -198,14 +193,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -257,51 +248,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -309,6 +259,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 2188f7e..5dfd49a 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,20 +198,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#else
-#ifdef CONFIG_SPL_BUILD
-	ldr	sp, =(CONFIG_SPL_STACK)
-#else
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#endif
-#endif
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -229,15 +216,11 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	sub	r9, r6, r0		/* r9 <- relocation offset */
 	cmp	r0, r6
-	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	moveq	r9, #0			/* no relocation. offset(r9) = 0 */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -289,56 +272,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
+relocate_done:
 
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-#ifndef CONFIG_SPL_BUILD
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	ldr	r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -346,8 +282,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 30e2183..a7a98a4 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,46 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
+relocate_done:
 
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -275,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index a133d19..c189849 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -143,12 +143,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -165,14 +160,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -224,50 +215,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -276,6 +226,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 7df97c5..dcc1f83 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -155,12 +155,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -177,14 +172,10 @@ ENTRY(relocate_code)
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -233,34 +224,22 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+
+relocate_done:
+
+	bx	lr
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+ENDPROC(relocate_code)
 
-clear_bss:
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+#endif
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-jump_2_ram:
+ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
  */
@@ -279,20 +258,9 @@ jump_2_ram:
 	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
 #endif /* !Tegra20 */
 
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-ENDPROC(relocate_code)
-#endif
+	bx	lr
+
+ENDPROC(c_runtime_cpu_setup)
 
 /*************************************************************************
  *
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index c12f1a7..efb5a40 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -245,12 +245,7 @@ reset:
 	orr	r0,r0,#0x13
 	msr	cpsr,r0
 
-/* Set initial stackpointer in SDRAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -267,14 +262,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -326,42 +317,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -370,6 +328,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /****************************************************************************/
 /*									    */
 /* Interrupt handling							    */
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 536cf5c..72af869 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -164,12 +164,7 @@ reset:
 	bl	lock_cache_for_stack
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0, =0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 #ifndef CONFIG_SPL_BUILD
@@ -186,10 +181,6 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 /* Disable the Dcache RAM lock for stack now */
 #ifdef	CONFIG_CPU_PXA25X
 	bl	cpu_init_crit
@@ -198,7 +189,7 @@ stack_setup:
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -250,48 +241,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_ONENAND_SPL
-	ldr     r0, _onenand_boot_ofs
-	mov	pc, r0
-
-_onenand_boot_ofs:
-	.word onenand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -299,7 +251,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
+
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 323b923..4528c91 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -128,12 +128,7 @@ reset:
 	bl	lowlevel_init
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -150,14 +145,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -209,42 +200,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,6 +211,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 1ea92d1..3144299 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -132,12 +132,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -154,14 +149,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -213,40 +204,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -254,6 +215,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..07baee2 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,6 +36,8 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+SOBJS-y += crt0.o
+
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 92cad9a..ad96d7e 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -272,11 +272,6 @@ void board_init_f(ulong bootflag)
 
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
-	/* compiler optimization barrier needed for GCC >= 3.4 */
-	__asm__ __volatile__("": : :"memory");
-
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
@@ -458,10 +453,6 @@ void board_init_f(ulong bootflag)
 		gd->fdt_blob = new_fdt;
 	}
 	memcpy(id, (void *)gd, sizeof(gd_t));
-
-	relocate_code(addr_sp, id, addr);
-
-	/* NOTREACHED - relocate_code() does not return */
 }
 
 #if !defined(CONFIG_SYS_NO_FLASH)
@@ -486,8 +477,6 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	ulong flash_size;
 #endif
 
-	gd = id;
-
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
new file mode 100644
index 0000000..ad6c71d
--- /dev/null
+++ b/arch/arm/lib/crt0.S
@@ -0,0 +1,180 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM U-Boot
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+
+/*
+ * This file handles the target-independent stages of the U-Boot
+ * start-up where a C runtime environment is needed. Its entry point
+ * is _main and is branched into from the target's start.S file.
+ *
+ * _main execution sequence is:
+ *
+ * 1. Set up initial environment for calling board_init_f().
+ *    This environment only provides a stack and a place to store
+ *    the GD ('global data') structure, both located in some readily
+ *    available RAM (SRAM, locked cache...). In this context, VARIABLE
+ *    global data, initialized or not (BSS), are UNAVAILABLE; only
+ *    CONSTANT initialized data are available.
+ *
+ * 2. Call board_init_f(). This function prepares the hardware for
+ *    execution from system RAM (DRAM, DDR...) As system RAM may not
+ *    be available yet, , board_init_f() must use the current GD to
+ *    store any data which must be passed on to later stages. These
+ *    data include the relocation destination, the future stack, and
+ *    the future GD location.
+ *
+ * 3. Set up intermediate environment where the stack and GD are the
+ *    ones allocated by board_init_f() in system RAM, but BSS and
+ *    initialized non-const data are still not available.
+ *
+ * 4. Call relocate_code(). This function relocates U-Boot from its
+ *    current location into the relocation destination computed by
+ *    board_init_f().
+ *
+ * 5. Set up final environment for calling board_init_r(). This
+ *    environment has BSS (initialized to 0), initialized non-const
+ *    data (initialized to their intended value), and stack in system
+ *    RAM. GD has retained values set by board_init_f(). Some CPUs
+ *    have some work left to do at this point regarding memory, so
+ *    call c_runtime_cpu_setup.
+ *
+ * 6. Branch to either _nand_boot() or board_init_r().
+ */
+
+/*
+ * offset of the nand_boot() function for SPL crt
+ */
+
+#if defined(CONFIG_NAND_SPL)
+
+.globl nand_boot
+_nand_boot:
+	.word nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+/*
+ * offset of the board_init_r() function for non-SPL crt
+ */
+
+.globl board_init_r
+_board_init_r:
+	.word board_init_r
+
+#endif
+
+/*
+ * start and end of BSS
+ */
+
+.globl __bss_start
+.globl __bss_end__
+
+/*
+ * entry point of crt0 sequence
+ */
+
+.global _main
+
+_main:
+
+/*
+ * Set up initial C runtime environment and call board_init_f(0).
+ */
+
+#if defined(CONFIG_NAND_SPL)
+	/* deprecated, use instead CONFIG_SPL_BUILD */
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
+	ldr	sp, =(CONFIG_SPL_STACK)
+#else
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#endif
+	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
+	mov	r8, sp		/* GD is above SP */
+	mov	r0, #0
+	bl	board_init_f
+
+/*
+ * Set up intermediate environment (new sp and gd) and call
+ * relocate_code(addr_sp, gd, addr_moni). Trick here is that
+ * we'll return 'here' but relocated.
+ */
+
+	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
+	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
+	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
+
+#if ! defined(CONFIG_SPL_BUILD)
+
+	adr	lr, here
+	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
+	add	lr, lr, r0
+	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
+	mov	r1, r8				/* r1 = gd */
+	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
+	b	relocate_code
+here:
+
+#endif
+
+/* Set up final (full) environment */
+
+	bl	c_runtime_cpu_setup	/* we still call old routine here */
+
+	ldr	r0, =__bss_start	/* this is auto-relocated! */
+	ldr	r1, =__bss_end__	/* this is auto-relocated! */
+
+	mov	r2, #0x00000000		/* prepare zero to clear BSS */
+
+clbss_l:cmp	r0, r1			/* while not at end of BSS */
+	strlo	r2, [r0]		/* clear 32-bit BSS word */
+	addlo	r0, r0, #4		/* move to next */
+	bhs	clbss_l
+
+#if ! defined(CONFIG_SPL_BUILD)
+
+	bl coloured_LED_init
+	bl red_led_on
+
+#endif
+
+#if defined(CONFIG_NAND_SPL)
+
+	/* call _nand_boot() */
+	ldr     pc, _nand_boot
+
+#else
+
+	/* call board_init_r(gd_t *id, ulong dest_addr) */
+	mov	r0, r8			/* gd_t */
+	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
+	/* call board_init_r */
+	ldr	pc, _board_init_r	/* this is auto-relocated! */
+
+#endif
+
+	/* we should not return here. */
diff --git a/include/common.h b/include/common.h
index 5e3c5ee..69a1ccd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -300,7 +300,7 @@ int	abortboot(int bootdelay);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
-void	board_init_f  (ulong) __attribute__ ((noreturn));
+void	board_init_f(ulong);
 void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
 int	checkboard    (void);
 int	checkflash    (void);
diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h
index 42077bd..5633d2a 100644
--- a/include/configs/socfpga_cyclone5.h
+++ b/include/configs/socfpga_cyclone5.h
@@ -65,7 +65,7 @@
 #define CONFIG_SYS_BOOTMAPSZ		((256*1024*1024) - (4*1024))
 
 #define CONFIG_SPL_RAM_DEVICE
-#define CONFIG_SPL_STACK (&__stack_start)
+#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
 #define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
 #define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
 
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c88f5d4..764e27b 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,5 +28,15 @@ int main(void)
 	DEFINE(GENERATED_BD_INFO_SIZE,
 		(sizeof(struct bd_info) + 15) & ~15);
 
+	DEFINE(GD_SIZE, sizeof(struct global_data));
+
+	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+	DEFINE(GD_RELOCADDR, offsetof(struct global_data, relocaddr));
+
+	DEFINE(GD_RELOC_OFF, offsetof(struct global_data, reloc_off));
+
+	DEFINE(GD_START_ADDR_SP, offsetof(struct global_data, start_addr_sp));
+
 	return 0;
 }
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index 43e72c4..2793aef 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -12,11 +12,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm1136/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/freescale/mx31pdk/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -49,6 +50,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm1136/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index becf7fa..825f06d 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -33,11 +33,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm926ejs/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/karo/tx25/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -70,6 +71,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm926ejs/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 2/2] arm: remove useless code in start.S files
  2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-10 17:00       ` Albert ARIBAUD
  2012-11-15 19:35       ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Simon Glass
  1 sibling, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 17:00 UTC (permalink / raw)
  To: u-boot

Remove code such as unneeded includes or labels.
These removals have no functional effect.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- no change

Changes in v2:
- introduced in V2

 arch/arm/cpu/arm925t/start.S   |    4 ----
 arch/arm/cpu/arm926ejs/start.S |    6 ------
 2 files changed, 10 deletions(-)

diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 82f5b8b..e8d6d71 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -34,10 +34,6 @@
 #include <config.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1510)
-#include <./configs/omap1510.h>
-#endif
-
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 5dfd49a..6b91535 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -36,12 +36,6 @@
 #include <common.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1610)
-#include <./configs/omap1510.h>
-#elif defined(CONFIG_OMAP730)
-#include <./configs/omap730.h>
-#endif
-
 /*
  *************************************************************************
  *
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 0/2] Factorize ARM startup code as mush as possible.
  2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-10 17:28     ` Albert ARIBAUD
  2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-10 17:28 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Sat, 10 Nov 2012 18:00:11 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> The goal of this series is to scrub the start.S files
> which have proliferated across arch/arm and eliminate
> code redundancy.
> 
> Currently this series only factorizes the C runtime
> framework, that is, the assembly code responsible for
> setting up the C environments needed by board_init_*()
> and relocate_code().
> 
> Further factorization is possible: relocate_code() can
> be moved out and possibly rewritten in C now that it
> has plain C function semantics; exception handlers
> should also be pretty much cpu-independent.
> 
> Eventually, start.S files should disappear or contain
> CPU-specific code only.
> 
> The new C runtime setup sequence has been validated step by
> step on target versatileqemu using toolchain ELDK4.2.
> 
> The whole changes have been build-tested across all ARM
> targets using MAKEALL -a arm.
> 
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case

Note there is no warning for using 'deprecated' NAND_SPL yet. I'm
running full MAKEALL -a arm on this and it'll be added in v4 depending
on results.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-10 14:30           ` Albert ARIBAUD
@ 2012-11-13  4:10             ` Sughosh Ganu
  2012-11-13 19:55               ` Albert ARIBAUD
  0 siblings, 1 reply; 47+ messages in thread
From: Sughosh Ganu @ 2012-11-13  4:10 UTC (permalink / raw)
  To: u-boot

hi Albert,

On Sat, Nov 10, 2012 at 8:00 PM, Albert ARIBAUD
<albert.u.boot@aribaud.net>wrote:

> Hi Sughosh,
>
> On Thu, 8 Nov 2012 19:50:28 +0530, Sughosh Ganu
> <urwithsughosh@gmail.com> wrote:
>
> > hi Albert,
> >
> > On Mon Nov 05, 2012 at 01:09:25PM +0530, Sughosh Ganu wrote:
> > > On Sun Nov 04, 2012 at 10:38:32AM -0700, Tom Rini wrote:
> > > > On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:
> > > >
> > > > > Hi Tom,
> > > > >
> > > > > On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> > > > > <albert.u.boot@aribaud.net> wrote:
> > > > >
> > > > > > The goal of this series is to scrub the start.S files
> > > > > > which have proliferated across arch/arm and eliminate
> > > > > > code redundancy.
> > > > >
> > > > > I know this came a bit late in early nov 4th, but I really would
> like
> > > > > it to be considered for 2013.01. Would you agree to make an
> exception
> > > > > for it? Thanks in advance.
> > > >
> > > > If you can collect a diverse set of Tested-by's, yes.
> > >
> > > I have not gone through the patch, but will test it in a day or two on
> > > the hawkboard, and report the findings.
> > >
> > > The hawkboard comes with the arm926ejs core, so that part of the code
> > > would be tested.
> >
> > I tried the 1st patch of the series, and with that u-boot does not
> > come up on the board. It is also printing out some random values for
> > the dram and nand sizes.
> >
> > The patch was applied on top of commit 1cc619be8b7. Also, with the
> > mentioned commit, u-boot boots up fine on the board. Also to be noted
> > is that the spl image compiled with these changes is booting up fine,
> > loading the main u-boot image, and jumping to it -- the issue is with
> > booting the main u-boot image.
>
> Thanks Sughosh. Can you build an U-Boot with the following defined
> in the hawkboard.h config file?
>
> #define DEBUG
> #if defined(CONFIG_SPL_BUILD) && ! defined (__ASSEMBLY__)
> static inline int printf(const char *fmt, ...)
> {
>         return 0;
> }
> #endif
>
> Note: only the #define DEBUG matter to me, but with it alone, SPL build
> fails due to some code now requiring printf(). This is why I add a
> dummy printf definition for C code during SPL build -- ASM code does not
> need printf() and actually chokes on the definition, hence the
> condition on __ASSEMBLY__.
>
> This debug U-Boot should print a lot more info. Can you please try it
> and copy/paste its output here? Thanks in advance.
>

Unfortunately i am currently on vacation, with no access to the board, and
would be able to try out your suggested changes only after   i am back, by
the end of next week. In the meantime, i am also trying to get myself a
jtag debugger -- it is quite frustrating to provide half baked information.

I had tried enabling DEBUG in the board.c file, and with that, i saw that
board_init_f completes, and the board hangs after returning from the
function. Now i really need a debugger to figure out where exactly is the
problem, as it could be in the relocation part, or while trying to jump to
the board_init_r after having relocated the code. Hopefully, with a jtag
debugger, i will be able to provide you a lot more info.

-sughosh

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-13  4:10             ` Sughosh Ganu
@ 2012-11-13 19:55               ` Albert ARIBAUD
  2012-12-09 20:31                 ` Sughosh Ganu
  0 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-13 19:55 UTC (permalink / raw)
  To: u-boot

Hi Sughosh,

On Tue, 13 Nov 2012 09:40:19 +0530, Sughosh Ganu
<urwithsughosh@gmail.com> wrote:

> hi Albert,
> 
> On Sat, Nov 10, 2012 at 8:00 PM, Albert ARIBAUD
> <albert.u.boot@aribaud.net>wrote:
> 
> > Hi Sughosh,
> >
> > On Thu, 8 Nov 2012 19:50:28 +0530, Sughosh Ganu
> > <urwithsughosh@gmail.com> wrote:
> >
> > > hi Albert,
> > >
> > > On Mon Nov 05, 2012 at 01:09:25PM +0530, Sughosh Ganu wrote:
> > > > On Sun Nov 04, 2012 at 10:38:32AM -0700, Tom Rini wrote:
> > > > > On Sun, Nov 04, 2012 at 12:43:12PM +0100, Albert ARIBAUD wrote:
> > > > >
> > > > > > Hi Tom,
> > > > > >
> > > > > > On Sun,  4 Nov 2012 12:32:03 +0100, Albert ARIBAUD
> > > > > > <albert.u.boot@aribaud.net> wrote:
> > > > > >
> > > > > > > The goal of this series is to scrub the start.S files
> > > > > > > which have proliferated across arch/arm and eliminate
> > > > > > > code redundancy.
> > > > > >
> > > > > > I know this came a bit late in early nov 4th, but I really would
> > like
> > > > > > it to be considered for 2013.01. Would you agree to make an
> > exception
> > > > > > for it? Thanks in advance.
> > > > >
> > > > > If you can collect a diverse set of Tested-by's, yes.
> > > >
> > > > I have not gone through the patch, but will test it in a day or two on
> > > > the hawkboard, and report the findings.
> > > >
> > > > The hawkboard comes with the arm926ejs core, so that part of the code
> > > > would be tested.
> > >
> > > I tried the 1st patch of the series, and with that u-boot does not
> > > come up on the board. It is also printing out some random values for
> > > the dram and nand sizes.
> > >
> > > The patch was applied on top of commit 1cc619be8b7. Also, with the
> > > mentioned commit, u-boot boots up fine on the board. Also to be noted
> > > is that the spl image compiled with these changes is booting up fine,
> > > loading the main u-boot image, and jumping to it -- the issue is with
> > > booting the main u-boot image.
> >
> > Thanks Sughosh. Can you build an U-Boot with the following defined
> > in the hawkboard.h config file?
> >
> > #define DEBUG
> > #if defined(CONFIG_SPL_BUILD) && ! defined (__ASSEMBLY__)
> > static inline int printf(const char *fmt, ...)
> > {
> >         return 0;
> > }
> > #endif
> >
> > Note: only the #define DEBUG matter to me, but with it alone, SPL build
> > fails due to some code now requiring printf(). This is why I add a
> > dummy printf definition for C code during SPL build -- ASM code does not
> > need printf() and actually chokes on the definition, hence the
> > condition on __ASSEMBLY__.
> >
> > This debug U-Boot should print a lot more info. Can you please try it
> > and copy/paste its output here? Thanks in advance.
> >
> 
> Unfortunately i am currently on vacation, with no access to the board, and
> would be able to try out your suggested changes only after   i am back, by
> the end of next week. In the meantime, i am also trying to get myself a
> jtag debugger -- it is quite frustrating to provide half baked information.
> 
> I had tried enabling DEBUG in the board.c file, and with that, i saw that
> board_init_f completes, and the board hangs after returning from the
> function. Now i really need a debugger to figure out where exactly is the
> problem, as it could be in the relocation part, or while trying to jump to
> the board_init_r after having relocated the code. Hopefully, with a jtag
> debugger, i will be able to provide you a lot more info.
> 
> -sughosh

Thanks for the feedback. Meanwhile, I have found two ugly bugs which
would certainly affect execution past board_init_f(), so maybe your
hawkboard was bitten by theses; next time please try v3, which fixes
these bugs, or the latest patch version if v3 is obsolete by the time
you come back.

Enjoy your vacation!

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S
  2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-10 17:00       ` [U-Boot] [PATCH v3 2/2] arm: remove useless code in start.S files Albert ARIBAUD
@ 2012-11-15 19:35       ` Simon Glass
  2012-11-15 22:41         ` Albert ARIBAUD
  1 sibling, 1 reply; 47+ messages in thread
From: Simon Glass @ 2012-11-15 19:35 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Sat, Nov 10, 2012 at 9:00 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from isetting up the initial stack
> to calling into board_init_r().
>
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
>
> Some SPL targets had to be touched because they use
> start.S exolicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
>
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

I am very pleased to see this. My generic relocation series from some
time ago is still hanging around. Your series tidies up some things
which would make that series easier to do. I'm happy to take another
look at it.

I have tested your series on a Tegra seaboard, and got it running with
a few changes. Please see comments below.

> ---
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case
> Series-changes: 2
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
>
>  arch/arm/cpu/arm1136/start.S              |   69 +++--------
>  arch/arm/cpu/arm1176/start.S              |   62 ++--------
>  arch/arm/cpu/arm720t/start.S              |   53 ++-------
>  arch/arm/cpu/arm920t/start.S              |   61 ++--------
>  arch/arm/cpu/arm925t/start.S              |   61 ++--------
>  arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
>  arch/arm/cpu/arm946es/start.S             |   56 ++-------
>  arch/arm/cpu/arm_intcm/start.S            |   63 ++--------
>  arch/arm/cpu/armv7/start.S                |   58 +++-------
>  arch/arm/cpu/ixp/start.S                  |   55 ++-------
>  arch/arm/cpu/pxa/start.S                  |   63 ++--------
>  arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
>  arch/arm/cpu/sa1100/start.S               |   50 ++------
>  arch/arm/lib/Makefile                     |    2 +
>  arch/arm/lib/board.c                      |   11 --
>  arch/arm/lib/crt0.S                       |  180 +++++++++++++++++++++++++++++
>  include/common.h                          |    2 +-
>  include/configs/socfpga_cyclone5.h        |    2 +-
>  lib/asm-offsets.c                         |   10 ++
>  nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
>  nand_spl/board/karo/tx25/Makefile         |    6 +-
>  21 files changed, 329 insertions(+), 676 deletions(-)
>  create mode 100644 arch/arm/lib/crt0.S
>
[snip]
> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> new file mode 100644
> index 0000000..ad6c71d
> --- /dev/null
> +++ b/arch/arm/lib/crt0.S
> @@ -0,0 +1,180 @@
> +/*
> + *  crt0 - C-runtime startup Code for ARM U-Boot
> + *
> + *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <config.h>
> +#include <asm-offsets.h>
> +
> +/*
> + * This file handles the target-independent stages of the U-Boot
> + * start-up where a C runtime environment is needed. Its entry point
> + * is _main and is branched into from the target's start.S file.
> + *
> + * _main execution sequence is:
> + *
> + * 1. Set up initial environment for calling board_init_f().
> + *    This environment only provides a stack and a place to store
> + *    the GD ('global data') structure, both located in some readily
> + *    available RAM (SRAM, locked cache...). In this context, VARIABLE
> + *    global data, initialized or not (BSS), are UNAVAILABLE; only
> + *    CONSTANT initialized data are available.
> + *
> + * 2. Call board_init_f(). This function prepares the hardware for
> + *    execution from system RAM (DRAM, DDR...) As system RAM may not
> + *    be available yet, , board_init_f() must use the current GD to
> + *    store any data which must be passed on to later stages. These
> + *    data include the relocation destination, the future stack, and
> + *    the future GD location.
> + *
> + * 3. Set up intermediate environment where the stack and GD are the
> + *    ones allocated by board_init_f() in system RAM, but BSS and
> + *    initialized non-const data are still not available.
> + *
> + * 4. Call relocate_code(). This function relocates U-Boot from its
> + *    current location into the relocation destination computed by
> + *    board_init_f().
> + *
> + * 5. Set up final environment for calling board_init_r(). This
> + *    environment has BSS (initialized to 0), initialized non-const
> + *    data (initialized to their intended value), and stack in system
> + *    RAM. GD has retained values set by board_init_f(). Some CPUs
> + *    have some work left to do at this point regarding memory, so
> + *    call c_runtime_cpu_setup.
> + *
> + * 6. Branch to either _nand_boot() or board_init_r().
> + */
> +
> +/*
> + * offset of the nand_boot() function for SPL crt
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +
> +.globl nand_boot
> +_nand_boot:
> +       .word nand_boot
> +
> +#elif ! defined(CONFIG_SPL_BUILD)
> +
> +/*
> + * offset of the board_init_r() function for non-SPL crt
> + */
> +
> +.globl board_init_r
> +_board_init_r:
> +       .word board_init_r
> +
> +#endif
> +
> +/*
> + * start and end of BSS
> + */
> +
> +.globl __bss_start
> +.globl __bss_end__
> +
> +/*
> + * entry point of crt0 sequence
> + */
> +
> +.global _main
> +
> +_main:
> +
> +/*
> + * Set up initial C runtime environment and call board_init_f(0).
> + */
> +
> +#if defined(CONFIG_NAND_SPL)
> +       /* deprecated, use instead CONFIG_SPL_BUILD */
> +       ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
> +       ldr     sp, =(CONFIG_SPL_STACK)
> +#else
> +       ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
> +#endif
> +       bic     sp, sp, #7 /* 8-byte alignment for ABI compliance */
> +       mov     r8, sp          /* GD is above SP */
> +       mov     r0, #0
> +       bl      board_init_f
> +
> +/*
> + * Set up intermediate environment (new sp and gd) and call
> + * relocate_code(addr_sp, gd, addr_moni). Trick here is that
> + * we'll return 'here' but relocated.
> + */
> +
> +       ldr     sp, [r8, #GD_START_ADDR_SP]     /* r8 = gd->start_addr_sp */
> +       ldr     r8, [r8, #GD_BD]                /* r8 = gd->bd */
> +       sub     r8, r8, #GD_SIZE                /* new GD is below bd */
> +
> +#if ! defined(CONFIG_SPL_BUILD)
> +
> +       adr     lr, here
> +       ldr     r0, [r8, #GD_RELOC_OFF]         /* lr = gd->start_addr_sp */
> +       add     lr, lr, r0
> +       ldr     r0, [r8, #GD_START_ADDR_SP]     /* r0 = gd->start_addr_sp */
> +       mov     r1, r8                          /* r1 = gd */
> +       ldr     r2, [r8, #GD_RELOCADDR]         /* r2 = gd->relocaddr */
> +       b       relocate_code
> +here:
> +
> +#endif
> +
> +/* Set up final (full) environment */
> +
> +       bl      c_runtime_cpu_setup     /* we still call old routine here */
> +
> +       ldr     r0, =__bss_start        /* this is auto-relocated! */
> +       ldr     r1, =__bss_end__        /* this is auto-relocated! */

I noticed this last time around - really we should have __bss_end__,
not __bss_end. Something to look at in future work, perhaps.

> +
> +       mov     r2, #0x00000000         /* prepare zero to clear BSS */
> +
> +clbss_l:cmp    r0, r1                  /* while not at end of BSS */
> +       strlo   r2, [r0]                /* clear 32-bit BSS word */
> +       addlo   r0, r0, #4              /* move to next */
> +       bhs     clbss_l

I think this should be blo, not bhs. Otherwise the BSS does not get
cleared and my seaboard doesn't boot properly.

> +
> +#if ! defined(CONFIG_SPL_BUILD)
> +
> +       bl coloured_LED_init
> +       bl red_led_on
> +
> +#endif
> +
> +#if defined(CONFIG_NAND_SPL)
> +
> +       /* call _nand_boot() */
> +       ldr     pc, _nand_boot
> +
> +#else
> +
> +       /* call board_init_r(gd_t *id, ulong dest_addr) */
> +       mov     r0, r8                  /* gd_t */
> +       ldr     r1, [r8, #GD_RELOCADDR] /* dest_addr */
> +       /* call board_init_r */
> +       ldr     pc, _board_init_r       /* this is auto-relocated! */

For my toolchain I need:

ldr     pc, =board_init_r

otherwise I get:

crt0.S: Assembler messages:
crt0.S:176: Error: internal_relocation (type: OFFSET_IMM) not fixed up

Also _board_init_r seems to be the wrong symbol name for me:

arch/arm/lib/libarm.o: In function `clbss_l':
/home/sjg/trunk/src/third_party/u-boot/files/arch/arm/lib/crt0.S:176:
undefined reference to `_board_init_r'

> +
> +#endif
> +
> +       /* we should not return here. */

[snip]

Regards,
Simon

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S
  2012-11-15 19:35       ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Simon Glass
@ 2012-11-15 22:41         ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-15 22:41 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, 15 Nov 2012 11:35:27 -0800, Simon Glass <sjg@chromium.org>
wrote:

> Hi Albert,
> 
> On Sat, Nov 10, 2012 at 9:00 AM, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> > Move all the C runtime setup code from every start.S
> > in arch/arm into arch/arm/lib/crt0.S. This covers
> > the code sequence from isetting up the initial stack
> > to calling into board_init_r().
> >
> > Also, rewrite the C runtime setup and make functions
> > board_init_*() and relocate_code() behave according to
> > normal C semantics (no jumping across the C stack any
> > more, etc).
> >
> > Some SPL targets had to be touched because they use
> > start.S exolicitly or for some reason; the relevant
> > maintainers and custodians are cc:ed.
> >
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> 
> I am very pleased to see this. My generic relocation series from some
> time ago is still hanging around. Your series tidies up some things
> which would make that series easier to do. I'm happy to take another
> look at it.

I do remember your series -- it is part of what gave me the incentive 
toput this patch series together. :)

> I have tested your series on a Tegra seaboard, and got it running with
> a few changes. Please see comments below.

> > +       ldr     r0, =__bss_start        /* this is auto-relocated! */
> > +       ldr     r1, =__bss_end__        /* this is auto-relocated! */
> 
> I noticed this last time around - really we should have __bss_end__,
> not __bss_end. Something to look at in future work, perhaps.

Noted.

> > +       bhs     clbss_l
> 
> I think this should be blo, not bhs. Otherwise the BSS does not get
> cleared and my seaboard doesn't boot properly.

Thanks -- not the first time I see these... I'll have a go at checking
all loops.

> > +       /* call board_init_r */
> > +       ldr     pc, _board_init_r       /* this is auto-relocated! */
> 
> For my toolchain I need:
> 
> ldr     pc, =board_init_r
> 
> otherwise I get:
> 
> crt0.S: Assembler messages:
> crt0.S:176: Error: internal_relocation (type: OFFSET_IMM) not fixed up

Thanks -- this could well cure errors that Tom Warren reported to me
for various toolchains.

> Also _board_init_r seems to be the wrong symbol name for me:
> 
> arch/arm/lib/libarm.o: In function `clbss_l':
> /home/sjg/trunk/src/third_party/u-boot/files/arch/arm/lib/crt0.S:176:
> undefined reference to `_board_init_r'

Thanks a lot for the feedback and analysis! This should make V4 work on
a much wider range of ARM boards.

> Regards,
> Simon

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush as possible.
  2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-10 17:28     ` [U-Boot] [PATCH v3 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
@ 2012-11-27 12:43     ` Albert ARIBAUD
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                         ` (2 more replies)
  2 siblings, 3 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-27 12:43 UTC (permalink / raw)
  To: u-boot

The goal of this series is to scrub the start.S files
which have proliferated across arch/arm and eliminate
code redundancy.

This series only factorizes the C runtime framework,
that is, the assembly code responsible for setting up
the C environments needed by board_init_*() and
relocate_code().

Further factorization is possible: relocate_code() can
be moved out and possibly rewritten in C now that it
has plain C function semantics; exception handlers
should also be pretty much cpu-independent.

Also, SPL currently makes board_init_f() perform all
of the setting up, including BSS clearing and chain-
loading. This could be streamlined by only putting
basic inits in board_init_f(), letting crt0 do the
BSS initialization and chain-loading U-Boot from
inside board_init_r().

Eventually, start.S files should disappear or contain
CPU-specific code only.

The new C runtime setup sequence has been validated step by
step on targets versatileqemu using gcc version 4.2.2 from
the ELDK4.2 toolchain, and wireless_space using gcc version
4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1).

The whole changes have been build-tested across all ARM
targets using MAKEALL -a arm.

Changes in v4:
- fixed bhs into blo in BSS init loop
- switched from explicit literals to '=target' notation
- fixed location of GD in initial environment
- stopped SPL boot sequence at calling board_init_f

Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case

Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
- removed useless includes in arm926ejs and arm925t

Albert ARIBAUD (2):
  arm: move C runtime setup code in crt0.S
  arm: remove useless code in start.S files

 arch/arm/cpu/arm1136/start.S              |   71 +++---------
 arch/arm/cpu/arm1176/start.S              |   62 ++---------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   65 ++---------
 arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
 arch/arm/cpu/arm946es/start.S             |   56 ++--------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++---------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++-------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 322 insertions(+), 688 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
@ 2012-11-27 12:43       ` Albert ARIBAUD
  2012-11-27 12:43         ` [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files Albert ARIBAUD
                           ` (5 more replies)
  2012-12-27 11:27       ` [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush " Albert ARIBAUD
  2013-01-08 17:20       ` Albert ARIBAUD
  2 siblings, 6 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-27 12:43 UTC (permalink / raw)
  To: u-boot

Move all the C runtime setup code from every start.S
in arch/arm into arch/arm/lib/crt0.S. This covers
the code sequence from setting up the initial stack
to calling into board_init_r().

Also, rewrite the C runtime setup and make functions
board_init_*() and relocate_code() behave according to
normal C semantics (no jumping across the C stack any
more, etc).

Some SPL targets had to be touched because they use
start.S explicitly or for some reason; the relevant
maintainers and custodians are cc:ed.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4:
- fixed bhs into blo in BSS init loop
- switched from explicit literals to '=target' notation
- fixed location of GD in initial environment
- stopped SPL boot sequence at calling board_init_f

Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case

Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

 arch/arm/cpu/arm1136/start.S              |   71 +++---------
 arch/arm/cpu/arm1176/start.S              |   62 ++---------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++--------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++---------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++-------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   10 ++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 322 insertions(+), 678 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 5d3b4c2..a067b8a 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -165,13 +165,7 @@ next:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -188,14 +182,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -245,7 +235,15 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+	bx	lr
+
+#endif
+
+relocate_done:
+
+	bx	lr
+
+#ifndef CONFIG_SPL_BUILD
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,54 +251,13 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
-#endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
 #endif
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 /*
  *************************************************************************
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 667a0e0..40df4b1 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -224,12 +224,7 @@ skip_tcmdisable:
 	 */
 	bl	lowlevel_init		/* go setup pll,mux,memory */
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -246,14 +241,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -343,49 +334,9 @@ mmu_enable:
 skip_hw_init:
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#ifndef CONFIG_NAND_SPL
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
-
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add     lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -399,6 +350,11 @@ _mmu_table_base:
 	.word mmu_table
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 #ifndef CONFIG_NAND_SPL
 /*
  * we assume that cache operation is done before. (eg. cleanup_before_linux())
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index c2a7763..771d386 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,43 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -272,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 14c9156..511d21d 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -182,12 +182,7 @@ copyex:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -204,14 +199,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -263,51 +254,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -315,6 +265,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 3a483f6..82f5b8b 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -176,12 +176,7 @@ poll1:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -198,14 +193,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -257,51 +248,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -309,6 +259,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 2188f7e..3cdecd9 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,20 +198,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#else
-#ifdef CONFIG_SPL_BUILD
-	ldr	sp, =(CONFIG_SPL_STACK)
-#else
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#endif
-#endif
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -229,15 +216,11 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	sub	r9, r6, r0		/* r9 <- relocation offset */
 	cmp	r0, r6
-	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	moveq	r9, #0			/* no relocation. offset(r9) = 0 */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -289,56 +272,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+relocate_done:
 
-#ifndef CONFIG_SPL_BUILD
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	ldr	r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -346,8 +282,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 30e2183..a7a98a4 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,46 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
+relocate_done:
 
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -275,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index a133d19..c189849 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -143,12 +143,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -165,14 +160,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -224,50 +215,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -276,6 +226,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 7df97c5..dcc1f83 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -155,12 +155,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -177,14 +172,10 @@ ENTRY(relocate_code)
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -233,34 +224,22 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+
+relocate_done:
+
+	bx	lr
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+ENDPROC(relocate_code)
 
-clear_bss:
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+#endif
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-jump_2_ram:
+ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
  */
@@ -279,20 +258,9 @@ jump_2_ram:
 	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
 #endif /* !Tegra20 */
 
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-ENDPROC(relocate_code)
-#endif
+	bx	lr
+
+ENDPROC(c_runtime_cpu_setup)
 
 /*************************************************************************
  *
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index c12f1a7..efb5a40 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -245,12 +245,7 @@ reset:
 	orr	r0,r0,#0x13
 	msr	cpsr,r0
 
-/* Set initial stackpointer in SDRAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -267,14 +262,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -326,42 +317,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -370,6 +328,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /****************************************************************************/
 /*									    */
 /* Interrupt handling							    */
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 536cf5c..72af869 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -164,12 +164,7 @@ reset:
 	bl	lock_cache_for_stack
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0, =0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 #ifndef CONFIG_SPL_BUILD
@@ -186,10 +181,6 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 /* Disable the Dcache RAM lock for stack now */
 #ifdef	CONFIG_CPU_PXA25X
 	bl	cpu_init_crit
@@ -198,7 +189,7 @@ stack_setup:
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -250,48 +241,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_ONENAND_SPL
-	ldr     r0, _onenand_boot_ofs
-	mov	pc, r0
-
-_onenand_boot_ofs:
-	.word onenand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -299,7 +251,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
+
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 323b923..4528c91 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -128,12 +128,7 @@ reset:
 	bl	lowlevel_init
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -150,14 +145,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -209,42 +200,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,6 +211,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 1ea92d1..3144299 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -132,12 +132,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -154,14 +149,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -213,40 +204,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -254,6 +215,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..07baee2 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,6 +36,8 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+SOBJS-y += crt0.o
+
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 92cad9a..ad96d7e 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -272,11 +272,6 @@ void board_init_f(ulong bootflag)
 
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
-	/* compiler optimization barrier needed for GCC >= 3.4 */
-	__asm__ __volatile__("": : :"memory");
-
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
@@ -458,10 +453,6 @@ void board_init_f(ulong bootflag)
 		gd->fdt_blob = new_fdt;
 	}
 	memcpy(id, (void *)gd, sizeof(gd_t));
-
-	relocate_code(addr_sp, id, addr);
-
-	/* NOTREACHED - relocate_code() does not return */
 }
 
 #if !defined(CONFIG_SYS_NO_FLASH)
@@ -486,8 +477,6 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	ulong flash_size;
 #endif
 
-	gd = id;
-
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
new file mode 100644
index 0000000..4f60958
--- /dev/null
+++ b/arch/arm/lib/crt0.S
@@ -0,0 +1,173 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM U-Boot
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+
+/*
+ * This file handles the target-independent stages of the U-Boot
+ * start-up where a C runtime environment is needed. Its entry point
+ * is _main and is branched into from the target's start.S file.
+ *
+ * _main execution sequence is:
+ *
+ * 1. Set up initial environment for calling board_init_f().
+ *    This environment only provides a stack and a place to store
+ *    the GD ('global data') structure, both located in some readily
+ *    available RAM (SRAM, locked cache...). In this context, VARIABLE
+ *    global data, initialized or not (BSS), are UNAVAILABLE; only
+ *    CONSTANT initialized data are available.
+ *
+ * 2. Call board_init_f(). This function prepares the hardware for
+ *    execution from system RAM (DRAM, DDR...) As system RAM may not
+ *    be available yet, , board_init_f() must use the current GD to
+ *    store any data which must be passed on to later stages. These
+ *    data include the relocation destination, the future stack, and
+ *    the future GD location.
+ *
+ * (the following applies only to non-SPL builds)
+ *
+ * 3. Set up intermediate environment where the stack and GD are the
+ *    ones allocated by board_init_f() in system RAM, but BSS and
+ *    initialized non-const data are still not available.
+ *
+ * 4. Call relocate_code(). This function relocates U-Boot from its
+ *    current location into the relocation destination computed by
+ *    board_init_f().
+ *
+ * 5. Set up final environment for calling board_init_r(). This
+ *    environment has BSS (initialized to 0), initialized non-const
+ *    data (initialized to their intended value), and stack in system
+ *    RAM. GD has retained values set by board_init_f(). Some CPUs
+ *    have some work left to do at this point regarding memory, so
+ *    call c_runtime_cpu_setup.
+ *
+ * 6. Branch to either nand_boot() or board_init_r().
+ */
+
+/*
+ * declare nand_boot() or board_init_r() to jump to at end of crt0
+ */
+
+#if defined(CONFIG_NAND_SPL)
+
+.globl nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+.globl board_init_r
+
+#endif
+
+/*
+ * start and end of BSS
+ */
+
+.globl __bss_start
+.globl __bss_end__
+
+/*
+ * entry point of crt0 sequence
+ */
+
+.global _main
+
+_main:
+
+/*
+ * Set up initial C runtime environment and call board_init_f(0).
+ */
+
+#if defined(CONFIG_NAND_SPL)
+	/* deprecated, use instead CONFIG_SPL_BUILD */
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
+	ldr	sp, =(CONFIG_SPL_STACK)
+#else
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#endif
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	sub	sp, #GD_SIZE	/* allocate one GD above SP */
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	mov	r8, sp		/* GD is above SP */
+	mov	r0, #0
+	bl	board_init_f
+
+#if ! defined(CONFIG_SPL_BUILD)
+
+/*
+ * Set up intermediate environment (new sp and gd) and call
+ * relocate_code(addr_sp, gd, addr_moni). Trick here is that
+ * we'll return 'here' but relocated.
+ */
+
+	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
+	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
+
+	adr	lr, here
+	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
+	add	lr, lr, r0
+	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
+	mov	r1, r8				/* r1 = gd */
+	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
+	b	relocate_code
+here:
+
+/* Set up final (full) environment */
+
+	bl	c_runtime_cpu_setup	/* we still call old routine here */
+
+	ldr	r0, =__bss_start	/* this is auto-relocated! */
+	ldr	r1, =__bss_end__	/* this is auto-relocated! */
+
+	mov	r2, #0x00000000		/* prepare zero to clear BSS */
+
+clbss_l:cmp	r0, r1			/* while not at end of BSS */
+	strlo	r2, [r0]		/* clear 32-bit BSS word */
+	addlo	r0, r0, #4		/* move to next */
+	blo	clbss_l
+
+	bl coloured_LED_init
+	bl red_led_on
+
+#if defined(CONFIG_NAND_SPL)
+
+	/* call _nand_boot() */
+	ldr     pc, =nand_boot
+
+#else
+
+	/* call board_init_r(gd_t *id, ulong dest_addr) */
+	mov	r0, r8			/* gd_t */
+	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
+	/* call board_init_r */
+	ldr	pc, =board_init_r	/* this is auto-relocated! */
+
+#endif
+
+	/* we should not return here. */
+
+#endif
diff --git a/include/common.h b/include/common.h
index 5e3c5ee..69a1ccd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -300,7 +300,7 @@ int	abortboot(int bootdelay);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
-void	board_init_f  (ulong) __attribute__ ((noreturn));
+void	board_init_f(ulong);
 void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
 int	checkboard    (void);
 int	checkflash    (void);
diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h
index 42077bd..5633d2a 100644
--- a/include/configs/socfpga_cyclone5.h
+++ b/include/configs/socfpga_cyclone5.h
@@ -65,7 +65,7 @@
 #define CONFIG_SYS_BOOTMAPSZ		((256*1024*1024) - (4*1024))
 
 #define CONFIG_SPL_RAM_DEVICE
-#define CONFIG_SPL_STACK (&__stack_start)
+#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
 #define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
 #define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
 
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c88f5d4..764e27b 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,5 +28,15 @@ int main(void)
 	DEFINE(GENERATED_BD_INFO_SIZE,
 		(sizeof(struct bd_info) + 15) & ~15);
 
+	DEFINE(GD_SIZE, sizeof(struct global_data));
+
+	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+	DEFINE(GD_RELOCADDR, offsetof(struct global_data, relocaddr));
+
+	DEFINE(GD_RELOC_OFF, offsetof(struct global_data, reloc_off));
+
+	DEFINE(GD_START_ADDR_SP, offsetof(struct global_data, start_addr_sp));
+
 	return 0;
 }
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index 43e72c4..2793aef 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -12,11 +12,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm1136/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/freescale/mx31pdk/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -49,6 +50,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm1136/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index becf7fa..825f06d 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -33,11 +33,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm926ejs/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/karo/tx25/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -70,6 +71,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm926ejs/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-11-27 12:43         ` Albert ARIBAUD
  2013-01-07 14:41           ` Tom Rini
  2012-11-28 21:18         ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Simon Glass
                           ` (4 subsequent siblings)
  5 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-27 12:43 UTC (permalink / raw)
  To: u-boot

Remove code such as unneeded includes or labels.
These removals have no functional effect.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- removed useless includes in arm926ejs and arm925t

 arch/arm/cpu/arm925t/start.S   |    4 ----
 arch/arm/cpu/arm926ejs/start.S |    6 ------
 2 files changed, 10 deletions(-)

diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 82f5b8b..e8d6d71 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -34,10 +34,6 @@
 #include <config.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1510)
-#include <./configs/omap1510.h>
-#endif
-
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 3cdecd9..66a8b65 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -36,12 +36,6 @@
 #include <common.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1610)
-#include <./configs/omap1510.h>
-#elif defined(CONFIG_OMAP730)
-#include <./configs/omap730.h>
-#endif
-
 /*
  *************************************************************************
  *
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-27 12:43         ` [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files Albert ARIBAUD
@ 2012-11-28 21:18         ` Simon Glass
  2012-11-28 22:34           ` Albert ARIBAUD
  2012-12-09 20:33         ` Sughosh Ganu
                           ` (3 subsequent siblings)
  5 siblings, 1 reply; 47+ messages in thread
From: Simon Glass @ 2012-11-28 21:18 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tue, Nov 27, 2012 at 4:43 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from setting up the initial stack
> to calling into board_init_r().
>
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
>
> Some SPL targets had to be touched because they use
> start.S explicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
>
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

I tested this on Seaboard (Tegra 20).

Tested-by: Simon Glass <sjg@chromium.org>

I tried to test it on a snow (exynos5250) but couldn't really sync up
with our tree, so gave up. I am not completely sure about how the
CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
undefined reference to `relocate_done')

Regards,
Simon

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-28 21:18         ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Simon Glass
@ 2012-11-28 22:34           ` Albert ARIBAUD
  2012-11-30 22:10             ` Simon Glass
  0 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-11-28 22:34 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Wed, 28 Nov 2012 13:18:57 -0800, Simon Glass <sjg@chromium.org>
wrote:

> Hi Albert,
> 
> On Tue, Nov 27, 2012 at 4:43 AM, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> > Move all the C runtime setup code from every start.S
> > in arch/arm into arch/arm/lib/crt0.S. This covers
> > the code sequence from setting up the initial stack
> > to calling into board_init_r().
> >
> > Also, rewrite the C runtime setup and make functions
> > board_init_*() and relocate_code() behave according to
> > normal C semantics (no jumping across the C stack any
> > more, etc).
> >
> > Some SPL targets had to be touched because they use
> > start.S explicitly or for some reason; the relevant
> > maintainers and custodians are cc:ed.
> >
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> 
> I tested this on Seaboard (Tegra 20).
> 
> Tested-by: Simon Glass <sjg@chromium.org>
> 
> I tried to test it on a snow (exynos5250) but couldn't really sync up
> with our tree, so gave up. I am not completely sure about how the
> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
> undefined reference to `relocate_done')

Thansk Simon.

In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and
line 228 provides it, and there is no preprocessor conditional
in-between, so I fail to see how you could get this error.

Is your tree (and branch) available so that I can try and see the issue
for myself? Either it'll uncover a problem in my patch series, or it'll
help you merge it (or both).

> Regards,
> Simon

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-28 22:34           ` Albert ARIBAUD
@ 2012-11-30 22:10             ` Simon Glass
  2012-12-23 15:03               ` Albert ARIBAUD
  0 siblings, 1 reply; 47+ messages in thread
From: Simon Glass @ 2012-11-30 22:10 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Wed, Nov 28, 2012 at 2:34 PM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> Hi Simon,
>
> On Wed, 28 Nov 2012 13:18:57 -0800, Simon Glass <sjg@chromium.org>
> wrote:
>
>> Hi Albert,
>>
>> On Tue, Nov 27, 2012 at 4:43 AM, Albert ARIBAUD
>> <albert.u.boot@aribaud.net> wrote:
>> > Move all the C runtime setup code from every start.S
>> > in arch/arm into arch/arm/lib/crt0.S. This covers
>> > the code sequence from setting up the initial stack
>> > to calling into board_init_r().
>> >
>> > Also, rewrite the C runtime setup and make functions
>> > board_init_*() and relocate_code() behave according to
>> > normal C semantics (no jumping across the C stack any
>> > more, etc).
>> >
>> > Some SPL targets had to be touched because they use
>> > start.S explicitly or for some reason; the relevant
>> > maintainers and custodians are cc:ed.
>> >
>> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
>>
>> I tested this on Seaboard (Tegra 20).
>>
>> Tested-by: Simon Glass <sjg@chromium.org>
>>
>> I tried to test it on a snow (exynos5250) but couldn't really sync up
>> with our tree, so gave up. I am not completely sure about how the
>> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
>> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
>> undefined reference to `relocate_done')
>
> Thansk Simon.
>
> In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and
> line 228 provides it, and there is no preprocessor conditional
> in-between, so I fail to see how you could get this error.
>
> Is your tree (and branch) available so that I can try and see the issue
> for myself? Either it'll uncover a problem in my patch series, or it'll
> help you merge it (or both).

OK I will try a bit harder and come back to you. Sorry I can't do that
immediately but will be soon...

Regards,
Simon

>
>> Regards,
>> Simon
>
> Amicalement,
> --
> Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible.
  2012-11-13 19:55               ` Albert ARIBAUD
@ 2012-12-09 20:31                 ` Sughosh Ganu
  0 siblings, 0 replies; 47+ messages in thread
From: Sughosh Ganu @ 2012-12-09 20:31 UTC (permalink / raw)
  To: u-boot

hi Albert,
On Tue Nov 13, 2012 at 08:55:23PM +0100, Albert ARIBAUD wrote:

<snip>

> > > > I tried the 1st patch of the series, and with that u-boot does not
> > > > come up on the board. It is also printing out some random values for
> > > > the dram and nand sizes.
> > > >
> > > > The patch was applied on top of commit 1cc619be8b7. Also, with the
> > > > mentioned commit, u-boot boots up fine on the board. Also to be noted
> > > > is that the spl image compiled with these changes is booting up fine,
> > > > loading the main u-boot image, and jumping to it -- the issue is with
> > > > booting the main u-boot image.
> > >
> > > Thanks Sughosh. Can you build an U-Boot with the following defined
> > > in the hawkboard.h config file?
> > >
> > > #define DEBUG
> > > #if defined(CONFIG_SPL_BUILD) && ! defined (__ASSEMBLY__)
> > > static inline int printf(const char *fmt, ...)
> > > {
> > >         return 0;
> > > }
> > > #endif
> > >
> > > Note: only the #define DEBUG matter to me, but with it alone, SPL build
> > > fails due to some code now requiring printf(). This is why I add a
> > > dummy printf definition for C code during SPL build -- ASM code does not
> > > need printf() and actually chokes on the definition, hence the
> > > condition on __ASSEMBLY__.
> > >
> > > This debug U-Boot should print a lot more info. Can you please try it
> > > and copy/paste its output here? Thanks in advance.
> > >
> > 
> > Unfortunately i am currently on vacation, with no access to the board, and
> > would be able to try out your suggested changes only after   i am back, by
> > the end of next week. In the meantime, i am also trying to get myself a
> > jtag debugger -- it is quite frustrating to provide half baked information.
> > 
> Thanks for the feedback. Meanwhile, I have found two ugly bugs which
> would certainly affect execution past board_init_f(), so maybe your
> hawkboard was bitten by theses; next time please try v3, which fixes
> these bugs, or the latest patch version if v3 is obsolete by the time
> you come back.

I tested the v4 of your patches on hawkboard, and now the board boots
up fine. Sorry, i took a little longer than i had expected to be back,
so this got a bit delayed.

-sughosh

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-11-27 12:43         ` [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files Albert ARIBAUD
  2012-11-28 21:18         ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Simon Glass
@ 2012-12-09 20:33         ` Sughosh Ganu
  2013-01-07 14:40         ` Tom Rini
                           ` (2 subsequent siblings)
  5 siblings, 0 replies; 47+ messages in thread
From: Sughosh Ganu @ 2012-12-09 20:33 UTC (permalink / raw)
  To: u-boot

On Tue Nov 27, 2012 at 01:43:25PM +0100, Albert ARIBAUD wrote:
> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from setting up the initial stack
> to calling into board_init_r().
> 
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
> 
> Some SPL targets had to be touched because they use
> start.S explicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---

Tested on hawkboard. Spl and u-boot images boot up fine with these
changes.

Tested-by: Sughosh Ganu <urwithsughosh@gmail.com>

-sughosh

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-30 22:10             ` Simon Glass
@ 2012-12-23 15:03               ` Albert ARIBAUD
  2012-12-26 20:41                 ` Simon Glass
  0 siblings, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2012-12-23 15:03 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Fri, 30 Nov 2012 14:10:01 -0800, Simon Glass <sjg@chromium.org>
wrote:

> >> I tried to test it on a snow (exynos5250) but couldn't really sync up
> >> with our tree, so gave up. I am not completely sure about how the
> >> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
> >> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
> >> undefined reference to `relocate_done')
> >
> > Thansk Simon.
> >
> > In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and
> > line 228 provides it, and there is no preprocessor conditional
> > in-between, so I fail to see how you could get this error.
> >
> > Is your tree (and branch) available so that I can try and see the issue
> > for myself? Either it'll uncover a problem in my patch series, or it'll
> > help you merge it (or both).
> 
> OK I will try a bit harder and come back to you. Sorry I can't do that
> immediately but will be soon...

Did you manage to reproduce or sort out this issue?

> Regards,
> Simon

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-12-23 15:03               ` Albert ARIBAUD
@ 2012-12-26 20:41                 ` Simon Glass
  2013-01-05  1:00                   ` Simon Glass
  0 siblings, 1 reply; 47+ messages in thread
From: Simon Glass @ 2012-12-26 20:41 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Sun, Dec 23, 2012 at 7:03 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> Hi Simon,
>
> On Fri, 30 Nov 2012 14:10:01 -0800, Simon Glass <sjg@chromium.org>
> wrote:
>
>> >> I tried to test it on a snow (exynos5250) but couldn't really sync up
>> >> with our tree, so gave up. I am not completely sure about how the
>> >> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
>> >> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
>> >> undefined reference to `relocate_done')
>> >
>> > Thansk Simon.
>> >
>> > In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and
>> > line 228 provides it, and there is no preprocessor conditional
>> > in-between, so I fail to see how you could get this error.
>> >
>> > Is your tree (and branch) available so that I can try and see the issue
>> > for myself? Either it'll uncover a problem in my patch series, or it'll
>> > help you merge it (or both).
>>
>> OK I will try a bit harder and come back to you. Sorry I can't do that
>> immediately but will be soon...
>
> Did you manage to reproduce or sort out this issue?

No, I was hoping that I would be able to test upstream U-Boot on snow
(waiting on some memory patches to appear), but that hasn't happened.
I will have another go at working out the problem - either this week
or next depending on when I can set aside the time for it. However,
please don't hold up the series for it.

>
>> Regards,
>> Simon
>
> Amicalement,
> --
> Albert.

Regards,
Simon

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush as possible.
  2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2012-12-27 11:27       ` Albert ARIBAUD
  2013-01-08 17:20       ` Albert ARIBAUD
  2 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2012-12-27 11:27 UTC (permalink / raw)
  To: u-boot

On Tue, 27 Nov 2012 13:43:24 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> The goal of this series is to scrub the start.S files
> which have proliferated across arch/arm and eliminate
> code redundancy.
> 
> This series only factorizes the C runtime framework,
> that is, the assembly code responsible for setting up
> the C environments needed by board_init_*() and
> relocate_code().
> 
> Further factorization is possible: relocate_code() can
> be moved out and possibly rewritten in C now that it
> has plain C function semantics; exception handlers
> should also be pretty much cpu-independent.
> 
> Also, SPL currently makes board_init_f() perform all
> of the setting up, including BSS clearing and chain-
> loading. This could be streamlined by only putting
> basic inits in board_init_f(), letting crt0 do the
> BSS initialization and chain-loading U-Boot from
> inside board_init_r().
> 
> Eventually, start.S files should disappear or contain
> CPU-specific code only.
> 
> The new C runtime setup sequence has been validated step by
> step on targets versatileqemu using gcc version 4.2.2 from
> the ELDK4.2 toolchain, and wireless_space using gcc version
> 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1).
> 
> The whole changes have been build-tested across all ARM
> targets using MAKEALL -a arm.
> 
> Changes in v4:
> - fixed bhs into blo in BSS init loop
> - switched from explicit literals to '=target' notation
> - fixed location of GD in initial environment
> - stopped SPL boot sequence at calling board_init_f
> 
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case
> 
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
> - removed useless includes in arm926ejs and arm925t
> 
> Albert ARIBAUD (2):
>   arm: move C runtime setup code in crt0.S
>   arm: remove useless code in start.S files
> 
>  arch/arm/cpu/arm1136/start.S              |   71 +++---------
>  arch/arm/cpu/arm1176/start.S              |   62 ++---------
>  arch/arm/cpu/arm720t/start.S              |   53 ++-------
>  arch/arm/cpu/arm920t/start.S              |   61 ++--------
>  arch/arm/cpu/arm925t/start.S              |   65 ++---------
>  arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
>  arch/arm/cpu/arm946es/start.S             |   56 ++--------
>  arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
>  arch/arm/cpu/armv7/start.S                |   58 +++-------
>  arch/arm/cpu/ixp/start.S                  |   55 ++-------
>  arch/arm/cpu/pxa/start.S                  |   63 ++---------
>  arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
>  arch/arm/cpu/sa1100/start.S               |   50 ++-------
>  arch/arm/lib/Makefile                     |    2 +
>  arch/arm/lib/board.c                      |   11 --
>  arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
>  include/common.h                          |    2 +-
>  include/configs/socfpga_cyclone5.h        |    2 +-
>  lib/asm-offsets.c                         |   10 ++
>  nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
>  nand_spl/board/karo/tx25/Makefile         |    6 +-
>  21 files changed, 322 insertions(+), 688 deletions(-)
>  create mode 100644 arch/arm/lib/crt0.S
> 
> -- 
> 1.7.10.4

Tom,

These have been tested on several boards. Can it go in? If it can,
then I would like to take it in u-boot-arm/master with your Acked-By.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-12-26 20:41                 ` Simon Glass
@ 2013-01-05  1:00                   ` Simon Glass
  0 siblings, 0 replies; 47+ messages in thread
From: Simon Glass @ 2013-01-05  1:00 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Wed, Dec 26, 2012 at 12:41 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Albert,
>
> On Sun, Dec 23, 2012 at 7:03 AM, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
>> Hi Simon,
>>
>> On Fri, 30 Nov 2012 14:10:01 -0800, Simon Glass <sjg@chromium.org>
>> wrote:
>>
>>> >> I tried to test it on a snow (exynos5250) but couldn't really sync up
>>> >> with our tree, so gave up. I am not completely sure about how the
>>> >> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build
>>> >> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179:
>>> >> undefined reference to `relocate_done')
>>> >
>>> > Thansk Simon.
>>> >
>>> > In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and
>>> > line 228 provides it, and there is no preprocessor conditional
>>> > in-between, so I fail to see how you could get this error.
>>> >
>>> > Is your tree (and branch) available so that I can try and see the issue
>>> > for myself? Either it'll uncover a problem in my patch series, or it'll
>>> > help you merge it (or both).
>>>
>>> OK I will try a bit harder and come back to you. Sorry I can't do that
>>> immediately but will be soon...
>>
>> Did you manage to reproduce or sort out this issue?
>
> No, I was hoping that I would be able to test upstream U-Boot on snow
> (waiting on some memory patches to appear), but that hasn't happened.
> I will have another go at working out the problem - either this week
> or next depending on when I can set aside the time for it. However,
> please don't hold up the series for it.

I have tested this on snow at last. My problem was basically the
distance between our tree and upstream - we are just coming up to a
rebase so are at the furthest point.

Tested-by: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>

>
>>
>>> Regards,
>>> Simon
>>
>> Amicalement,
>> --
>> Albert.
>
> Regards,
> Simon

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                           ` (2 preceding siblings ...)
  2012-12-09 20:33         ` Sughosh Ganu
@ 2013-01-07 14:40         ` Tom Rini
  2013-01-08 19:26         ` Tom Rini
  2013-01-08 20:18         ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
  5 siblings, 0 replies; 47+ messages in thread
From: Tom Rini @ 2013-01-07 14:40 UTC (permalink / raw)
  To: u-boot

On Tue, Nov 27, 2012 at 01:43:25PM +0100, Albert ARIBAUD wrote:

> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from setting up the initial stack
> to calling into board_init_r().
> 
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
> 
> Some SPL targets had to be touched because they use
> start.S explicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

On beaglebone Rev A5
Tested-by: Tom Rini <trini@ti.com>
Acked-by: Tom Rini <trini@ti.com>

-- 
Tom

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files
  2012-11-27 12:43         ` [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files Albert ARIBAUD
@ 2013-01-07 14:41           ` Tom Rini
  0 siblings, 0 replies; 47+ messages in thread
From: Tom Rini @ 2013-01-07 14:41 UTC (permalink / raw)
  To: u-boot

On Tue, Nov 27, 2012 at 01:43:26PM +0100, Albert ARIBAUD wrote:

> Remove code such as unneeded includes or labels.
> These removals have no functional effect.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - removed useless includes in arm926ejs and arm925t

On beaglebone Rev A5
Tested-by: Tom Rini <trini@ti.com>
Acked-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130107/830ae3df/attachment.pgp>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush as possible.
  2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2012-12-27 11:27       ` [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush " Albert ARIBAUD
@ 2013-01-08 17:20       ` Albert ARIBAUD
  2 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 17:20 UTC (permalink / raw)
  To: u-boot

On Tue, 27 Nov 2012 13:43:24 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> The goal of this series is to scrub the start.S files
> which have proliferated across arch/arm and eliminate
> code redundancy.
> 
> This series only factorizes the C runtime framework,
> that is, the assembly code responsible for setting up
> the C environments needed by board_init_*() and
> relocate_code().
> 
> Further factorization is possible: relocate_code() can
> be moved out and possibly rewritten in C now that it
> has plain C function semantics; exception handlers
> should also be pretty much cpu-independent.
> 
> Also, SPL currently makes board_init_f() perform all
> of the setting up, including BSS clearing and chain-
> loading. This could be streamlined by only putting
> basic inits in board_init_f(), letting crt0 do the
> BSS initialization and chain-loading U-Boot from
> inside board_init_r().
> 
> Eventually, start.S files should disappear or contain
> CPU-specific code only.
> 
> The new C runtime setup sequence has been validated step by
> step on targets versatileqemu using gcc version 4.2.2 from
> the ELDK4.2 toolchain, and wireless_space using gcc version
> 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1).
> 
> The whole changes have been build-tested across all ARM
> targets using MAKEALL -a arm.
> 
> Changes in v4:
> - fixed bhs into blo in BSS init loop
> - switched from explicit literals to '=target' notation
> - fixed location of GD in initial environment
> - stopped SPL boot sequence at calling board_init_f
> 
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case
> 
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
> - removed useless includes in arm926ejs and arm925t
> 
> Albert ARIBAUD (2):
>   arm: move C runtime setup code in crt0.S
>   arm: remove useless code in start.S files
> 
>  arch/arm/cpu/arm1136/start.S              |   71 +++---------
>  arch/arm/cpu/arm1176/start.S              |   62 ++---------
>  arch/arm/cpu/arm720t/start.S              |   53 ++-------
>  arch/arm/cpu/arm920t/start.S              |   61 ++--------
>  arch/arm/cpu/arm925t/start.S              |   65 ++---------
>  arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
>  arch/arm/cpu/arm946es/start.S             |   56 ++--------
>  arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
>  arch/arm/cpu/armv7/start.S                |   58 +++-------
>  arch/arm/cpu/ixp/start.S                  |   55 ++-------
>  arch/arm/cpu/pxa/start.S                  |   63 ++---------
>  arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
>  arch/arm/cpu/sa1100/start.S               |   50 ++-------
>  arch/arm/lib/Makefile                     |    2 +
>  arch/arm/lib/board.c                      |   11 --
>  arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
>  include/common.h                          |    2 +-
>  include/configs/socfpga_cyclone5.h        |    2 +-
>  lib/asm-offsets.c                         |   10 ++
>  nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
>  nand_spl/board/karo/tx25/Makefile         |    6 +-
>  21 files changed, 322 insertions(+), 688 deletions(-)
>  create mode 100644 arch/arm/lib/crt0.S
> 

Applied to u-boot-arm/master.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                           ` (3 preceding siblings ...)
  2013-01-07 14:40         ` Tom Rini
@ 2013-01-08 19:26         ` Tom Rini
  2013-01-08 19:50           ` Albert ARIBAUD
  2013-01-08 20:18         ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
  5 siblings, 1 reply; 47+ messages in thread
From: Tom Rini @ 2013-01-08 19:26 UTC (permalink / raw)
  To: u-boot

On Tue, Nov 27, 2012 at 01:43:25PM +0100, Albert ARIBAUD wrote:

> Move all the C runtime setup code from every start.S
> in arch/arm into arch/arm/lib/crt0.S. This covers
> the code sequence from setting up the initial stack
> to calling into board_init_r().
> 
> Also, rewrite the C runtime setup and make functions
> board_init_*() and relocate_code() behave according to
> normal C semantics (no jumping across the C stack any
> more, etc).
> 
> Some SPL targets had to be touched because they use
> start.S explicitly or for some reason; the relevant
> maintainers and custodians are cc:ed.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v4:
> - fixed bhs into blo in BSS init loop
> - switched from explicit literals to '=target' notation
> - fixed location of GD in initial environment
> - stopped SPL boot sequence at calling board_init_f
> 
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case
> 
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

This change breaks sandbox, powerpc, mips and m68k.  I suspect fixing
sandbox will be the easiest test-case and catch all of the others.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130108/e9d871df/attachment.pgp>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
  2013-01-08 19:26         ` Tom Rini
@ 2013-01-08 19:50           ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 19:50 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On Tue, 8 Jan 2013 12:26:07 -0700, Tom Rini <trini@ti.com> wrote:
> On Tue, Nov 27, 2012 at 01:43:25PM +0100, Albert ARIBAUD wrote:
> 
> > Move all the C runtime setup code from every start.S
> > in arch/arm into arch/arm/lib/crt0.S. This covers
> > the code sequence from setting up the initial stack
> > to calling into board_init_r().
> > 
> > Also, rewrite the C runtime setup and make functions
> > board_init_*() and relocate_code() behave according to
> > normal C semantics (no jumping across the C stack any
> > more, etc).
> > 
> > Some SPL targets had to be touched because they use
> > start.S explicitly or for some reason; the relevant
> > maintainers and custodians are cc:ed.
> > 
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > ---
> > Changes in v4:
> > - fixed bhs into blo in BSS init loop
> > - switched from explicit literals to '=target' notation
> > - fixed location of GD in initial environment
> > - stopped SPL boot sequence at calling board_init_f
> > 
> > Changes in v3:
> > - various clarifications and typo fixes
> > - fixed wrong LED calls conditional
> > - fixed open comment eating some code
> > - fixed code overrun in SPL case
> > 
> > Changes in v2:
> > - moved description from cover letter to patch commit msg
> > - added note about tests in the cover letter
> > - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
> 
> This change breaks sandbox, powerpc, mips and m68k.  I suspect fixing
> sandbox will be the easiest test-case and catch all of the others.
> 
> -- 
> Tom

Ok, then, rolling back ARM and pushing v5 to fix breakage on non-ARM
arches.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible.
  2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
                           ` (4 preceding siblings ...)
  2013-01-08 19:26         ` Tom Rini
@ 2013-01-08 20:18         ` Albert ARIBAUD
  2013-01-08 20:18           ` [U-Boot] [PATCH v5 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
  2013-01-08 21:16           ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
  5 siblings, 2 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 20:18 UTC (permalink / raw)
  To: u-boot

The goal of this series is to scrub the start.S files
which have proliferated across arch/arm and eliminate
code redundancy.

This series only factorizes the C runtime framework,
that is, the assembly code responsible for setting up
the C environments needed by board_init_*() and
relocate_code().

Further factorization is possible: relocate_code() can
be moved out and possibly rewritten in C now that it
has plain C function semantics; exception handlers
should also be pretty much cpu-independent.

Also, SPL currently makes board_init_f() perform all
of the setting up, including BSS clearing and chain-
loading. This could be streamlined by only putting
basic inits in board_init_f(), letting crt0 do the
BSS initialization and chain-loading U-Boot from
inside board_init_r().

Eventually, start.S files should disappear or contain
CPU-specific code only.

The new C runtime setup sequence has been validated step by
step on targets versatileqemu using gcc version 4.2.2 from
the ELDK4.2 toolchain, and wireless_space using gcc version
4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1).

The whole changes have been build-tested across all ARM
targets using MAKEALL -a arm.

Changes in v5:
- Fixed build on non-ARM architectures

Changes in v4:
- fixed bhs into blo in BSS init loop
- switched from explicit literals to '=target' notation
- fixed location of GD in initial environment
- stopped SPL boot sequence at calling board_init_f

Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case

Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
- removed useless includes in arm926ejs and arm925t

Albert ARIBAUD (2):
  arm: move C runtime setup code in crt0.S
  arm: remove useless code in start.S files

 arch/arm/cpu/arm1136/start.S              |   71 +++---------
 arch/arm/cpu/arm1176/start.S              |   62 ++---------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   65 ++---------
 arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
 arch/arm/cpu/arm946es/start.S             |   56 ++--------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++---------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++-------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   14 +++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 326 insertions(+), 688 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v5 1/2] arm: move C runtime setup code in crt0.S
  2013-01-08 20:18         ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
@ 2013-01-08 20:18           ` Albert ARIBAUD
  2013-01-08 20:18             ` [U-Boot] [PATCH v5 2/2] arm: remove useless code in start.S files Albert ARIBAUD
  2013-01-08 21:16           ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
  1 sibling, 1 reply; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 20:18 UTC (permalink / raw)
  To: u-boot

Move all the C runtime setup code from every start.S
in arch/arm into arch/arm/lib/crt0.S. This covers
the code sequence from setting up the initial stack
to calling into board_init_r().

Also, rewrite the C runtime setup and make functions
board_init_*() and relocate_code() behave according to
normal C semantics (no jumping across the C stack any
more, etc).

Some SPL targets had to be touched because they use
start.S explicitly or for some reason; the relevant
maintainers and custodians are cc:ed.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v5:
- Fixed build on non-ARM architectures

Changes in v4:
- fixed bhs into blo in BSS init loop
- switched from explicit literals to '=target' notation
- fixed location of GD in initial environment
- stopped SPL boot sequence at calling board_init_f

Changes in v3:
- various clarifications and typo fixes
- fixed wrong LED calls conditional
- fixed open comment eating some code
- fixed code overrun in SPL case

Changes in v2:
- moved description from cover letter to patch commit msg
- added note about tests in the cover letter
- fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK

 arch/arm/cpu/arm1136/start.S              |   71 +++---------
 arch/arm/cpu/arm1176/start.S              |   62 ++---------
 arch/arm/cpu/arm720t/start.S              |   53 ++-------
 arch/arm/cpu/arm920t/start.S              |   61 ++--------
 arch/arm/cpu/arm925t/start.S              |   61 ++--------
 arch/arm/cpu/arm926ejs/start.S            |   80 ++-----------
 arch/arm/cpu/arm946es/start.S             |   56 ++--------
 arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
 arch/arm/cpu/armv7/start.S                |   58 +++-------
 arch/arm/cpu/ixp/start.S                  |   55 ++-------
 arch/arm/cpu/pxa/start.S                  |   63 ++---------
 arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
 arch/arm/cpu/sa1100/start.S               |   50 ++-------
 arch/arm/lib/Makefile                     |    2 +
 arch/arm/lib/board.c                      |   11 --
 arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
 include/common.h                          |    2 +-
 include/configs/socfpga_cyclone5.h        |    2 +-
 lib/asm-offsets.c                         |   14 +++
 nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
 nand_spl/board/karo/tx25/Makefile         |    6 +-
 21 files changed, 326 insertions(+), 678 deletions(-)
 create mode 100644 arch/arm/lib/crt0.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 5d3b4c2..a067b8a 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -165,13 +165,7 @@ next:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -188,14 +182,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -245,7 +235,15 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+	bx	lr
+
+#endif
+
+relocate_done:
+
+	bx	lr
+
+#ifndef CONFIG_SPL_BUILD
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,54 +251,13 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
-#endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
 #endif
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 /*
  *************************************************************************
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 667a0e0..40df4b1 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -224,12 +224,7 @@ skip_tcmdisable:
 	 */
 	bl	lowlevel_init		/* go setup pll,mux,memory */
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -246,14 +241,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -343,49 +334,9 @@ mmu_enable:
 skip_hw_init:
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#ifndef CONFIG_NAND_SPL
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
-
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add     lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -399,6 +350,11 @@ _mmu_table_base:
 	.word mmu_table
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 #ifndef CONFIG_NAND_SPL
 /*
  * we assume that cache operation is done before. (eg. cleanup_before_linux())
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index c2a7763..771d386 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,43 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -272,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 14c9156..511d21d 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -182,12 +182,7 @@ copyex:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -204,14 +199,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -263,51 +254,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -315,6 +265,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 3a483f6..82f5b8b 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -176,12 +176,7 @@ poll1:
 	bl  cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -198,14 +193,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -257,51 +248,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
+relocate_done:
 
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -309,6 +259,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 2188f7e..3cdecd9 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,20 +198,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-#ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#else
-#ifdef CONFIG_SPL_BUILD
-	ldr	sp, =(CONFIG_SPL_STACK)
-#else
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-#endif
-#endif
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -229,15 +216,11 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	sub	r9, r6, r0		/* r9 <- relocation offset */
 	cmp	r0, r6
-	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	moveq	r9, #0			/* no relocation. offset(r9) = 0 */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -289,56 +272,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifdef CONFIG_SPL_BUILD
-	/* No relocation for SPL */
-	ldr	r0, =__bss_start
-	ldr	r1, =__bss_end__
-#else
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-#endif
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+relocate_done:
 
-#ifndef CONFIG_SPL_BUILD
-	bl coloured_LED_init
-	bl red_led_on
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	ldr	r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -346,8 +282,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 30e2183..a7a98a4 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -147,12 +147,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -169,14 +164,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -228,46 +219,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
-
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     pc, _nand_boot
+relocate_done:
 
-_nand_boot: .word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -275,6 +230,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index a133d19..c189849 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -143,12 +143,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -165,14 +160,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -224,50 +215,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_NAND_SPL
-	ldr     r0, _nand_boot_ofs
-	mov	pc, r0
-
-_nand_boot_ofs:
-	.word nand_boot
-#else
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -276,6 +226,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 7df97c5..dcc1f83 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -155,12 +155,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -177,14 +172,10 @@ ENTRY(relocate_code)
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _image_copy_end_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -233,34 +224,22 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-	b	clear_bss
+
+relocate_done:
+
+	bx	lr
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+ENDPROC(relocate_code)
 
-clear_bss:
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
+#endif
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-jump_2_ram:
+ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
  */
@@ -279,20 +258,9 @@ jump_2_ram:
 	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
 #endif /* !Tegra20 */
 
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-ENDPROC(relocate_code)
-#endif
+	bx	lr
+
+ENDPROC(c_runtime_cpu_setup)
 
 /*************************************************************************
  *
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index c12f1a7..efb5a40 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -245,12 +245,7 @@ reset:
 	orr	r0,r0,#0x13
 	msr	cpsr,r0
 
-/* Set initial stackpointer in SDRAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -267,14 +262,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -326,42 +317,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -370,6 +328,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /****************************************************************************/
 /*									    */
 /* Interrupt handling							    */
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 536cf5c..72af869 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -164,12 +164,7 @@ reset:
 	bl	lock_cache_for_stack
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0, =0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 #ifndef CONFIG_SPL_BUILD
@@ -186,10 +181,6 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 /* Disable the Dcache RAM lock for stack now */
 #ifdef	CONFIG_CPU_PXA25X
 	bl	cpu_init_crit
@@ -198,7 +189,7 @@ stack_setup:
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -250,48 +241,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif	/* #ifndef CONFIG_SPL_BUILD */
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-#ifdef CONFIG_ONENAND_SPL
-	ldr     r0, _onenand_boot_ofs
-	mov	pc, r0
-
-_onenand_boot_ofs:
-	.word onenand_boot
-#else
-jump_2_ram:
-	ldr	r0, _board_init_r_ofs
-	ldr     r1, _TEXT_BASE
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
-#endif
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -299,7 +251,14 @@ _rel_dyn_end_ofs:
 	.word __rel_dyn_end - _start
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
+
 #endif
+
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 323b923..4528c91 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -128,12 +128,7 @@ reset:
 	bl	lowlevel_init
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -150,14 +145,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -209,42 +200,9 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-
-	bl coloured_LED_init
-	bl red_led_on
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
-	mov	pc, lr
-
-_board_init_r_ofs:
-	.word board_init_r - _start
+	bx	lr
 
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
@@ -253,6 +211,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	bx	lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 1ea92d1..3144299 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -132,12 +132,7 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
-	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-	ldr	r0,=0x00000000
-	bl	board_init_f
+	bl	_main
 
 /*------------------------------------------------------------------------------*/
 
@@ -154,14 +149,10 @@ relocate_code:
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
-stack_setup:
-	mov	sp, r4
-
 	adr	r0, _start
 	cmp	r0, r6
 	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
-	beq	clear_bss		/* skip relocation */
+	beq	relocate_done		/* skip relocation */
 	mov	r1, r6			/* r1 <- scratch for copy_loop */
 	ldr	r3, _bss_start_ofs
 	add	r2, r0, r3		/* r2 <- source end address	    */
@@ -213,40 +204,10 @@ fixnext:
 	blo	fixloop
 #endif
 
-clear_bss:
-#ifndef CONFIG_SPL_BUILD
-	ldr	r0, _bss_start_ofs
-	ldr	r1, _bss_end_ofs
-	mov	r4, r6			/* reloc addr */
-	add	r0, r0, r4
-	add	r1, r1, r4
-	mov	r2, #0x00000000		/* clear			    */
-
-clbss_l:cmp	r0, r1			/* clear loop... */
-	bhs	clbss_e			/* if reached end of bss, exit */
-	str	r2, [r0]
-	add	r0, r0, #4
-	b	clbss_l
-clbss_e:
-#endif
+relocate_done:
 
-/*
- * We are done. Do not return, instead branch to second part of board
- * initialization, now running from RAM.
- */
-	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
-	add	lr, r0, r1
-	add	lr, lr, r9
-	/* setup parameters for board_init_r */
-	mov	r0, r5		/* gd_t */
-	mov	r1, r6		/* dest_addr */
-	/* jump to it ... */
 	mov	pc, lr
 
-_board_init_r_ofs:
-	.word board_init_r - _start
-
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -254,6 +215,11 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
+
+	mov	pc, lr
+
 /*
  *************************************************************************
  *
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..07baee2 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,6 +36,8 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+SOBJS-y += crt0.o
+
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index e0cb635..0459d0c 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -279,11 +279,6 @@ void board_init_f(ulong bootflag)
 
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
-	/* compiler optimization barrier needed for GCC >= 3.4 */
-	__asm__ __volatile__("": : :"memory");
-
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
@@ -465,10 +460,6 @@ void board_init_f(ulong bootflag)
 		gd->fdt_blob = new_fdt;
 	}
 	memcpy(id, (void *)gd, sizeof(gd_t));
-
-	relocate_code(addr_sp, id, addr);
-
-	/* NOTREACHED - relocate_code() does not return */
 }
 
 #if !defined(CONFIG_SYS_NO_FLASH)
@@ -493,8 +484,6 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	ulong flash_size;
 #endif
 
-	gd = id;
-
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
new file mode 100644
index 0000000..4f60958
--- /dev/null
+++ b/arch/arm/lib/crt0.S
@@ -0,0 +1,173 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM U-Boot
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+
+/*
+ * This file handles the target-independent stages of the U-Boot
+ * start-up where a C runtime environment is needed. Its entry point
+ * is _main and is branched into from the target's start.S file.
+ *
+ * _main execution sequence is:
+ *
+ * 1. Set up initial environment for calling board_init_f().
+ *    This environment only provides a stack and a place to store
+ *    the GD ('global data') structure, both located in some readily
+ *    available RAM (SRAM, locked cache...). In this context, VARIABLE
+ *    global data, initialized or not (BSS), are UNAVAILABLE; only
+ *    CONSTANT initialized data are available.
+ *
+ * 2. Call board_init_f(). This function prepares the hardware for
+ *    execution from system RAM (DRAM, DDR...) As system RAM may not
+ *    be available yet, , board_init_f() must use the current GD to
+ *    store any data which must be passed on to later stages. These
+ *    data include the relocation destination, the future stack, and
+ *    the future GD location.
+ *
+ * (the following applies only to non-SPL builds)
+ *
+ * 3. Set up intermediate environment where the stack and GD are the
+ *    ones allocated by board_init_f() in system RAM, but BSS and
+ *    initialized non-const data are still not available.
+ *
+ * 4. Call relocate_code(). This function relocates U-Boot from its
+ *    current location into the relocation destination computed by
+ *    board_init_f().
+ *
+ * 5. Set up final environment for calling board_init_r(). This
+ *    environment has BSS (initialized to 0), initialized non-const
+ *    data (initialized to their intended value), and stack in system
+ *    RAM. GD has retained values set by board_init_f(). Some CPUs
+ *    have some work left to do at this point regarding memory, so
+ *    call c_runtime_cpu_setup.
+ *
+ * 6. Branch to either nand_boot() or board_init_r().
+ */
+
+/*
+ * declare nand_boot() or board_init_r() to jump to at end of crt0
+ */
+
+#if defined(CONFIG_NAND_SPL)
+
+.globl nand_boot
+
+#elif ! defined(CONFIG_SPL_BUILD)
+
+.globl board_init_r
+
+#endif
+
+/*
+ * start and end of BSS
+ */
+
+.globl __bss_start
+.globl __bss_end__
+
+/*
+ * entry point of crt0 sequence
+ */
+
+.global _main
+
+_main:
+
+/*
+ * Set up initial C runtime environment and call board_init_f(0).
+ */
+
+#if defined(CONFIG_NAND_SPL)
+	/* deprecated, use instead CONFIG_SPL_BUILD */
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
+	ldr	sp, =(CONFIG_SPL_STACK)
+#else
+	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+#endif
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	sub	sp, #GD_SIZE	/* allocate one GD above SP */
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	mov	r8, sp		/* GD is above SP */
+	mov	r0, #0
+	bl	board_init_f
+
+#if ! defined(CONFIG_SPL_BUILD)
+
+/*
+ * Set up intermediate environment (new sp and gd) and call
+ * relocate_code(addr_sp, gd, addr_moni). Trick here is that
+ * we'll return 'here' but relocated.
+ */
+
+	ldr	sp, [r8, #GD_START_ADDR_SP]	/* r8 = gd->start_addr_sp */
+	bic	sp, sp, #7	/* 8-byte alignment for ABI compliance */
+	ldr	r8, [r8, #GD_BD]		/* r8 = gd->bd */
+	sub	r8, r8, #GD_SIZE		/* new GD is below bd */
+
+	adr	lr, here
+	ldr	r0, [r8, #GD_RELOC_OFF]		/* lr = gd->start_addr_sp */
+	add	lr, lr, r0
+	ldr	r0, [r8, #GD_START_ADDR_SP]	/* r0 = gd->start_addr_sp */
+	mov	r1, r8				/* r1 = gd */
+	ldr	r2, [r8, #GD_RELOCADDR]		/* r2 = gd->relocaddr */
+	b	relocate_code
+here:
+
+/* Set up final (full) environment */
+
+	bl	c_runtime_cpu_setup	/* we still call old routine here */
+
+	ldr	r0, =__bss_start	/* this is auto-relocated! */
+	ldr	r1, =__bss_end__	/* this is auto-relocated! */
+
+	mov	r2, #0x00000000		/* prepare zero to clear BSS */
+
+clbss_l:cmp	r0, r1			/* while not at end of BSS */
+	strlo	r2, [r0]		/* clear 32-bit BSS word */
+	addlo	r0, r0, #4		/* move to next */
+	blo	clbss_l
+
+	bl coloured_LED_init
+	bl red_led_on
+
+#if defined(CONFIG_NAND_SPL)
+
+	/* call _nand_boot() */
+	ldr     pc, =nand_boot
+
+#else
+
+	/* call board_init_r(gd_t *id, ulong dest_addr) */
+	mov	r0, r8			/* gd_t */
+	ldr	r1, [r8, #GD_RELOCADDR]	/* dest_addr */
+	/* call board_init_r */
+	ldr	pc, =board_init_r	/* this is auto-relocated! */
+
+#endif
+
+	/* we should not return here. */
+
+#endif
diff --git a/include/common.h b/include/common.h
index d0bf1e8..2f2578b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -300,7 +300,7 @@ int	abortboot(int bootdelay);
 extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
-void	board_init_f  (ulong) __attribute__ ((noreturn));
+void	board_init_f(ulong);
 void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
 int	checkboard    (void);
 int	checkflash    (void);
diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h
index 42077bd..5633d2a 100644
--- a/include/configs/socfpga_cyclone5.h
+++ b/include/configs/socfpga_cyclone5.h
@@ -65,7 +65,7 @@
 #define CONFIG_SYS_BOOTMAPSZ		((256*1024*1024) - (4*1024))
 
 #define CONFIG_SPL_RAM_DEVICE
-#define CONFIG_SPL_STACK (&__stack_start)
+#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
 #define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
 #define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
 
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c88f5d4..8546a52 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,5 +28,19 @@ int main(void)
 	DEFINE(GENERATED_BD_INFO_SIZE,
 		(sizeof(struct bd_info) + 15) & ~15);
 
+	DEFINE(GD_SIZE, sizeof(struct global_data));
+
+	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+#if defined(CONFIG_ARM)
+
+	DEFINE(GD_RELOCADDR, offsetof(struct global_data, relocaddr));
+
+	DEFINE(GD_RELOC_OFF, offsetof(struct global_data, reloc_off));
+
+	DEFINE(GD_START_ADDR_SP, offsetof(struct global_data, start_addr_sp));
+
+#endif
+
 	return 0;
 }
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index f67ed09..fd0dfc1 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -12,11 +12,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm1136/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/freescale/mx31pdk/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -50,6 +51,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm1136/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index b27189d..82489d2 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -33,11 +33,12 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o crt0.o lowlevel_init.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
 SRCS	+= $(SRCTREE)/arch/arm/cpu/arm926ejs/start.S
+SRCS	+= $(SRCTREE)/arch/arm/lib/crt0.S
 SRCS	+= $(SRCTREE)/board/karo/tx25/lowlevel_init.S
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
 __OBJS	:= $(SOBJS) $(COBJS)
@@ -71,6 +72,9 @@ $(nandobj)u-boot.lds: $(LDSCRIPT) $(LSTSCRIPT)
 $(obj)%.o:	$(SRCTREE)/arch/arm/cpu/arm926ejs/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 	$(CC) $(AFLAGS) -c -o $@ $<
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v5 2/2] arm: remove useless code in start.S files
  2013-01-08 20:18           ` [U-Boot] [PATCH v5 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2013-01-08 20:18             ` Albert ARIBAUD
  0 siblings, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 20:18 UTC (permalink / raw)
  To: u-boot

Remove code such as unneeded includes or labels.
These removals have no functional effect.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
- removed useless includes in arm926ejs and arm925t

 arch/arm/cpu/arm925t/start.S   |    4 ----
 arch/arm/cpu/arm926ejs/start.S |    6 ------
 2 files changed, 10 deletions(-)

diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 82f5b8b..e8d6d71 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -34,10 +34,6 @@
 #include <config.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1510)
-#include <./configs/omap1510.h>
-#endif
-
 /*
  *************************************************************************
  *
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 3cdecd9..66a8b65 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -36,12 +36,6 @@
 #include <common.h>
 #include <version.h>
 
-#if defined(CONFIG_OMAP1610)
-#include <./configs/omap1510.h>
-#elif defined(CONFIG_OMAP730)
-#include <./configs/omap730.h>
-#endif
-
 /*
  *************************************************************************
  *
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible.
  2013-01-08 20:18         ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
  2013-01-08 20:18           ` [U-Boot] [PATCH v5 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
@ 2013-01-08 21:16           ` Albert ARIBAUD
  1 sibling, 0 replies; 47+ messages in thread
From: Albert ARIBAUD @ 2013-01-08 21:16 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tue,  8 Jan 2013 21:18:01 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> The goal of this series is to scrub the start.S files
> which have proliferated across arch/arm and eliminate
> code redundancy.
> 
> This series only factorizes the C runtime framework,
> that is, the assembly code responsible for setting up
> the C environments needed by board_init_*() and
> relocate_code().
> 
> Further factorization is possible: relocate_code() can
> be moved out and possibly rewritten in C now that it
> has plain C function semantics; exception handlers
> should also be pretty much cpu-independent.
> 
> Also, SPL currently makes board_init_f() perform all
> of the setting up, including BSS clearing and chain-
> loading. This could be streamlined by only putting
> basic inits in board_init_f(), letting crt0 do the
> BSS initialization and chain-loading U-Boot from
> inside board_init_r().
> 
> Eventually, start.S files should disappear or contain
> CPU-specific code only.
> 
> The new C runtime setup sequence has been validated step by
> step on targets versatileqemu using gcc version 4.2.2 from
> the ELDK4.2 toolchain, and wireless_space using gcc version
> 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1).
> 
> The whole changes have been build-tested across all ARM
> targets using MAKEALL -a arm.
> 
> Changes in v5:
> - Fixed build on non-ARM architectures
> 
> Changes in v4:
> - fixed bhs into blo in BSS init loop
> - switched from explicit literals to '=target' notation
> - fixed location of GD in initial environment
> - stopped SPL boot sequence at calling board_init_f
> 
> Changes in v3:
> - various clarifications and typo fixes
> - fixed wrong LED calls conditional
> - fixed open comment eating some code
> - fixed code overrun in SPL case
> 
> Changes in v2:
> - moved description from cover letter to patch commit msg
> - added note about tests in the cover letter
> - fixed baords with CONFIG_SPL but not CONFIG_SPL_STACK
> - removed useless includes in arm926ejs and arm925t
> 
> Albert ARIBAUD (2):
>   arm: move C runtime setup code in crt0.S
>   arm: remove useless code in start.S files
> 
>  arch/arm/cpu/arm1136/start.S              |   71 +++---------
>  arch/arm/cpu/arm1176/start.S              |   62 ++---------
>  arch/arm/cpu/arm720t/start.S              |   53 ++-------
>  arch/arm/cpu/arm920t/start.S              |   61 ++--------
>  arch/arm/cpu/arm925t/start.S              |   65 ++---------
>  arch/arm/cpu/arm926ejs/start.S            |   86 ++------------
>  arch/arm/cpu/arm946es/start.S             |   56 ++--------
>  arch/arm/cpu/arm_intcm/start.S            |   63 ++---------
>  arch/arm/cpu/armv7/start.S                |   58 +++-------
>  arch/arm/cpu/ixp/start.S                  |   55 ++-------
>  arch/arm/cpu/pxa/start.S                  |   63 ++---------
>  arch/arm/cpu/s3c44b0/start.S              |   55 ++-------
>  arch/arm/cpu/sa1100/start.S               |   50 ++-------
>  arch/arm/lib/Makefile                     |    2 +
>  arch/arm/lib/board.c                      |   11 --
>  arch/arm/lib/crt0.S                       |  173 +++++++++++++++++++++++++++++
>  include/common.h                          |    2 +-
>  include/configs/socfpga_cyclone5.h        |    2 +-
>  lib/asm-offsets.c                         |   14 +++
>  nand_spl/board/freescale/mx31pdk/Makefile |    6 +-
>  nand_spl/board/karo/tx25/Makefile         |    6 +-
>  21 files changed, 326 insertions(+), 688 deletions(-)
>  create mode 100644 arch/arm/lib/crt0.S
> 

Applied to u-boot-arm/master with a rollback from the Marvell PR and
v4 of this patch series.

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2013-01-08 21:16 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-04  3:57 [U-Boot] [PATCH v1 0/1] Factorize ARM startup code as mush as possible Albert ARIBAUD
2012-11-04  3:57 ` [U-Boot] [PATCH v1] arm: move generic startup code in crt0.S Albert ARIBAUD
2012-11-04  7:29   ` Wolfgang Denk
2012-11-04  8:36     ` Albert ARIBAUD
2012-11-04 11:32 ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
2012-11-04 11:32   ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
2012-11-04 11:32     ` [U-Boot] [PATCH v2 2/2] arm: remove useless code in start.S files Albert ARIBAUD
2012-11-04 11:34     ` [U-Boot] [PATCH v2 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
2012-11-04 15:06     ` Vikram Narayanan
2012-11-04 18:01       ` Albert ARIBAUD
2012-11-05  8:31     ` Andreas Bießmann
2012-11-10 16:48       ` Albert ARIBAUD
2012-11-10 16:53     ` Albert ARIBAUD
2012-11-04 11:43   ` [U-Boot] [PATCH v2 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
2012-11-04 17:38     ` Tom Rini
2012-11-05  7:39       ` Sughosh Ganu
2012-11-08 14:20         ` Sughosh Ganu
2012-11-10 14:30           ` Albert ARIBAUD
2012-11-13  4:10             ` Sughosh Ganu
2012-11-13 19:55               ` Albert ARIBAUD
2012-12-09 20:31                 ` Sughosh Ganu
2012-11-10 17:00   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
2012-11-10 17:00     ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
2012-11-10 17:00       ` [U-Boot] [PATCH v3 2/2] arm: remove useless code in start.S files Albert ARIBAUD
2012-11-15 19:35       ` [U-Boot] [PATCH v3 1/2] arm: move C runtime setup code in crt0.S Simon Glass
2012-11-15 22:41         ` Albert ARIBAUD
2012-11-10 17:28     ` [U-Boot] [PATCH v3 0/2] Factorize ARM startup code as mush as possible Albert ARIBAUD
2012-11-27 12:43     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
2012-11-27 12:43       ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
2012-11-27 12:43         ` [U-Boot] [PATCH v4 2/2] arm: remove useless code in start.S files Albert ARIBAUD
2013-01-07 14:41           ` Tom Rini
2012-11-28 21:18         ` [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S Simon Glass
2012-11-28 22:34           ` Albert ARIBAUD
2012-11-30 22:10             ` Simon Glass
2012-12-23 15:03               ` Albert ARIBAUD
2012-12-26 20:41                 ` Simon Glass
2013-01-05  1:00                   ` Simon Glass
2012-12-09 20:33         ` Sughosh Ganu
2013-01-07 14:40         ` Tom Rini
2013-01-08 19:26         ` Tom Rini
2013-01-08 19:50           ` Albert ARIBAUD
2013-01-08 20:18         ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
2013-01-08 20:18           ` [U-Boot] [PATCH v5 1/2] arm: move C runtime setup code in crt0.S Albert ARIBAUD
2013-01-08 20:18             ` [U-Boot] [PATCH v5 2/2] arm: remove useless code in start.S files Albert ARIBAUD
2013-01-08 21:16           ` [U-Boot] [PATCH v5 0/2] Factorize ARM startup code as much as possible Albert ARIBAUD
2012-12-27 11:27       ` [U-Boot] [PATCH v4 0/2] Factorize ARM startup code as mush " Albert ARIBAUD
2013-01-08 17:20       ` Albert ARIBAUD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox