All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/4] Factorize ARM relocation code
@ 2013-05-10 21:56 Albert ARIBAUD
  2013-05-10 21:56 ` [U-Boot] [PATCH 1/4] Rename arch/arm/lib/bss.c to sections.c Albert ARIBAUD
  2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  0 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-10 21:56 UTC (permalink / raw)
  To: u-boot

This is V1 of the ARM relocation code factorization patch series.

Albert ARIBAUD (4):
  Rename arch/arm/lib/bss.c to sections.c
  arm: make __image_copy_{start,end} compiler-generated
  arm: make relocation section symbols compiler-generated
  arm: factorize relocate_code routine

 arch/arm/cpu/arm1136/start.S                   |   83 --------------------
 arch/arm/cpu/arm1136/u-boot-spl.lds            |    3 +-
 arch/arm/cpu/arm1176/start.S                   |   75 ------------------
 arch/arm/cpu/arm720t/start.S                   |   79 -------------------
 arch/arm/cpu/arm920t/ep93xx/u-boot.lds         |    6 +-
 arch/arm/cpu/arm920t/start.S                   |   75 ------------------
 arch/arm/cpu/arm925t/start.S                   |   75 ------------------
 arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds      |   15 +++-
 arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds    |   15 +++-
 arch/arm/cpu/arm926ejs/start.S                 |   83 --------------------
 arch/arm/cpu/arm946es/start.S                  |   75 ------------------
 arch/arm/cpu/arm_intcm/start.S                 |   75 ------------------
 arch/arm/cpu/armv7/am33xx/u-boot-spl.lds       |    2 -
 arch/arm/cpu/armv7/omap-common/u-boot-spl.lds  |    2 -
 arch/arm/cpu/armv7/socfpga/u-boot-spl.lds      |    1 -
 arch/arm/cpu/armv7/start.S                     |   80 -------------------
 arch/arm/cpu/ixp/start.S                       |   75 ------------------
 arch/arm/cpu/ixp/u-boot.lds                    |   24 ++++--
 arch/arm/cpu/pxa/start.S                       |   84 --------------------
 arch/arm/cpu/s3c44b0/start.S                   |   75 ------------------
 arch/arm/cpu/sa1100/start.S                    |   75 ------------------
 arch/arm/cpu/u-boot-spl.lds                    |   21 +++--
 arch/arm/cpu/u-boot.lds                        |   25 ++++--
 arch/arm/lib/Makefile                          |    4 +-
 arch/arm/lib/relocate.S                        |  100 ++++++++++++++++++++++++
 arch/arm/lib/{bss.c => sections.c}             |    7 +-
 board/actux1/u-boot.lds                        |   18 ++++-
 board/actux2/u-boot.lds                        |   18 ++++-
 board/actux3/u-boot.lds                        |   19 ++++-
 board/ait/cam_enc_4xx/u-boot-spl.lds           |   16 +++-
 board/davinci/da8xxevm/u-boot-spl-da850evm.lds |   16 +++-
 board/dvlhost/u-boot.lds                       |   18 ++++-
 board/freescale/mx31ads/u-boot.lds             |   18 ++++-
 board/vpac270/u-boot-spl.lds                   |   18 ++++-
 34 files changed, 303 insertions(+), 1072 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S
 rename arch/arm/lib/{bss.c => sections.c} (78%)

-- 
1.7.10.4

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

* [U-Boot] [PATCH 1/4] Rename arch/arm/lib/bss.c to sections.c
  2013-05-10 21:56 [U-Boot] [PATCH 0/4] Factorize ARM relocation code Albert ARIBAUD
@ 2013-05-10 21:56 ` Albert ARIBAUD
  2013-05-10 21:56   ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Albert ARIBAUD
  2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-10 21:56 UTC (permalink / raw)
  To: u-boot

This file will contain symbols other than the BSS
start and stop, so rename it for better accuracy.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/lib/Makefile              |    2 +-
 arch/arm/lib/{bss.c => sections.c} |    0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename arch/arm/lib/{bss.c => sections.c} (100%)

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6ae161a..ac51cc1 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -42,7 +42,7 @@ ifndef CONFIG_SPL_BUILD
 ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
 endif
-COBJS-y += bss.o
+COBJS-y += sections.o
 
 COBJS-y	+= bootm.o
 COBJS-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
diff --git a/arch/arm/lib/bss.c b/arch/arm/lib/sections.c
similarity index 100%
rename from arch/arm/lib/bss.c
rename to arch/arm/lib/sections.c
-- 
1.7.10.4

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-10 21:56 ` [U-Boot] [PATCH 1/4] Rename arch/arm/lib/bss.c to sections.c Albert ARIBAUD
@ 2013-05-10 21:56   ` Albert ARIBAUD
  2013-05-10 21:56     ` [U-Boot] [PATCH 3/4] arm: make relocation section symbols compiler-generated Albert ARIBAUD
  2013-05-11  0:25     ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Benoît Thébaudeau
  0 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-10 21:56 UTC (permalink / raw)
  To: u-boot


Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/cpu/arm1136/start.S                  |    7 +++----
 arch/arm/cpu/arm1136/u-boot-spl.lds           |    3 ++-
 arch/arm/cpu/arm720t/start.S                  |   11 +++++++----
 arch/arm/cpu/arm920t/ep93xx/u-boot.lds        |    6 +++++-
 arch/arm/cpu/arm926ejs/start.S                |    7 +++----
 arch/arm/cpu/armv7/am33xx/u-boot-spl.lds      |    2 --
 arch/arm/cpu/armv7/omap-common/u-boot-spl.lds |    2 --
 arch/arm/cpu/armv7/socfpga/u-boot-spl.lds     |    1 -
 arch/arm/cpu/armv7/start.S                    |    6 ++----
 arch/arm/cpu/ixp/u-boot.lds                   |    6 +++++-
 arch/arm/cpu/u-boot-spl.lds                   |    3 +--
 arch/arm/cpu/u-boot.lds                       |    7 +++++--
 arch/arm/lib/sections.c                       |    4 +++-
 13 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index ccea2d5..ab8fd56 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -104,10 +104,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -239,6 +235,9 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
+
 #ifndef CONFIG_SPL_BUILD
 
 _rel_dyn_start_ofs:
diff --git a/arch/arm/cpu/arm1136/u-boot-spl.lds b/arch/arm/cpu/arm1136/u-boot-spl.lds
index 8296e5d..04fc881 100644
--- a/arch/arm/cpu/arm1136/u-boot-spl.lds
+++ b/arch/arm/cpu/arm1136/u-boot-spl.lds
@@ -37,7 +37,6 @@ SECTIONS
 {
 	.text      :
 	{
-	__start = .;
 	  arch/arm/cpu/arm1136/start.o	(.text*)
 	  *(.text*)
 	} >.sram
@@ -48,7 +47,9 @@ SECTIONS
 	. = ALIGN(4);
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 	. = ALIGN(4);
+
 	__image_copy_end = .;
+
 	_end = .;
 
 	.bss :
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 9facc7e..b85509c 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -221,6 +217,11 @@ relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
+
+#ifndef CONFIG_SPL_BUILD
+
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +229,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/ep93xx/u-boot.lds b/arch/arm/cpu/arm920t/ep93xx/u-boot.lds
index cf55bf7..2b32c0a 100644
--- a/arch/arm/cpu/arm920t/ep93xx/u-boot.lds
+++ b/arch/arm/cpu/arm920t/ep93xx/u-boot.lds
@@ -31,6 +31,7 @@ SECTIONS
 	. = ALIGN(4);
 	.text      :
 	{
+	  *(.__image_copy_start)
 	  arch/arm/cpu/arm920t/start.o	(.text*)
 		/* the EP93xx expects to find the pattern 'CRUS' at 0x1000 */
 	  . = 0x1000;
@@ -56,7 +57,10 @@ SECTIONS
 
 	. = ALIGN(4);
 
-	__image_copy_end = .;
+	.image_copy_end :
+	{
+		*(.__image_copy_end);
+	}
 
 	__bss_start = .;
 	.bss : { *(.bss*) }
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 4c56711..736361a 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -136,10 +136,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -256,6 +252,9 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
+
 #ifndef CONFIG_SPL_BUILD
 
 _rel_dyn_start_ofs:
diff --git a/arch/arm/cpu/armv7/am33xx/u-boot-spl.lds b/arch/arm/cpu/armv7/am33xx/u-boot-spl.lds
index b6a929f..29cefd0 100644
--- a/arch/arm/cpu/armv7/am33xx/u-boot-spl.lds
+++ b/arch/arm/cpu/armv7/am33xx/u-boot-spl.lds
@@ -37,7 +37,6 @@ SECTIONS
 {
 	.text      :
 	{
-		__start = .;
 		arch/arm/cpu/armv7/start.o	(.text)
 		*(.text*)
 	} >.sram
@@ -53,7 +52,6 @@ SECTIONS
 	} >.sram
 
 	. = ALIGN(4);
-	__image_copy_end = .;
 	_end = .;
 
 	.bss :
diff --git a/arch/arm/cpu/armv7/omap-common/u-boot-spl.lds b/arch/arm/cpu/armv7/omap-common/u-boot-spl.lds
index bd218c0..81cafe1 100644
--- a/arch/arm/cpu/armv7/omap-common/u-boot-spl.lds
+++ b/arch/arm/cpu/armv7/omap-common/u-boot-spl.lds
@@ -37,7 +37,6 @@ SECTIONS
 {
 	.text      :
 	{
-		__start = .;
 		arch/arm/cpu/armv7/start.o	(.text*)
 		*(.text*)
 	} >.sram
@@ -49,7 +48,6 @@ SECTIONS
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
 	. = ALIGN(4);
-	__image_copy_end = .;
 	_end = .;
 
 	.bss :
diff --git a/arch/arm/cpu/armv7/socfpga/u-boot-spl.lds b/arch/arm/cpu/armv7/socfpga/u-boot-spl.lds
index 15f8c01..c0dcfd7 100644
--- a/arch/arm/cpu/armv7/socfpga/u-boot-spl.lds
+++ b/arch/arm/cpu/armv7/socfpga/u-boot-spl.lds
@@ -38,7 +38,6 @@ SECTIONS
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sdram
 
 	. = ALIGN(4);
-	__image_copy_end = .;
 	_end = .;
 
 	.bss : {
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index e9e57e6..3ade510 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -94,10 +94,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -231,6 +227,8 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/ixp/u-boot.lds b/arch/arm/cpu/ixp/u-boot.lds
index 553589c..1a0ba17 100644
--- a/arch/arm/cpu/ixp/u-boot.lds
+++ b/arch/arm/cpu/ixp/u-boot.lds
@@ -31,6 +31,7 @@ SECTIONS
 	. = ALIGN(4);
 	.text :
 	{
+		*(.__image_copy_start)
 		arch/arm/cpu/ixp/start.o(.text*)
 		*(.text*)
 	}
@@ -54,7 +55,10 @@ SECTIONS
 
 	. = ALIGN(4);
 
-	__image_copy_end = .;
+	.image_copy_end :
+	{
+		*(.__image_copy_end);
+	}
 
 	.rel.dyn : {
 		__rel_dyn_start = .;
diff --git a/arch/arm/cpu/u-boot-spl.lds b/arch/arm/cpu/u-boot-spl.lds
index 1408f03..87341c1 100644
--- a/arch/arm/cpu/u-boot-spl.lds
+++ b/arch/arm/cpu/u-boot-spl.lds
@@ -33,7 +33,6 @@ SECTIONS
 	. = ALIGN(4);
 	.text :
 	{
-		__image_copy_start = .;
 		CPUDIR/start.o (.text*)
 		*(.text*)
 	}
@@ -80,7 +79,7 @@ SECTIONS
 }
 
 #if defined(CONFIG_SPL_MAX_SIZE)
-ASSERT(__image_copy_end - __image_copy_start < (CONFIG_SPL_MAX_SIZE), \
+ASSERT(__image_copy_end - _start < (CONFIG_SPL_MAX_SIZE), \
 	"SPL image too big");
 #endif
 
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index d9bbee3..5b43621 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -33,7 +33,7 @@ SECTIONS
 	. = ALIGN(4);
 	.text :
 	{
-		__image_copy_start = .;
+		*(.__image_copy_start)
 		CPUDIR/start.o (.text*)
 		*(.text*)
 	}
@@ -57,7 +57,10 @@ SECTIONS
 
 	. = ALIGN(4);
 
-	__image_copy_end = .;
+	.image_copy_end :
+	{
+		*(.__image_copy_end);
+	}
 
 	.rel.dyn : {
 		__rel_dyn_start = .;
diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
index 99eda59..80a0c38 100644
--- a/arch/arm/lib/sections.c
+++ b/arch/arm/lib/sections.c
@@ -21,7 +21,7 @@
  */
 
 /**
- * These two symbols are declared in a C file so that the linker
+ * The following symbols are declared in a C file so that the linker
  * uses R_ARM_RELATIVE relocation, rather than the R_ARM_ABS32 one
  * it would use if the symbols were defined in the linker file.
  * Using only R_ARM_RELATIVE relocation ensures that references to
@@ -37,3 +37,5 @@
 
 char __bss_start[0] __attribute__((used, section(".__bss_start")));
 char __bss_end[0] __attribute__((used, section(".__bss_end")));
+char __image_copy_start[0] __attribute__((used, section(".__image_copy_start")));
+char __image_copy_end[0] __attribute__((used, section(".__image_copy_end")));
-- 
1.7.10.4

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

* [U-Boot] [PATCH 3/4] arm: make relocation section symbols compiler-generated
  2013-05-10 21:56   ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Albert ARIBAUD
@ 2013-05-10 21:56     ` Albert ARIBAUD
  2013-05-10 21:56       ` [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine Albert ARIBAUD
  2013-05-11  0:25     ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Benoît Thébaudeau
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-10 21:56 UTC (permalink / raw)
  To: u-boot


Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds      |   15 ++++++++++++---
 arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds    |   15 ++++++++++++---
 arch/arm/cpu/ixp/u-boot.lds                    |   18 ++++++++++++++----
 arch/arm/cpu/u-boot-spl.lds                    |   18 ++++++++++++++----
 arch/arm/cpu/u-boot.lds                        |   18 ++++++++++++++----
 arch/arm/lib/sections.c                        |    3 +++
 board/actux1/u-boot.lds                        |   18 ++++++++++++++----
 board/actux2/u-boot.lds                        |   18 ++++++++++++++----
 board/actux3/u-boot.lds                        |   19 +++++++++++++++----
 board/ait/cam_enc_4xx/u-boot-spl.lds           |   16 +++++++++++++---
 board/davinci/da8xxevm/u-boot-spl-da850evm.lds |   16 +++++++++++++---
 board/dvlhost/u-boot.lds                       |   18 ++++++++++++++----
 board/freescale/mx31ads/u-boot.lds             |   18 ++++++++++++++----
 board/vpac270/u-boot-spl.lds                   |   18 ++++++++++++++----
 14 files changed, 180 insertions(+), 48 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds b/arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds
index 673c725..b078387 100644
--- a/arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds
+++ b/arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds
@@ -51,14 +51,23 @@ SECTIONS
 
 	. = ALIGN(4);
 
+	.rel_dyn_start : {
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds b/arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds
index 967a135..a24879f 100644
--- a/arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds
+++ b/arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds
@@ -51,14 +51,23 @@ SECTIONS
 
 	. = ALIGN(4);
 
+	.rel_dyn_start : {
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/arch/arm/cpu/ixp/u-boot.lds b/arch/arm/cpu/ixp/u-boot.lds
index 1a0ba17..1315b41 100644
--- a/arch/arm/cpu/ixp/u-boot.lds
+++ b/arch/arm/cpu/ixp/u-boot.lds
@@ -60,14 +60,24 @@ SECTIONS
 		*(.__image_copy_end);
 	}
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -78,7 +88,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/arch/arm/cpu/u-boot-spl.lds b/arch/arm/cpu/u-boot-spl.lds
index 87341c1..87e5655 100644
--- a/arch/arm/cpu/u-boot-spl.lds
+++ b/arch/arm/cpu/u-boot-spl.lds
@@ -51,20 +51,30 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
 	_end = .;
 
-	.bss __rel_dyn_start (OVERLAY) : {
+	.bss __rel_dyn_base (OVERLAY) : {
 		__bss_start = .;
 		*(.bss*)
 		 . = ALIGN(4);
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 5b43621..fbac4d1 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -62,14 +62,24 @@ SECTIONS
 		*(.__image_copy_end);
 	}
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -89,7 +99,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
index 80a0c38..c1ef867 100644
--- a/arch/arm/lib/sections.c
+++ b/arch/arm/lib/sections.c
@@ -39,3 +39,6 @@ char __bss_start[0] __attribute__((used, section(".__bss_start")));
 char __bss_end[0] __attribute__((used, section(".__bss_end")));
 char __image_copy_start[0] __attribute__((used, section(".__image_copy_start")));
 char __image_copy_end[0] __attribute__((used, section(".__image_copy_end")));
+char __rel_dyn_start[0] __attribute__((used, section(".__rel_dyn_start")));
+char __rel_dyn_end[0] __attribute__((used, section(".__rel_dyn_end")));
+char __dynsym_start[0] __attribute__((used, section(".__dynsym_start")));
diff --git a/board/actux1/u-boot.lds b/board/actux1/u-boot.lds
index ef4a25b..0327c27 100644
--- a/board/actux1/u-boot.lds
+++ b/board/actux1/u-boot.lds
@@ -64,14 +64,24 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -82,7 +92,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/board/actux2/u-boot.lds b/board/actux2/u-boot.lds
index 00ad8b7..a025bf1 100644
--- a/board/actux2/u-boot.lds
+++ b/board/actux2/u-boot.lds
@@ -64,14 +64,24 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -82,7 +92,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/board/actux3/u-boot.lds b/board/actux3/u-boot.lds
index 44b990e..41510c4 100644
--- a/board/actux3/u-boot.lds
+++ b/board/actux3/u-boot.lds
@@ -64,14 +64,25 @@ SECTIONS
 
 	__image_copy_end = .;
 
+
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -82,7 +93,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/board/ait/cam_enc_4xx/u-boot-spl.lds b/board/ait/cam_enc_4xx/u-boot-spl.lds
index 1daa1b3..68c65c1 100644
--- a/board/ait/cam_enc_4xx/u-boot-spl.lds
+++ b/board/ait/cam_enc_4xx/u-boot-spl.lds
@@ -48,14 +48,24 @@ SECTIONS
 	. = ALIGN(4);
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 	. = ALIGN(4);
+
+	.rel_dyn_start : {
+		*(.__rel_dyn_start);
+	} >.sram
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	} >.sram
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	} >.sram
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	} >.sram
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	} >.sram
 
diff --git a/board/davinci/da8xxevm/u-boot-spl-da850evm.lds b/board/davinci/da8xxevm/u-boot-spl-da850evm.lds
index b1b8701..56c276f 100644
--- a/board/davinci/da8xxevm/u-boot-spl-da850evm.lds
+++ b/board/davinci/da8xxevm/u-boot-spl-da850evm.lds
@@ -49,14 +49,24 @@ SECTIONS
 	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
 	. = ALIGN(4);
+
+	.rel_dyn_start : {
+		*(.__rel_dyn_start);
+	} >.sram
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	} >.sram
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	} >.sram
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	} >.sram
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	} >.sram
 
diff --git a/board/dvlhost/u-boot.lds b/board/dvlhost/u-boot.lds
index 6d4b187..ea00c09 100644
--- a/board/dvlhost/u-boot.lds
+++ b/board/dvlhost/u-boot.lds
@@ -64,14 +64,24 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -82,7 +92,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/board/freescale/mx31ads/u-boot.lds b/board/freescale/mx31ads/u-boot.lds
index 4969960..092232f 100644
--- a/board/freescale/mx31ads/u-boot.lds
+++ b/board/freescale/mx31ads/u-boot.lds
@@ -67,14 +67,24 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+	__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -85,7 +95,7 @@ SECTIONS
  * __bss_base and __bss_limit are for linker only (overlay ordering)
  */
 
-	.bss_start __rel_dyn_start (OVERLAY) : {
+	.bss_start __rel_dyn_base (OVERLAY) : {
 		KEEP(*(.__bss_start));
 		__bss_base = .;
 	}
diff --git a/board/vpac270/u-boot-spl.lds b/board/vpac270/u-boot-spl.lds
index 61d1154..e341ce6 100644
--- a/board/vpac270/u-boot-spl.lds
+++ b/board/vpac270/u-boot-spl.lds
@@ -61,14 +61,24 @@ SECTIONS
 
 	__image_copy_end = .;
 
+	.rel_dyn_start : {
+		__rel_dyn_base = .;
+		*(.__rel_dyn_start);
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end : {
+		*(.__rel_dyn_end);
+	}
+
+	.dynsym_start : {
+		*(.__dynsym_start);
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
@@ -76,7 +86,7 @@ SECTIONS
 
 	_end = .;
 
-	.bss __rel_dyn_start (OVERLAY) : {
+	.bss __rel_dyn_base (OVERLAY) : {
 		__bss_start = .;
 		*(.bss*)
 		 . = ALIGN(4);
-- 
1.7.10.4

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

* [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine
  2013-05-10 21:56     ` [U-Boot] [PATCH 3/4] arm: make relocation section symbols compiler-generated Albert ARIBAUD
@ 2013-05-10 21:56       ` Albert ARIBAUD
  2013-05-11  2:04         ` Benoît Thébaudeau
  2013-05-11 22:13         ` Simon Glass
  0 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-10 21:56 UTC (permalink / raw)
  To: u-boot


Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/cpu/arm1136/start.S   |   82 --------------------------------
 arch/arm/cpu/arm1176/start.S   |   75 ------------------------------
 arch/arm/cpu/arm720t/start.S   |   82 --------------------------------
 arch/arm/cpu/arm920t/start.S   |   75 ------------------------------
 arch/arm/cpu/arm925t/start.S   |   75 ------------------------------
 arch/arm/cpu/arm926ejs/start.S |   82 --------------------------------
 arch/arm/cpu/arm946es/start.S  |   75 ------------------------------
 arch/arm/cpu/arm_intcm/start.S |   75 ------------------------------
 arch/arm/cpu/armv7/start.S     |   78 -------------------------------
 arch/arm/cpu/ixp/start.S       |   75 ------------------------------
 arch/arm/cpu/pxa/start.S       |   84 ---------------------------------
 arch/arm/cpu/s3c44b0/start.S   |   75 ------------------------------
 arch/arm/cpu/sa1100/start.S    |   75 ------------------------------
 arch/arm/lib/Makefile          |    2 +-
 arch/arm/lib/relocate.S        |  100 ++++++++++++++++++++++++++++++++++++++++
 15 files changed, 101 insertions(+), 1009 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index ab8fd56..4b3f828 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -167,88 +167,6 @@ next:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
-#ifndef CONFIG_SPL_BUILD
-
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index f20da8e..6929b08 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -223,81 +223,6 @@ skip_tcmdisable:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index b85509c..afb40eb 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -149,88 +149,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
-#ifndef CONFIG_SPL_BUILD
-
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 6250025..dbfca78 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -192,81 +192,6 @@ copyex:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	mov	pc, 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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 021e241..372b9e9 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -182,81 +182,6 @@ poll1:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	mov	pc, 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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 736361a..2ee591b 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -184,88 +184,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
-#ifndef CONFIG_SPL_BUILD
-
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 9c2b70d..e31af6f 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -157,81 +157,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	mov	pc, 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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index 5e8c528..9cce12f 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -153,81 +153,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 3ade510..bfdc22b 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -161,84 +161,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-ENTRY(relocate_code)
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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)
-
-#endif
-
 ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 69ef8aa..f9594d0 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -255,81 +255,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index ada91a6..3078bec 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -170,90 +170,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-/* Disable the Dcache RAM lock for stack now */
-#ifdef	CONFIG_CPU_PXA25X
-	mov	r12, lr
-	bl	cpu_init_crit
-	mov	lr, r12
-#endif
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 7361aa2..4e1a444 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -138,81 +138,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 8a2eafd..c79f8c9 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -142,81 +142,6 @@ reset:
 
 	bl	_main
 
-/*------------------------------------------------------------------------------*/
-
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-#ifndef CONFIG_SPL_BUILD
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-#endif
-
-relocate_done:
-
-	mov	pc, 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
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index ac51cc1..f8349c5 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -36,7 +36,7 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
-SOBJS-y += crt0.o
+SOBJS-y += crt0.o relocate.o
 
 ifndef CONFIG_SPL_BUILD
 ifndef CONFIG_SYS_GENERIC_BOARD
diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
new file mode 100644
index 0000000..ce533ca
--- /dev/null
+++ b/arch/arm/lib/relocate.S
@@ -0,0 +1,100 @@
+/*
+ *  relocate - common relocation function for ARM U-Boot
+ *
+ *  Copyright (c) 2013  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
+ */
+
+/*
+ * These are defined in the board-specific linker script.
+ * Subtracting _start from them lets the linker put their
+ * relative position in the executable instead of leaving
+ * them null.
+ */
+
+	.globl	__image_copy_start
+	.globl	__image_copy_end
+	.globl	__rel_dyn_start
+	.globl	__rel_dyn_end
+	.globl	__dynsym_start
+
+/*------------------------------------------------------------------------------*/
+
+/*
+ * void relocate_code(addr_moni)
+ *
+ * This function relocates the monitor code.
+ */
+	.globl	relocate_code
+relocate_code:
+	mov	r6, r0	/* save addr of destination */
+
+	ldr	r0, =_start
+	subs	r9, r6, r0		/* r9 <- relocation offset */
+	beq	relocate_done		/* skip relocation */
+	mov	r1, r6			/* r1 <- scratch for copy_loop */
+	ldr	r2, =__image_copy_end
+
+copy_loop:
+	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
+	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
+	cmp	r0, r2			/* until source end address [r2]    */
+	blo	copy_loop
+
+#ifndef CONFIG_SPL_BUILD
+	/*
+	 * fix .rel.dyn relocations
+	 */
+	ldr	r0, =_TEXT_BASE		/* r0 <- Text base */
+	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
+	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
+	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */
+fixloop:
+	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
+	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
+	ldr	r1, [r2, #4]
+	and	r7, r1, #0xff
+	cmp	r7, #23			/* relative fixup? */
+	beq	fixrel
+	cmp	r7, #2			/* absolute fixup? */
+	beq	fixabs
+	/* ignore unknown type of fixup */
+	b	fixnext
+fixabs:
+	/* absolute fix: set location to (offset) symbol value */
+	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
+	add	r1, r10, r1		/* r1 <- address of symbol in table */
+	ldr	r1, [r1, #4]		/* r1 <- symbol value */
+	add	r1, r1, r9		/* r1 <- relocated sym addr */
+	b	fixnext
+fixrel:
+	/* relative fix: increase location by offset */
+	ldr	r1, [r0]
+	add	r1, r1, r9
+fixnext:
+	str	r1, [r0]
+	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
+	cmp	r2, r3
+	blo	fixloop
+#endif
+
+relocate_done:
+
+	bx	lr
-- 
1.7.10.4

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-10 21:56   ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Albert ARIBAUD
  2013-05-10 21:56     ` [U-Boot] [PATCH 3/4] arm: make relocation section symbols compiler-generated Albert ARIBAUD
@ 2013-05-11  0:25     ` Benoît Thébaudeau
  2013-05-11  8:02       ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-11  0:25 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Friday, May 10, 2013 11:56:50 PM, Albert ARIBAUD wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>  arch/arm/cpu/arm1136/start.S                  |    7 +++----
>  arch/arm/cpu/arm1136/u-boot-spl.lds           |    3 ++-
>  arch/arm/cpu/arm720t/start.S                  |   11 +++++++----
>  arch/arm/cpu/arm920t/ep93xx/u-boot.lds        |    6 +++++-
>  arch/arm/cpu/arm926ejs/start.S                |    7 +++----
>  arch/arm/cpu/armv7/am33xx/u-boot-spl.lds      |    2 --
>  arch/arm/cpu/armv7/omap-common/u-boot-spl.lds |    2 --
>  arch/arm/cpu/armv7/socfpga/u-boot-spl.lds     |    1 -
>  arch/arm/cpu/armv7/start.S                    |    6 ++----
>  arch/arm/cpu/ixp/u-boot.lds                   |    6 +++++-
>  arch/arm/cpu/u-boot-spl.lds                   |    3 +--
>  arch/arm/cpu/u-boot.lds                       |    7 +++++--
>  arch/arm/lib/sections.c                       |    4 +++-
>  13 files changed, 36 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
> index ccea2d5..ab8fd56 100644
> --- a/arch/arm/cpu/arm1136/start.S
> +++ b/arch/arm/cpu/arm1136/start.S
> @@ -104,10 +104,6 @@ _TEXT_BASE:
>  _bss_start_ofs:
>  	.word __bss_start - _start
>  
> -.globl _image_copy_end_ofs

Wasn't _image_copy_end_ofs used outside of start.S? Same question for all the
start.S files.

> -_image_copy_end_ofs:
> -	.word __image_copy_end - _start
> -
>  .globl _bss_end_ofs
>  _bss_end_ofs:
>  	.word __bss_end - _start
> @@ -239,6 +235,9 @@ relocate_done:
>  
>  	bx	lr
>  
> +_image_copy_end_ofs:
> +	.word __image_copy_end - _start
> +
>  #ifndef CONFIG_SPL_BUILD
>  
>  _rel_dyn_start_ofs:
> diff --git a/arch/arm/cpu/arm1136/u-boot-spl.lds
> b/arch/arm/cpu/arm1136/u-boot-spl.lds
> index 8296e5d..04fc881 100644
> --- a/arch/arm/cpu/arm1136/u-boot-spl.lds
> +++ b/arch/arm/cpu/arm1136/u-boot-spl.lds
> @@ -37,7 +37,6 @@ SECTIONS
>  {
>  	.text      :
>  	{
> -	__start = .;
>  	  arch/arm/cpu/arm1136/start.o	(.text*)
>  	  *(.text*)
>  	} >.sram
> @@ -48,7 +47,9 @@ SECTIONS
>  	. = ALIGN(4);
>  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
>  	. = ALIGN(4);
> +
>  	__image_copy_end = .;

Why aren't all linker scripts treated equally?

Here, start.S is still used, so '*(.__image_copy_end)' and the related stuff
should be like what you did for arch/arm/cpu/u-boot.lds below. Or am I missing
something?

Same question for several other linker scripts below.

> +
>  	_end = .;
>  
>  	.bss :
[...]
> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> index d9bbee3..5b43621 100644
> --- a/arch/arm/cpu/u-boot.lds
> +++ b/arch/arm/cpu/u-boot.lds
> @@ -33,7 +33,7 @@ SECTIONS
>  	. = ALIGN(4);
>  	.text :
>  	{
> -		__image_copy_start = .;
> +		*(.__image_copy_start)

Are there any users of __image_copy_start?

>  		CPUDIR/start.o (.text*)
>  		*(.text*)
>  	}
> @@ -57,7 +57,10 @@ SECTIONS
>  
>  	. = ALIGN(4);
>  
> -	__image_copy_end = .;
> +	.image_copy_end :
> +	{
> +		*(.__image_copy_end);
> +	}
>  
>  	.rel.dyn : {
>  		__rel_dyn_start = .;
> diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
> index 99eda59..80a0c38 100644
> --- a/arch/arm/lib/sections.c
> +++ b/arch/arm/lib/sections.c
> @@ -21,7 +21,7 @@
>   */
>  
>  /**
> - * These two symbols are declared in a C file so that the linker
> + * The following symbols are declared in a C file so that the linker
>   * uses R_ARM_RELATIVE relocation, rather than the R_ARM_ABS32 one
>   * it would use if the symbols were defined in the linker file.
>   * Using only R_ARM_RELATIVE relocation ensures that references to
> @@ -37,3 +37,5 @@
>  
>  char __bss_start[0] __attribute__((used, section(".__bss_start")));
>  char __bss_end[0] __attribute__((used, section(".__bss_end")));
> +char __image_copy_start[0] __attribute__((used,
> section(".__image_copy_start")));

Ditto.

> +char __image_copy_end[0] __attribute__((used,
> section(".__image_copy_end")));

Best regards,
Beno?t

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

* [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine
  2013-05-10 21:56       ` [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine Albert ARIBAUD
@ 2013-05-11  2:04         ` Benoît Thébaudeau
  2013-05-11  7:40           ` Albert ARIBAUD
  2013-05-11 22:13         ` Simon Glass
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-11  2:04 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Friday, May 10, 2013 11:56:52 PM, Albert ARIBAUD wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>  arch/arm/cpu/arm1136/start.S   |   82 --------------------------------
>  arch/arm/cpu/arm1176/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm720t/start.S   |   82 --------------------------------
>  arch/arm/cpu/arm920t/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm925t/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm926ejs/start.S |   82 --------------------------------
>  arch/arm/cpu/arm946es/start.S  |   75 ------------------------------
>  arch/arm/cpu/arm_intcm/start.S |   75 ------------------------------
>  arch/arm/cpu/armv7/start.S     |   78 -------------------------------
>  arch/arm/cpu/ixp/start.S       |   75 ------------------------------
>  arch/arm/cpu/pxa/start.S       |   84 ---------------------------------
>  arch/arm/cpu/s3c44b0/start.S   |   75 ------------------------------
>  arch/arm/cpu/sa1100/start.S    |   75 ------------------------------
>  arch/arm/lib/Makefile          |    2 +-
>  arch/arm/lib/relocate.S        |  100
>  ++++++++++++++++++++++++++++++++++++++++
>  15 files changed, 101 insertions(+), 1009 deletions(-)
>  create mode 100644 arch/arm/lib/relocate.S
> 

[...]

> diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
> index ada91a6..3078bec 100644
> --- a/arch/arm/cpu/pxa/start.S
> +++ b/arch/arm/cpu/pxa/start.S
> @@ -170,90 +170,6 @@ reset:
>  
>  	bl	_main
>  
> -/*------------------------------------------------------------------------------*/
> -#ifndef CONFIG_SPL_BUILD
> -/*
> - * void relocate_code(addr_moni)
> - *
> - * This function relocates the monitor code.
> - */
> -	.globl	relocate_code
> -relocate_code:
> -	mov	r6, r0	/* save addr of destination */
> -
> -/* Disable the Dcache RAM lock for stack now */
> -#ifdef	CONFIG_CPU_PXA25X
> -	mov	r12, lr
> -	bl	cpu_init_crit
> -	mov	lr, r12
> -#endif

What about this thing that you silently drop?

> -
> -	adr	r0, _start
> -	subs	r9, r6, r0		/* r9 <- relocation offset */
> -	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	    */
> -
> -copy_loop:
> -	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> -	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> -	cmp	r0, r2			/* until source end address [r2]    */
> -	blo	copy_loop
> -
> -#ifndef CONFIG_SPL_BUILD
> -	/*
> -	 * fix .rel.dyn relocations
> -	 */
> -	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
> -	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> -	add	r10, r10, r0		/* r10 <- sym table in FLASH */
> -	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> -	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
> -	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> -	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
> -fixloop:
> -	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
> -	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
> -	ldr	r1, [r2, #4]
> -	and	r7, r1, #0xff
> -	cmp	r7, #23			/* relative fixup? */
> -	beq	fixrel
> -	cmp	r7, #2			/* absolute fixup? */
> -	beq	fixabs
> -	/* ignore unknown type of fixup */
> -	b	fixnext
> -fixabs:
> -	/* absolute fix: set location to (offset) symbol value */
> -	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> -	add	r1, r10, r1		/* r1 <- address of symbol in table */
> -	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> -	add	r1, r1, r9		/* r1 <- relocated sym addr */
> -	b	fixnext
> -fixrel:
> -	/* relative fix: increase location by offset */
> -	ldr	r1, [r0]
> -	add	r1, r1, r9
> -fixnext:
> -	str	r1, [r0]
> -	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> -	cmp	r2, r3
> -	blo	fixloop
> -#endif
> -
> -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
> -
> -#endif
> -
>  	.globl	c_runtime_cpu_setup
>  c_runtime_cpu_setup:
>  

[...]

> diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> new file mode 100644
> index 0000000..ce533ca
> --- /dev/null
> +++ b/arch/arm/lib/relocate.S
> @@ -0,0 +1,100 @@
> +/*
> + *  relocate - common relocation function for ARM U-Boot
> + *
> + *  Copyright (c) 2013  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
> + */
> +
> +/*
> + * These are defined in the board-specific linker script.
> + * Subtracting _start from them lets the linker put their
> + * relative position in the executable instead of leaving
> + * them null.
> + */
> +
> +	.globl	__image_copy_start
> +	.globl	__image_copy_end
> +	.globl	__rel_dyn_start
> +	.globl	__rel_dyn_end
> +	.globl	__dynsym_start

.globl is for exporting symbols to the linker, not importing, so the lines above
should be removed.

> +
> +/*------------------------------------------------------------------------------*/
> +
> +/*
> + * void relocate_code(addr_moni)
> + *
> + * This function relocates the monitor code.
> + */
> +	.globl	relocate_code
> +relocate_code:

Or "ENTRY(relocate_code)" instead of the two lines above.

> +	mov	r6, r0	/* save addr of destination */
> +
> +	ldr	r0, =_start

This is wrong. Here, r0 will get _start link-time address, while with 'adr' in
the original code, r0 was getting _start runtime address, which is not the same
for all boards. relocate_code() is and must stay position-independent code, at
least for SPL.

E.g., for mx31pdk or tx25, the SPL is first loaded by the boot ROM in the NAND
Flash controller buffer, then executed from there. The SPL then has to use
relocate_code() to relocate itself to CONFIG_SPL_TEXT_BASE in order to free the
NFC buffer to load U-Boot from NAND Flash. This means that 'ldr r0, =_start'
would set r0 to CONFIG_SPL_TEXT_BASE, while 'adr r0, _start' sets r0 to the
address of the NFC buffer. Since the SPL calls relocate_code() with
CONFIG_SPL_TEXT_BASE, the 'ldr' choice would just result in a branch to
relocate_done below, which would abort the relocation and break the boot on
those boards.

The issue is that 'adr' requires that _start be defined in the same file and
section. That's why my patch 31/31 was using a macro to define relocate_code()
in the start.S files. Perhaps some other constructs like
'sub r0, pc, . - _start' would work, but I doubt it if _start is not in the same
file and section since this is exactly how 'adr' is translated.

> +	subs	r9, r6, r0		/* r9 <- relocation offset */
> +	beq	relocate_done		/* skip relocation */
> +	mov	r1, r6			/* r1 <- scratch for copy_loop */
> +	ldr	r2, =__image_copy_end
> +
> +copy_loop:
> +	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> +	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> +	cmp	r0, r2			/* until source end address [r2]    */
> +	blo	copy_loop
> +
> +#ifndef CONFIG_SPL_BUILD
> +	/*
> +	 * fix .rel.dyn relocations
> +	 */
> +	ldr	r0, =_TEXT_BASE		/* r0 <- Text base */

The value you load above into r0 then gets overwritten prior to having been
used, so you can drop this line, all the more it is wrong, loading the address
of _TEXT_BASE instead of its value.

> +	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
> +	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
> +	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */

'ofs' should be replaced with 'in FLASH' in the comments above.

Contrary to above, this construct works here because this can't be SPL code.

> +fixloop:
> +	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
> +	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
> +	ldr	r1, [r2, #4]
> +	and	r7, r1, #0xff
> +	cmp	r7, #23			/* relative fixup? */
> +	beq	fixrel
> +	cmp	r7, #2			/* absolute fixup? */
> +	beq	fixabs
> +	/* ignore unknown type of fixup */
> +	b	fixnext
> +fixabs:
> +	/* absolute fix: set location to (offset) symbol value */
> +	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> +	add	r1, r10, r1		/* r1 <- address of symbol in table */
> +	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> +	add	r1, r1, r9		/* r1 <- relocated sym addr */
> +	b	fixnext
> +fixrel:
> +	/* relative fix: increase location by offset */
> +	ldr	r1, [r0]
> +	add	r1, r1, r9
> +fixnext:
> +	str	r1, [r0]
> +	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> +	cmp	r2, r3
> +	blo	fixloop
> +#endif
> +
> +relocate_done:
> +
> +	bx	lr

This instruction is not supported on ARMv4, even if GCC does not complain about
it (it looks like this is not even fixed by the linker, except if the
instruction was issued by GCC itself), but it is required for more recent ARM
versions for Thumb inter-working, which is enabled by some boards in U-Boot.
Hence, shouldn't the line above be replaced with:

#ifdef __ARM_ARCH_4__
        mov        pc, lr
#else
        bx        lr
#endif

Or using CONFIG_SYS_THUMB_BUILD?

"ENDPROC(relocate_code)" should be added here if you go for ENTRY() at the
beginning.

Best regards,
Beno?t

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

* [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine
  2013-05-11  2:04         ` Benoît Thébaudeau
@ 2013-05-11  7:40           ` Albert ARIBAUD
  2013-05-11 13:40             ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-11  7:40 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Sat, 11 May 2013 04:04:09 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Friday, May 10, 2013 11:56:52 PM, Albert ARIBAUD wrote:
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

> > diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
> > index ada91a6..3078bec 100644
> > --- a/arch/arm/cpu/pxa/start.S
> > +++ b/arch/arm/cpu/pxa/start.S
> > @@ -170,90 +170,6 @@ reset:
> >  
> >  	bl	_main
> >  
> > -/*------------------------------------------------------------------------------*/
> > -#ifndef CONFIG_SPL_BUILD
> > -/*
> > - * void relocate_code(addr_moni)
> > - *
> > - * This function relocates the monitor code.
> > - */
> > -	.globl	relocate_code
> > -relocate_code:
> > -	mov	r6, r0	/* save addr of destination */
> > -
> > -/* Disable the Dcache RAM lock for stack now */
> > -#ifdef	CONFIG_CPU_PXA25X
> > -	mov	r12, lr
> > -	bl	cpu_init_crit
> > -	mov	lr, r12
> > -#endif  
> 
> What about this thing that you silently drop?

Overlook on my side, and PXA is not one of my test vehicles so I
missed it while testing. Will 'undrop' in V2.

> > diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> > new file mode 100644
> > index 0000000..ce533ca
> > --- /dev/null
> > +++ b/arch/arm/lib/relocate.S
> > @@ -0,0 +1,100 @@
> > +/*
> > + *  relocate - common relocation function for ARM U-Boot
> > + *
> > + *  Copyright (c) 2013  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
> > + */
> > +
> > +/*
> > + * These are defined in the board-specific linker script.
> > + * Subtracting _start from them lets the linker put their
> > + * relative position in the executable instead of leaving
> > + * them null.
> > + */
> > +
> > +	.globl	__image_copy_start
> > +	.globl	__image_copy_end
> > +	.globl	__rel_dyn_start
> > +	.globl	__rel_dyn_end
> > +	.globl	__dynsym_start
> 
> .globl is for exporting symbols to the linker, not importing, so the lines above
> should be removed.

correct. Will drop in V2.

> > +
> > +/*------------------------------------------------------------------------------*/
> > +
> > +/*
> > + * void relocate_code(addr_moni)
> > + *
> > + * This function relocates the monitor code.
> > + */
> > +	.globl	relocate_code
> > +relocate_code:
> 
> Or "ENTRY(relocate_code)" instead of the two lines above.

I'd gone for just moving code around rather than cosmetic, but I can do
the cosmetic change at the end of the patch too.

> > +	mov	r6, r0	/* save addr of destination */
> > +
> > +	ldr	r0, =_start
> 
> This is wrong. Here, r0 will get _start link-time address, while with 'adr' in
> the original code, r0 was getting _start runtime address, which is not the same
> for all boards. relocate_code() is and must stay position-independent code, at
> least for SPL.
> 
> E.g., for mx31pdk or tx25, the SPL is first loaded by the boot ROM
in the NAND
> Flash controller buffer, then executed from there. The SPL then has to use
> relocate_code() to relocate itself to CONFIG_SPL_TEXT_BASE in order to free the
> NFC buffer to load U-Boot from NAND Flash. This means that 'ldr r0, =_start'
> would set r0 to CONFIG_SPL_TEXT_BASE, while 'adr r0, _start' sets r0 to the
> address of the NFC buffer. Since the SPL calls relocate_code() with
> CONFIG_SPL_TEXT_BASE, the 'ldr' choice would just result in a branch to
> relocate_done below, which would abort the relocation and break the boot on
> those boards.
> 
> The issue is that 'adr' requires that _start be defined in the same file and
> section. That's why my patch 31/31 was using a macro to define relocate_code()
> in the start.S files. Perhaps some other constructs like
> 'sub r0, pc, . - _start' would work, but I doubt it if _start is not in the same
> file and section since this is exactly how 'adr' is translated.

Alright, so -- formally, there is no assumption that code running before
relocation must be position-independent, as far as I remember. The
assumption is that it is designed to run at the link-time location, and
that it is responsible for making sure that the rest of the code is
properly relocated and thus will run at whatever location it was moved
to.

In the case you mention, SPL does not relocate itself: it only *moves*
itself, skipping the actual relocation (reference fixing part) -- it
could havdoe so with a short ad hoc loop instead of relocate_code, and
thus not impose a specific requirement on relocate_code that was not
initially there. I'd be happier with a preprocessor conditional at the
crt0.S stage to choose between relocate_code and a new, short,
move_code routine depending on whether we are building SPL or not.

That being said, I am fine with trying to make the code before
relocation as position-independent as possible anyway; let me see how
this can be done.

> > +	subs	r9, r6, r0		/* r9 <- relocation offset */
> > +	beq	relocate_done		/* skip relocation */
> > +	mov	r1, r6			/* r1 <- scratch for copy_loop */
> > +	ldr	r2, =__image_copy_end
> > +
> > +copy_loop:
> > +	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> > +	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> > +	cmp	r0, r2			/* until source end address [r2]    */
> > +	blo	copy_loop
> > +
> > +#ifndef CONFIG_SPL_BUILD
> > +	/*
> > +	 * fix .rel.dyn relocations
> > +	 */
> > +	ldr	r0, =_TEXT_BASE		/* r0 <- Text base */
> 
> The value you load above into r0 then gets overwritten prior to having been
> used, so you can drop this line, all the more it is wrong, loading the address
> of _TEXT_BASE instead of its value.

Correct. Will fix in V2.

> > +	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
> > +	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
> > +	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */
> 
> 'ofs' should be replaced with 'in FLASH' in the comments above.
> 
> Contrary to above, this construct works here because this can't be SPL code.

Actually, this would not work either if used by non-SPL code as SPL code
expects to use it, e.g. by loading U-Boot at another address -- the
issue is in the use scenario, not in the requirements for SPL vs.
U-Boot.

> > +relocate_done:
> > +
> > +	bx	lr
> 
> This instruction is not supported on ARMv4, even if GCC does not complain about
> it (it looks like this is not even fixed by the linker, except if the
> instruction was issued by GCC itself), but it is required for more recent ARM
> versions for Thumb inter-working, which is enabled by some boards in U-Boot.
> Hence, shouldn't the line above be replaced with:
> 
> #ifdef __ARM_ARCH_4__
>         mov        pc, lr
> #else
>         bx        lr
> #endif
> 
> Or using CONFIG_SYS_THUMB_BUILD?

I would have preferred adding --fix-v4bx to the linker flags for ARMv4
targets, but it seems to have no effect at least with some toolchains.
I'll fix the code above with the ARMv4 conditional, as it is always
correct regardless of U-boot configuration options semantics.

> "ENDPROC(relocate_code)" should be added here if you go for ENTRY() at the
> beginning.

Ok.

> Best regards,
> Beno?t

Thanks for your review!

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-11  0:25     ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Benoît Thébaudeau
@ 2013-05-11  8:02       ` Albert ARIBAUD
  2013-05-11 17:52         ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-11  8:02 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Sat, 11 May 2013 02:25:02 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,

> > diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
> > index ccea2d5..ab8fd56 100644
> > --- a/arch/arm/cpu/arm1136/start.S
> > +++ b/arch/arm/cpu/arm1136/start.S
> > @@ -104,10 +104,6 @@ _TEXT_BASE:
> >  _bss_start_ofs:
> >  	.word __bss_start - _start
> >  
> > -.globl _image_copy_end_ofs
> 
> Wasn't _image_copy_end_ofs used outside of start.S? Same question for all the
> start.S files.

No -- and the build would have failed if it was. The only user of
__image_copy_end_ofs is the start.S which defines it, and only for the
purpose of preventing the assembler from generating an R_ARM_ABS32
relocation to __image_copy_end.

> > diff --git a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > index 8296e5d..04fc881 100644
> > --- a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > +++ b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > @@ -37,7 +37,6 @@ SECTIONS
> >  {
> >  	.text      :
> >  	{
> > -	__start = .;
> >  	  arch/arm/cpu/arm1136/start.o	(.text*)
> >  	  *(.text*)
> >  	} >.sram
> > @@ -48,7 +47,9 @@ SECTIONS
> >  	. = ALIGN(4);
> >  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
> >  	. = ALIGN(4);
> > +
> >  	__image_copy_end = .;
> 
> Why aren't all linker scripts treated equally?
> 
> Here, start.S is still used, so '*(.__image_copy_end)' and the related stuff
> should be like what you did for arch/arm/cpu/u-boot.lds below. Or am I missing
> something?
> 
> Same question for several other linker scripts below.

Not all SPLs use relocation -- actually, most SPLs do not use
relocation, and thus do not need image and relocaton section symbols.

> > diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> > index d9bbee3..5b43621 100644
> > --- a/arch/arm/cpu/u-boot.lds
> > +++ b/arch/arm/cpu/u-boot.lds
> > @@ -33,7 +33,7 @@ SECTIONS
> >  	. = ALIGN(4);
> >  	.text :
> >  	{
> > -		__image_copy_start = .;
> > +		*(.__image_copy_start)
> 
> Are there any users of __image_copy_start?

(see below)

> > diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
> > index 99eda59..80a0c38 100644
> > --- a/arch/arm/lib/sections.c
> +++ b/arch/arm/lib/sections.c

> > @@ -37,3 +37,5 @@
> >  
> >  char __bss_start[0] __attribute__((used, section(".__bss_start")));
> >  char __bss_end[0] __attribute__((used, section(".__bss_end")));
> > +char __image_copy_start[0] __attribute__((used,
> > section(".__image_copy_start")));
> 
> Ditto.

The only user of __image_copy_start is the relocation routine which
uses _start but should actually use __image_copy_start (will fix in V2),
to match with the semantics introduced when fixing CONFIG_SPL_MAX_SIZE
semantics in 6ebc3461.
 
> Best regards,
> Beno?t

Thanks for your review!

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine
  2013-05-11  7:40           ` Albert ARIBAUD
@ 2013-05-11 13:40             ` Benoît Thébaudeau
  0 siblings, 0 replies; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-11 13:40 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Saturday, May 11, 2013 9:40:02 AM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Sat, 11 May 2013 04:04:09 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Friday, May 10, 2013 11:56:52 PM, Albert ARIBAUD wrote:
> > > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

[...]

> > > +	mov	r6, r0	/* save addr of destination */
> > > +
> > > +	ldr	r0, =_start
> > 
> > This is wrong. Here, r0 will get _start link-time address, while with 'adr'
> > in
> > the original code, r0 was getting _start runtime address, which is not the
> > same
> > for all boards. relocate_code() is and must stay position-independent code,
> > at
> > least for SPL.
> > 
> > E.g., for mx31pdk or tx25, the SPL is first loaded by the boot ROM
> in the NAND
> > Flash controller buffer, then executed from there. The SPL then has to use
> > relocate_code() to relocate itself to CONFIG_SPL_TEXT_BASE in order to free
> > the
> > NFC buffer to load U-Boot from NAND Flash. This means that 'ldr r0,
> > =_start'
> > would set r0 to CONFIG_SPL_TEXT_BASE, while 'adr r0, _start' sets r0 to the
> > address of the NFC buffer. Since the SPL calls relocate_code() with
> > CONFIG_SPL_TEXT_BASE, the 'ldr' choice would just result in a branch to
> > relocate_done below, which would abort the relocation and break the boot on
> > those boards.
> > 
> > The issue is that 'adr' requires that _start be defined in the same file
> > and
> > section. That's why my patch 31/31 was using a macro to define
> > relocate_code()
> > in the start.S files. Perhaps some other constructs like
> > 'sub r0, pc, . - _start' would work, but I doubt it if _start is not in the
> > same
> > file and section since this is exactly how 'adr' is translated.
> 
> Alright, so -- formally, there is no assumption that code running before
> relocation must be position-independent, as far as I remember. The
> assumption is that it is designed to run at the link-time location, and
> that it is responsible for making sure that the rest of the code is
> properly relocated and thus will run at whatever location it was moved
> to.
> 
> In the case you mention, SPL does not relocate itself: it only *moves*
> itself, skipping the actual relocation (reference fixing part) -- it
> could havdoe so with a short ad hoc loop instead of relocate_code, and
> thus not impose a specific requirement on relocate_code that was not
> initially there. I'd be happier with a preprocessor conditional at the
> crt0.S stage to choose between relocate_code and a new, short,
> move_code routine depending on whether we are building SPL or not.
> 
> That being said, I am fine with trying to make the code before
> relocation as position-independent as possible anyway; let me see how
> this can be done.

OK, I let you try something. Otherwise, I agree with what you say above. The
original code for the non-SPL part below is not position-independent, so it is
safe to assume that only the beginning of relocate_code() (before
'#ifndef CONFIG_SPL_BUILD') should be position-independent, and only for SPL. It
is also probably true that the initial runtime address of all SPLs is known at
build time, so a new CONFIG_SPL_ could be created for that purpose and used in a
dedicated small SPL copy routine, which would also make the need for SPL move
testable at build time, and solve the 'adr' vs. 'ldr' issue.

> > > +	subs	r9, r6, r0		/* r9 <- relocation offset */
> > > +	beq	relocate_done		/* skip relocation */
> > > +	mov	r1, r6			/* r1 <- scratch for copy_loop */
> > > +	ldr	r2, =__image_copy_end
> > > +
> > > +copy_loop:
> > > +	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> > > +	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> > > +	cmp	r0, r2			/* until source end address [r2]    */
> > > +	blo	copy_loop
> > > +
> > > +#ifndef CONFIG_SPL_BUILD
> > > +	/*
> > > +	 * fix .rel.dyn relocations
> > > +	 */
> > > +	ldr	r0, =_TEXT_BASE		/* r0 <- Text base */
> > 
> > The value you load above into r0 then gets overwritten prior to having been
> > used, so you can drop this line, all the more it is wrong, loading the
> > address
> > of _TEXT_BASE instead of its value.
> 
> Correct. Will fix in V2.
> 
> > > +	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
> > > +	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
> > > +	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */
> > 
> > 'ofs' should be replaced with 'in FLASH' in the comments above.
> > 
> > Contrary to above, this construct works here because this can't be SPL
> > code.
> 
> Actually, this would not work either if used by non-SPL code as SPL code
> expects to use it, e.g. by loading U-Boot at another address -- the
> issue is in the use scenario, not in the requirements for SPL vs.
> U-Boot.

Right, but this new code behaves exactly in the same way as the original code,
so it is safe to assume that there is no such use scenario. This new code just
can't introduce a regression.

> > > +relocate_done:
> > > +
> > > +	bx	lr
> > 
> > This instruction is not supported on ARMv4, even if GCC does not complain
> > about
> > it (it looks like this is not even fixed by the linker, except if the
> > instruction was issued by GCC itself), but it is required for more recent
> > ARM
> > versions for Thumb inter-working, which is enabled by some boards in
> > U-Boot.
> > Hence, shouldn't the line above be replaced with:
> > 
> > #ifdef __ARM_ARCH_4__
> >         mov        pc, lr
> > #else
> >         bx        lr
> > #endif
> > 
> > Or using CONFIG_SYS_THUMB_BUILD?
> 
> I would have preferred adding --fix-v4bx to the linker flags for ARMv4
> targets, but it seems to have no effect at least with some toolchains.

Indeed.

> I'll fix the code above with the ARMv4 conditional, as it is always
> correct regardless of U-boot configuration options semantics.
> 
> > "ENDPROC(relocate_code)" should be added here if you go for ENTRY() at the
> > beginning.
> 
> Ok.
> 
> > Best regards,
> > Beno?t
> 
> Thanks for your review!

You're welcome.

Best regards,
Beno?t

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-11  8:02       ` Albert ARIBAUD
@ 2013-05-11 17:52         ` Benoît Thébaudeau
  2013-05-11 20:13           ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-11 17:52 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Saturday, May 11, 2013 10:02:48 AM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Sat, 11 May 2013 02:25:02 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,

[...]

> > > diff --git a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > index 8296e5d..04fc881 100644
> > > --- a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > +++ b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > @@ -37,7 +37,6 @@ SECTIONS
> > >  {
> > >  	.text      :
> > >  	{
> > > -	__start = .;
> > >  	  arch/arm/cpu/arm1136/start.o	(.text*)
> > >  	  *(.text*)
> > >  	} >.sram
> > > @@ -48,7 +47,9 @@ SECTIONS
> > >  	. = ALIGN(4);
> > >  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
> > >  	. = ALIGN(4);
> > > +
> > >  	__image_copy_end = .;
> > 
> > Why aren't all linker scripts treated equally?
> > 
> > Here, start.S is still used, so '*(.__image_copy_end)' and the related
> > stuff
> > should be like what you did for arch/arm/cpu/u-boot.lds below. Or am I
> > missing
> > something?
> > 
> > Same question for several other linker scripts below.
> 
> Not all SPLs use relocation -- actually, most SPLs do not use
> relocation, and thus do not need image and relocaton section symbols.

Then, why do you keep the old definition of __image_copy_end in such linker
scripts? Probably because start.S can't be linked in otherwise, but this is no
longer true at the end of this series with the new relocate.S that is garbage-
collected for those SPLs. And in all cases, shouldn't all linker scripts
requiring __image_copy_end be converted to the new definition?

[...]

Best regards,
Beno?t

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-11 17:52         ` Benoît Thébaudeau
@ 2013-05-11 20:13           ` Albert ARIBAUD
  2013-05-12  8:57             ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-11 20:13 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Sat, 11 May 2013 19:52:17 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Saturday, May 11, 2013 10:02:48 AM, Albert ARIBAUD wrote:
> > Hi Beno?t,
> > 
> > On Sat, 11 May 2013 02:25:02 +0200 (CEST), Beno?t Th?baudeau
> > <benoit.thebaudeau@advansee.com> wrote:
> > 
> > > Hi Albert,
> 
> [...]
> 
> > > > diff --git a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > > b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > > index 8296e5d..04fc881 100644
> > > > --- a/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > > +++ b/arch/arm/cpu/arm1136/u-boot-spl.lds
> > > > @@ -37,7 +37,6 @@ SECTIONS
> > > >  {
> > > >  	.text      :
> > > >  	{
> > > > -	__start = .;
> > > >  	  arch/arm/cpu/arm1136/start.o	(.text*)
> > > >  	  *(.text*)
> > > >  	} >.sram
> > > > @@ -48,7 +47,9 @@ SECTIONS
> > > >  	. = ALIGN(4);
> > > >  	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
> > > >  	. = ALIGN(4);
> > > > +
> > > >  	__image_copy_end = .;
> > > 
> > > Why aren't all linker scripts treated equally?
> > > 
> > > Here, start.S is still used, so '*(.__image_copy_end)' and the related
> > > stuff
> > > should be like what you did for arch/arm/cpu/u-boot.lds below. Or am I
> > > missing
> > > something?
> > > 
> > > Same question for several other linker scripts below.
> > 
> > Not all SPLs use relocation -- actually, most SPLs do not use
> > relocation, and thus do not need image and relocaton section symbols.
> 
> Then, why do you keep the old definition of __image_copy_end in such linker
> scripts? Probably because start.S can't be linked in otherwise, but this is no
> longer true at the end of this series with the new relocate.S that is garbage-
> collected for those SPLs. And in all cases, shouldn't all linker scripts
> requiring __image_copy_end be converted to the new definition?

You are right on both accounts: all linker scripts that need
__image_copy_* should be converted to the new definition, and some
linker scripts probably don't need __image_copy_end even though they
define it. I intend to achieve this, not by editing various linker
scripts, but by factoring them into a single linker script (or two at
most, one for U-boot and one for SPL). So I prefer to do as little work
on the scripts as possible right now; here, only what's needed for
relocation factoring to work.

Hence, if an SPL script sort-of-hardcodes image start and end (or
relocation symbols as some do), then I prefer to leave it alone for now
and handle in the linker script factoring series later.

(on an unrelated note, V2 will have an additional patch removing
absolute relocation record type support in relocate_code, as it should
be useless now too. But I'll pair this removal with a build step that
makes sure the ELF u-boot and SPL binaries only have R_ARM_RELATIVE
relocation records.)

> Best regards,
> Beno?t


Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine
  2013-05-10 21:56       ` [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine Albert ARIBAUD
  2013-05-11  2:04         ` Benoît Thébaudeau
@ 2013-05-11 22:13         ` Simon Glass
  1 sibling, 0 replies; 64+ messages in thread
From: Simon Glass @ 2013-05-11 22:13 UTC (permalink / raw)
  To: u-boot

On Fri, May 10, 2013 at 3:56 PM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
>
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>  arch/arm/cpu/arm1136/start.S   |   82 --------------------------------
>  arch/arm/cpu/arm1176/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm720t/start.S   |   82 --------------------------------
>  arch/arm/cpu/arm920t/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm925t/start.S   |   75 ------------------------------
>  arch/arm/cpu/arm926ejs/start.S |   82 --------------------------------
>  arch/arm/cpu/arm946es/start.S  |   75 ------------------------------
>  arch/arm/cpu/arm_intcm/start.S |   75 ------------------------------
>  arch/arm/cpu/armv7/start.S     |   78 -------------------------------
>  arch/arm/cpu/ixp/start.S       |   75 ------------------------------
>  arch/arm/cpu/pxa/start.S       |   84 ---------------------------------
>  arch/arm/cpu/s3c44b0/start.S   |   75 ------------------------------
>  arch/arm/cpu/sa1100/start.S    |   75 ------------------------------
>  arch/arm/lib/Makefile          |    2 +-
>  arch/arm/lib/relocate.S        |  100 ++++++++++++++++++++++++++++++++++++++++
>  15 files changed, 101 insertions(+), 1009 deletions(-)
>  create mode 100644 arch/arm/lib/relocate.S
>

I tested this series on snow (Exynos 5250, ARMv7, with SPL) with no
apparent regressions.

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

Regards,
Simon

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

* [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated
  2013-05-11 20:13           ` Albert ARIBAUD
@ 2013-05-12  8:57             ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-12  8:57 UTC (permalink / raw)
  To: u-boot

On Sat, 11 May 2013 22:13:51 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> Hence, if an SPL script sort-of-hardcodes image start and end (or
> relocation symbols as some do), then I prefer to leave it alone for now
> and handle in the linker script factoring series later.

... but I do realize in some cases I removed __image_copy_end and in
others I didn't. I'll go over this again in V2 by following the
rule of least change -- not doing a change unless required by the
objective of the series, that is, factoring relocate code.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances
  2013-05-10 21:56 [U-Boot] [PATCH 0/4] Factorize ARM relocation code Albert ARIBAUD
  2013-05-10 21:56 ` [U-Boot] [PATCH 1/4] Rename arch/arm/lib/bss.c to sections.c Albert ARIBAUD
@ 2013-05-14  9:50 ` Albert ARIBAUD
  2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
                     ` (2 more replies)
  1 sibling, 3 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:50 UTC (permalink / raw)
  To: u-boot

This series replaces all instances of relocate_code in
various start.S files from the ARM architecture with a
single instance in arch/arm/lib/relocate.S.

This is done in steps, each step keeping the whole of ARM
U-Boot buildable and runnable and touching as little code
as necessary.

1. Drop mx31pdk SPL call to relocate_code

In SPL of mx31pdk, board_init_f calls relocate_code to
move SPL from the NAND read buffer to SRAM. This move
is not a relocation and is thus better implemented as
a simple ad hoc copy loop.

2. Drop tx25 SPL call to relocate_code

Same as mx31pdk.

3. Prevent all SPLs from assembling relocate_code

Now that no SPL uses relocate_code any more, remove
it completely from SPL builds by putting it entirely
between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
conditional.

4. Actual factorization of relocate_code

Remove all instances of relocate_code from start.S and
create a new file, arch/arm/lib/relocate.S, to provide
the new single instance of relocate_code.

The only non-trivial change is that for PXA25X, a call
to unlock (actually disable) dcache is moved from before
relocating to after relocating. As this cache is either
locked-as-RAM or disabled, but never used as actual DDR
cache, this move has no performance effect on relocation
and no functional impact either.

Changes in v2:
- dropped relocate_code() call from mx31pdk SPL
- dropped relocate_code() call from tx25 SPL
- dropped all relocate_code instances from SPL builds
- use ENTRY / ENDPROC macros
- preserve PXA25X dcache unlocking

Albert ARIBAUD (4):
  mx31pdk: copy SPL directly, not using relocate_code.
  tx25: copy SPL directly, not using relocate_code.
  arm: do not compile relocate_code() for SPL builds
  arm: factorize relocate_code routine

 arch/arm/cpu/arm1136/start.S      |   81 ---------------------------
 arch/arm/cpu/arm1176/start.S      |   77 -------------------------
 arch/arm/cpu/arm720t/start.S      |   77 -------------------------
 arch/arm/cpu/arm920t/start.S      |   77 -------------------------
 arch/arm/cpu/arm925t/start.S      |   77 -------------------------
 arch/arm/cpu/arm926ejs/start.S    |   81 ---------------------------
 arch/arm/cpu/arm946es/start.S     |   77 -------------------------
 arch/arm/cpu/arm_intcm/start.S    |   77 -------------------------
 arch/arm/cpu/armv7/start.S        |   78 --------------------------
 arch/arm/cpu/ixp/start.S          |   77 -------------------------
 arch/arm/cpu/pxa/start.S          |   96 +++-----------------------------
 arch/arm/cpu/s3c44b0/start.S      |   77 -------------------------
 arch/arm/cpu/sa1100/start.S       |   77 -------------------------
 arch/arm/lib/Makefile             |    1 +
 arch/arm/lib/relocate.S           |  111 +++++++++++++++++++++++++++++++++++++
 board/freescale/mx31pdk/mx31pdk.c |   16 +++++-
 board/karo/tx25/tx25.c            |   16 +++++-
 17 files changed, 151 insertions(+), 1022 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

-- 
1.7.10.4

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

* [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
@ 2013-05-14  9:50   ` Albert ARIBAUD
  2013-05-14  9:50     ` [U-Boot] [PATCH v2 2/4] tx25: " Albert ARIBAUD
  2013-05-14 15:14     ` [U-Boot] [PATCH v2 1/4] mx31pdk: " Benoît Thébaudeau
  2013-05-14  9:55   ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:50 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- dropped relocate_code() call from mx31pdk SPL

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

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

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

* [U-Boot] [PATCH v2 2/4] tx25: copy SPL directly, not using relocate_code.
  2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-14  9:50     ` Albert ARIBAUD
  2013-05-14  9:50       ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
  2013-05-14 15:15       ` [U-Boot] [PATCH v2 2/4] tx25: copy SPL directly, not using relocate_code Benoît Thébaudeau
  2013-05-14 15:14     ` [U-Boot] [PATCH v2 1/4] mx31pdk: " Benoît Thébaudeau
  1 sibling, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:50 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- dropped relocate_code() call from tx25 SPL

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

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

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

* [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-14  9:50     ` [U-Boot] [PATCH v2 2/4] tx25: " Albert ARIBAUD
@ 2013-05-14  9:50       ` Albert ARIBAUD
  2013-05-14  9:50         ` [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine Albert ARIBAUD
  2013-05-14 15:21         ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Benoît Thébaudeau
  2013-05-14 15:15       ` [U-Boot] [PATCH v2 2/4] tx25: copy SPL directly, not using relocate_code Benoît Thébaudeau
  1 sibling, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:50 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- dropped all relocate_code instances from SPL builds

 arch/arm/cpu/arm1136/start.S   |   11 +++--------
 arch/arm/cpu/arm1176/start.S   |   11 +++++------
 arch/arm/cpu/arm720t/start.S   |   11 +++++------
 arch/arm/cpu/arm920t/start.S   |   12 +++++-------
 arch/arm/cpu/arm925t/start.S   |   11 +++++------
 arch/arm/cpu/arm926ejs/start.S |   11 +++--------
 arch/arm/cpu/arm946es/start.S  |   11 +++++------
 arch/arm/cpu/arm_intcm/start.S |   11 +++++------
 arch/arm/cpu/armv7/start.S     |    6 ++----
 arch/arm/cpu/ixp/start.S       |   11 +++++------
 arch/arm/cpu/pxa/start.S       |    8 ++------
 arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
 arch/arm/cpu/sa1100/start.S    |   11 +++++------
 13 files changed, 55 insertions(+), 81 deletions(-)

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index ccea2d5..1eec2e0 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -104,10 +104,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -173,6 +169,7 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -195,7 +192,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -233,14 +229,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index f20da8e..3c2a52c 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -112,10 +112,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -225,6 +221,7 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -247,7 +244,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -285,12 +281,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -298,6 +295,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 9facc7e..983f8ad 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 6250025..889329f 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -89,10 +89,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -194,6 +190,7 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -216,7 +213,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -254,12 +250,12 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
-
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -267,6 +263,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 021e241..64e8ae5 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -95,10 +95,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -184,6 +180,7 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -206,7 +203,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -244,12 +240,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -257,6 +254,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 4c56711..d5c4ab2 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -136,10 +136,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -190,6 +186,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -212,7 +209,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -250,14 +246,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 9c2b70d..2fc730c 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -105,10 +105,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -159,6 +155,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -181,7 +178,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -219,12 +215,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -232,6 +229,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index 5e8c528..c483b53 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index e9e57e6..3ade510 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -94,10 +94,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -231,6 +227,8 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 69ef8aa..8458f45 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -114,10 +114,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -257,6 +253,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -279,7 +276,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -317,12 +313,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -330,6 +327,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index ada91a6..595778a 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -118,10 +118,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -201,7 +197,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -239,12 +234,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 7361aa2..33a0a81 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -80,10 +80,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -140,6 +136,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -162,7 +159,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -200,12 +196,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -213,6 +210,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 8a2eafd..e0c45d6 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -90,10 +90,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -144,6 +140,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -166,7 +163,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -204,12 +200,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -217,6 +214,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
-- 
1.7.10.4

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14  9:50       ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
@ 2013-05-14  9:50         ` Albert ARIBAUD
  2013-05-14 16:01           ` Benoît Thébaudeau
  2013-05-14 15:21         ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Benoît Thébaudeau
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:50 UTC (permalink / raw)
  To: u-boot

Replace all relocate_code routines from ARM start.S files
with a single instance in file arch/arm/lib/relocate.S.
For PXA, this requires moving the dcache unlocking code
from within relocate_code into c_runtime_cpu_setup.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v2:
- use ENTRY / ENDPROC macros
- preserve PXA25X dcache unlocking

 arch/arm/cpu/arm1136/start.S   |   76 ---------------------------
 arch/arm/cpu/arm1176/start.S   |   76 ---------------------------
 arch/arm/cpu/arm720t/start.S   |   76 ---------------------------
 arch/arm/cpu/arm920t/start.S   |   75 ---------------------------
 arch/arm/cpu/arm925t/start.S   |   76 ---------------------------
 arch/arm/cpu/arm926ejs/start.S |   76 ---------------------------
 arch/arm/cpu/arm946es/start.S  |   76 ---------------------------
 arch/arm/cpu/arm_intcm/start.S |   76 ---------------------------
 arch/arm/cpu/armv7/start.S     |   76 ---------------------------
 arch/arm/cpu/ixp/start.S       |   76 ---------------------------
 arch/arm/cpu/pxa/start.S       |   92 ++++-----------------------------
 arch/arm/cpu/s3c44b0/start.S   |   76 ---------------------------
 arch/arm/cpu/sa1100/start.S    |   76 ---------------------------
 arch/arm/lib/Makefile          |    1 +
 arch/arm/lib/relocate.S        |  111 ++++++++++++++++++++++++++++++++++++++++
 15 files changed, 121 insertions(+), 994 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 1eec2e0..edf249d 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -169,82 +169,6 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 3c2a52c..65292bc 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -221,82 +221,6 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 983f8ad..a0444de 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 889329f..3232065 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -190,81 +190,6 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 64e8ae5..97eb276 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -180,82 +180,6 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index d5c4ab2..5fc8e04 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -186,82 +186,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 2fc730c..e9d0c34 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -155,82 +155,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index c483b53..8dfd919 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 3ade510..8e9cb19 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -163,82 +163,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-ENTRY(relocate_code)
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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)
-
-#endif
-
 ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 8458f45..46cba0c 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -253,82 +253,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 595778a..f9947de 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -167,93 +167,19 @@ reset:
 	bl	_main
 
 /*------------------------------------------------------------------------------*/
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-/* Disable the Dcache RAM lock for stack now */
-#ifdef	CONFIG_CPU_PXA25X
-	mov	r12, lr
-	bl	cpu_init_crit
-	mov	lr, r12
-#endif
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
 
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
-	bx	lr
+	/*
+	 * Unlock (actually, disable) the cache now that board_init_f
+	 * is done. We could do this earlier but we would need to add
+	 * a new C runtime hook, whereas c_runtime_cpu_setup already
+	 * exists.
+	 * As this routine is just a call to cpu_init_crit, let us
+	 * tail-optimize and do a simple branch here.
+	 */
+	b	cpu_init_crit
 
 /*
  *************************************************************************
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 33a0a81..78183fc 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -136,82 +136,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index e0c45d6..30d5a90 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -140,82 +140,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6ae161a..30e3290 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -39,6 +39,7 @@ GLCOBJS	+= div0.o
 SOBJS-y += crt0.o
 
 ifndef CONFIG_SPL_BUILD
+SOBJS-y += relocate.o
 ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
 endif
diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
new file mode 100644
index 0000000..9e91fae
--- /dev/null
+++ b/arch/arm/lib/relocate.S
@@ -0,0 +1,111 @@
+/*
+ *  relocate - common relocation function for ARM U-Boot
+ *
+ *  Copyright (c) 2013  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 <linux/linkage.h>
+
+/*
+ * These are defined in the board-specific linker script.
+ * Subtracting _start from them lets the linker put their
+ * relative position in the executable instead of leaving
+ * them null.
+ */
+
+/*
+ * void relocate_code(addr_moni)
+ *
+ * This function relocates the monitor code.
+ */
+ENTRY(relocate_code)
+	mov	r6, r0	/* save addr of destination */
+
+	ldr	r0, =_start
+	subs	r9, r6, r0		/* r9 <- relocation offset */
+	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	    */
+
+copy_loop:
+	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
+	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
+	cmp	r0, r2			/* until source end address [r2]    */
+	blo	copy_loop
+
+	/*
+	 * fix .rel.dyn relocations
+	 */
+	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
+	add	r10, r10, r9		/* r10 <- sym table in FLASH */
+	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
+	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
+	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
+	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */
+fixloop:
+	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
+	add	r0, r0, r9		/* r0 <- DST location to fix up */
+	ldr	r1, [r2, #4]
+	and	r7, r1, #0xff
+	cmp	r7, #23			/* relative fixup? */
+	beq	fixrel
+	cmp	r7, #2			/* absolute fixup? */
+	beq	fixabs
+	/* ignore unknown type of fixup */
+	b	fixnext
+fixabs:
+	/* absolute fix: set location to (offset) symbol value */
+	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
+	add	r1, r10, r1		/* r1 <- address of symbol in table */
+	ldr	r1, [r1, #4]		/* r1 <- symbol value */
+	add	r1, r1, r9		/* r1 <- relocated sym addr */
+	b	fixnext
+fixrel:
+	/* relative fix: increase location by offset */
+	ldr	r1, [r0]
+	add	r1, r1, r9
+fixnext:
+	str	r1, [r0]
+	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
+	cmp	r2, r3
+	blo	fixloop
+
+relocate_done:
+
+	/* ARMv4- don't know bx lr but the assembler fails to see that */
+
+#ifdef __ARM_ARCH_4__
+        mov        pc, lr
+#else
+        bx        lr
+#endif
+
+_image_copy_end_ofs:
+	.word __image_copy_end - relocate_code
+_rel_dyn_start_ofs:
+	.word __rel_dyn_start - relocate_code
+_rel_dyn_end_ofs:
+	.word __rel_dyn_end - relocate_code
+_dynsym_start_ofs:
+	.word __dynsym_start - relocate_code
+
+ENDPROC(relocate_code)
-- 
1.7.10.4

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

* [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances
  2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-14  9:55   ` Albert ARIBAUD
  2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14  9:55 UTC (permalink / raw)
  To: u-boot

On Tue, 14 May 2013 11:50:26 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> This series replaces all instances of relocate_code in
> various start.S files from the ARM architecture with a
> single instance in arch/arm/lib/relocate.S.

Additional (read: late) note: I have dropped the 'make some symbols
compiler-generated' part of the series, as this is not needed to
factorize relocation_code per se and I want to keep things simple.

I'll reintroduce the compiler-generated symbols stuff as part of a
later patch series about optimizing relocate_code -- that will go
to [NEXT] since we're outside the merge window now.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
  2013-05-14  9:50     ` [U-Boot] [PATCH v2 2/4] tx25: " Albert ARIBAUD
@ 2013-05-14 15:14     ` Benoît Thébaudeau
  2013-05-14 16:13       ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 15:14 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 11:50:27 AM, Albert ARIBAUD wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - dropped relocate_code() call from mx31pdk SPL
> 
>  board/freescale/mx31pdk/mx31pdk.c |   16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/board/freescale/mx31pdk/mx31pdk.c
> b/board/freescale/mx31pdk/mx31pdk.c
> index 49158bd..4f6cfee 100644
> --- a/board/freescale/mx31pdk/mx31pdk.c
> +++ b/board/freescale/mx31pdk/mx31pdk.c
> @@ -39,7 +39,21 @@ DECLARE_GLOBAL_DATA_PTR;
>  #ifdef CONFIG_SPL_BUILD
>  void board_init_f(ulong bootflag)
>  {
> -	relocate_code(CONFIG_SPL_TEXT_BASE);
> +	/*
> +	 * copy ourselves from where we are running to where we were
> +	 * linked at. Use ulong pointers as all addresses involved
> +	 * are 4-byte-aligned.
> +	 */
> +	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
> +	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
> +	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));

Why not __image_copy_start/end instead? I know that the result will be the same
here, but the naming would be more appropriate. The existing u-boot-spl.lds
still gives access to __image_copy_*.

> +	asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr));
> +	asm volatile ("adr %0, board_init_f" : "=r"(run_ptr));
> +	for (dst = start_ptr; dst < end_ptr; dst++)
> +		*dst = *(dst+(run_ptr-link_ptr));
> +	/*
> +	 * branch to nand_boot's link-time address.
> +	 */
>  	asm volatile("ldr pc, =nand_boot");
>  }
>  #endif
> --
> 1.7.10.4

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 2/4] tx25: copy SPL directly, not using relocate_code.
  2013-05-14  9:50     ` [U-Boot] [PATCH v2 2/4] tx25: " Albert ARIBAUD
  2013-05-14  9:50       ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
@ 2013-05-14 15:15       ` Benoît Thébaudeau
  1 sibling, 0 replies; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 15:15 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 11:50:28 AM, Albert ARIBAUD wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - dropped relocate_code() call from tx25 SPL
> 
>  board/karo/tx25/tx25.c |   16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/board/karo/tx25/tx25.c b/board/karo/tx25/tx25.c
> index 2952eba..461e21f 100644
> --- a/board/karo/tx25/tx25.c
> +++ b/board/karo/tx25/tx25.c
> @@ -35,7 +35,21 @@ DECLARE_GLOBAL_DATA_PTR;
>  #ifdef CONFIG_SPL_BUILD
>  void board_init_f(ulong bootflag)
>  {
> -	relocate_code(CONFIG_SPL_TEXT_BASE);
> +	/*
> +	 * copy ourselves from where we are running to where we were
> +	 * linked at. Use ulong pointers as all addresses involved
> +	 * are 4-byte-aligned.
> +	 */
> +	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
> +	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
> +	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));

Same question as for mx31pdk.

> +	asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr));
> +	asm volatile ("adr %0, board_init_f" : "=r"(run_ptr));
> +	for (dst = start_ptr; dst < end_ptr; dst++)
> +		*dst = *(dst+(run_ptr-link_ptr));
> +	/*
> +	 * branch to nand_boot's link-time address.
> +	 */
>  	asm volatile("ldr pc, =nand_boot");
>  }
>  #endif
> --
> 1.7.10.4

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-14  9:50       ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
  2013-05-14  9:50         ` [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine Albert ARIBAUD
@ 2013-05-14 15:21         ` Benoît Thébaudeau
  2013-05-14 16:21           ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 15:21 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 11:50:29 AM, Albert ARIBAUD wrote:
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v2:
> - dropped all relocate_code instances from SPL builds
> 
>  arch/arm/cpu/arm1136/start.S   |   11 +++--------
>  arch/arm/cpu/arm1176/start.S   |   11 +++++------
>  arch/arm/cpu/arm720t/start.S   |   11 +++++------
>  arch/arm/cpu/arm920t/start.S   |   12 +++++-------
>  arch/arm/cpu/arm925t/start.S   |   11 +++++------
>  arch/arm/cpu/arm926ejs/start.S |   11 +++--------
>  arch/arm/cpu/arm946es/start.S  |   11 +++++------
>  arch/arm/cpu/arm_intcm/start.S |   11 +++++------
>  arch/arm/cpu/armv7/start.S     |    6 ++----
>  arch/arm/cpu/ixp/start.S       |   11 +++++------
>  arch/arm/cpu/pxa/start.S       |    8 ++------
>  arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
>  arch/arm/cpu/sa1100/start.S    |   11 +++++------
>  13 files changed, 55 insertions(+), 81 deletions(-)
> 
> diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
> index ccea2d5..1eec2e0 100644
> --- a/arch/arm/cpu/arm1136/start.S
> +++ b/arch/arm/cpu/arm1136/start.S
> @@ -104,10 +104,6 @@ _TEXT_BASE:
>  _bss_start_ofs:
>  	.word __bss_start - _start
>  
> -.globl _image_copy_end_ofs
> -_image_copy_end_ofs:
> -	.word __image_copy_end - _start
> -

This change should be mentioned in the commit message, or moved to a separate
patch.

[...]

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14  9:50         ` [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine Albert ARIBAUD
@ 2013-05-14 16:01           ` Benoît Thébaudeau
  2013-05-14 16:32             ` Albert ARIBAUD
  2013-05-15  7:31             ` Albert ARIBAUD
  0 siblings, 2 replies; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 16:01 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 11:50:30 AM, Albert ARIBAUD wrote:
> Replace all relocate_code routines from ARM start.S files
> with a single instance in file arch/arm/lib/relocate.S.
> For PXA, this requires moving the dcache unlocking code
> from within relocate_code into c_runtime_cpu_setup.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

[...]

> diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
> index 595778a..f9947de 100644
> --- a/arch/arm/cpu/pxa/start.S
> +++ b/arch/arm/cpu/pxa/start.S
> @@ -167,93 +167,19 @@ reset:
>  	bl	_main
>  
>  /*------------------------------------------------------------------------------*/
> -#ifndef CONFIG_SPL_BUILD
> -/*
> - * void relocate_code(addr_moni)
> - *
> - * This function relocates the monitor code.
> - */
> -	.globl	relocate_code
> -relocate_code:
> -	mov	r6, r0	/* save addr of destination */
> -
> -/* Disable the Dcache RAM lock for stack now */
> -#ifdef	CONFIG_CPU_PXA25X
> -	mov	r12, lr
> -	bl	cpu_init_crit
> -	mov	lr, r12
> -#endif
> -
> -	adr	r0, _start
> -	subs	r9, r6, r0		/* r9 <- relocation offset */
> -	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	    */
> -
> -copy_loop:
> -	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> -	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> -	cmp	r0, r2			/* until source end address [r2]    */
> -	blo	copy_loop
> -
> -	/*
> -	 * fix .rel.dyn relocations
> -	 */
> -	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
> -	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> -	add	r10, r10, r0		/* r10 <- sym table in FLASH */
> -	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> -	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
> -	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> -	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
> -fixloop:
> -	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
> -	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
> -	ldr	r1, [r2, #4]
> -	and	r7, r1, #0xff
> -	cmp	r7, #23			/* relative fixup? */
> -	beq	fixrel
> -	cmp	r7, #2			/* absolute fixup? */
> -	beq	fixabs
> -	/* ignore unknown type of fixup */
> -	b	fixnext
> -fixabs:
> -	/* absolute fix: set location to (offset) symbol value */
> -	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> -	add	r1, r10, r1		/* r1 <- address of symbol in table */
> -	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> -	add	r1, r1, r9		/* r1 <- relocated sym addr */
> -	b	fixnext
> -fixrel:
> -	/* relative fix: increase location by offset */
> -	ldr	r1, [r0]
> -	add	r1, r1, r9
> -fixnext:
> -	str	r1, [r0]
> -	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> -	cmp	r2, r3
> -	blo	fixloop
> -
> -relocate_done:
> -
> -	bx	lr
> -
> -_image_copy_end_ofs:
> -	.word __image_copy_end - _start
> -_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
> -
> -#endif
>  
>  	.globl	c_runtime_cpu_setup
>  c_runtime_cpu_setup:
>  
> -	bx	lr
> +	/*
> +	 * Unlock (actually, disable) the cache now that board_init_f
> +	 * is done. We could do this earlier but we would need to add
> +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> +	 * exists.
> +	 * As this routine is just a call to cpu_init_crit, let us
> +	 * tail-optimize and do a simple branch here.
> +	 */
> +	b	cpu_init_crit

Shouldn't the "#ifdef CONFIG_CPU_PXA25X" from the original code be kept here?

>  
>  /*
>   *************************************************************************

[...]

> diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> new file mode 100644
> index 0000000..9e91fae
> --- /dev/null
> +++ b/arch/arm/lib/relocate.S
> @@ -0,0 +1,111 @@
> +/*
> + *  relocate - common relocation function for ARM U-Boot
> + *
> + *  Copyright (c) 2013  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 <linux/linkage.h>
> +
> +/*
> + * These are defined in the board-specific linker script.
> + * Subtracting _start from them lets the linker put their
> + * relative position in the executable instead of leaving
> + * them null.
> + */

This comment is obsolete. It should either be removed or updated.

> +
> +/*
> + * void relocate_code(addr_moni)
> + *
> + * This function relocates the monitor code.
> + */
> +ENTRY(relocate_code)
> +	mov	r6, r0	/* save addr of destination */
> +
> +	ldr	r0, =_start

If you are avoiding the "ldr =" construct below, why do you use it here? You
could "ldr r0, _TEXT_BASE".

> +	subs	r9, r6, r0		/* r9 <- relocation offset */
> +	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	    */

Adding _start to a relocate_code-relative _image_copy_end_ofs?!

> +
> +copy_loop:
> +	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> +	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> +	cmp	r0, r2			/* until source end address [r2]    */
> +	blo	copy_loop
> +
> +	/*
> +	 * fix .rel.dyn relocations
> +	 */
> +	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> +	add	r10, r10, r9		/* r10 <- sym table in FLASH */
> +	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> +	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
> +	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> +	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */

This is mixing relocate_code-relative offsets with the relocation offset!

> +fixloop:
> +	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
> +	add	r0, r0, r9		/* r0 <- DST location to fix up */
> +	ldr	r1, [r2, #4]
> +	and	r7, r1, #0xff
> +	cmp	r7, #23			/* relative fixup? */
> +	beq	fixrel
> +	cmp	r7, #2			/* absolute fixup? */
> +	beq	fixabs
> +	/* ignore unknown type of fixup */
> +	b	fixnext
> +fixabs:
> +	/* absolute fix: set location to (offset) symbol value */
> +	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> +	add	r1, r10, r1		/* r1 <- address of symbol in table */
> +	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> +	add	r1, r1, r9		/* r1 <- relocated sym addr */
> +	b	fixnext
> +fixrel:
> +	/* relative fix: increase location by offset */
> +	ldr	r1, [r0]
> +	add	r1, r1, r9
> +fixnext:
> +	str	r1, [r0]
> +	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> +	cmp	r2, r3
> +	blo	fixloop
> +
> +relocate_done:
> +
> +	/* ARMv4- don't know bx lr but the assembler fails to see that */
> +
> +#ifdef __ARM_ARCH_4__
> +        mov        pc, lr
> +#else
> +        bx        lr
> +#endif
> +
> +_image_copy_end_ofs:
> +	.word __image_copy_end - relocate_code
> +_rel_dyn_start_ofs:
> +	.word __rel_dyn_start - relocate_code
> +_rel_dyn_end_ofs:
> +	.word __rel_dyn_end - relocate_code
> +_dynsym_start_ofs:
> +	.word __dynsym_start - relocate_code
> +
> +ENDPROC(relocate_code)
> --
> 1.7.10.4

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-14 15:14     ` [U-Boot] [PATCH v2 1/4] mx31pdk: " Benoît Thébaudeau
@ 2013-05-14 16:13       ` Albert ARIBAUD
  2013-05-14 17:10         ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14 16:13 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Tue, 14 May 2013 17:14:12 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Tuesday, May 14, 2013 11:50:27 AM, Albert ARIBAUD wrote:
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > ---
> > Changes in v2:
> > - dropped relocate_code() call from mx31pdk SPL
> > 
> >  board/freescale/mx31pdk/mx31pdk.c |   16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/board/freescale/mx31pdk/mx31pdk.c
> > b/board/freescale/mx31pdk/mx31pdk.c
> > index 49158bd..4f6cfee 100644
> > --- a/board/freescale/mx31pdk/mx31pdk.c
> > +++ b/board/freescale/mx31pdk/mx31pdk.c
> > @@ -39,7 +39,21 @@ DECLARE_GLOBAL_DATA_PTR;
> >  #ifdef CONFIG_SPL_BUILD
> >  void board_init_f(ulong bootflag)
> >  {
> > -	relocate_code(CONFIG_SPL_TEXT_BASE);
> > +	/*
> > +	 * copy ourselves from where we are running to where we were
> > +	 * linked at. Use ulong pointers as all addresses involved
> > +	 * are 4-byte-aligned.
> > +	 */
> > +	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
> > +	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
> > +	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
> 
> Why not __image_copy_start/end instead? I know that the result will be the same
> here, but the naming would be more appropriate. The existing u-boot-spl.lds
> still gives access to __image_copy_*.

Well, yes, the naming seems appropriate, and I thought and said so
myself some time ago. But then, I realize that __image_copy_start and
__image_copy_end are tightly coupled with relocation, and I want to
avoid creating any additional ties between relocation and SPL just when
I am severing them. IOW, I want to keep the option of having a reduced
SPL linker file, distinct from the u-boot one, and where none of
__image_copy_*, __rel_dyn_* or __dynsym_start exist.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-14 15:21         ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Benoît Thébaudeau
@ 2013-05-14 16:21           ` Albert ARIBAUD
  2013-05-14 17:12             ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14 16:21 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Tue, 14 May 2013 17:21:51 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Tuesday, May 14, 2013 11:50:29 AM, Albert ARIBAUD wrote:
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > ---
> > Changes in v2:
> > - dropped all relocate_code instances from SPL builds
> > 
> >  arch/arm/cpu/arm1136/start.S   |   11 +++--------
> >  arch/arm/cpu/arm1176/start.S   |   11 +++++------
> >  arch/arm/cpu/arm720t/start.S   |   11 +++++------
> >  arch/arm/cpu/arm920t/start.S   |   12 +++++-------
> >  arch/arm/cpu/arm925t/start.S   |   11 +++++------
> >  arch/arm/cpu/arm926ejs/start.S |   11 +++--------
> >  arch/arm/cpu/arm946es/start.S  |   11 +++++------
> >  arch/arm/cpu/arm_intcm/start.S |   11 +++++------
> >  arch/arm/cpu/armv7/start.S     |    6 ++----
> >  arch/arm/cpu/ixp/start.S       |   11 +++++------
> >  arch/arm/cpu/pxa/start.S       |    8 ++------
> >  arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
> >  arch/arm/cpu/sa1100/start.S    |   11 +++++------
> >  13 files changed, 55 insertions(+), 81 deletions(-)
> > 
> > diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
> > index ccea2d5..1eec2e0 100644
> > --- a/arch/arm/cpu/arm1136/start.S
> > +++ b/arch/arm/cpu/arm1136/start.S
> > @@ -104,10 +104,6 @@ _TEXT_BASE:
> >  _bss_start_ofs:
> >  	.word __bss_start - _start
> >  
> > -.globl _image_copy_end_ofs
> > -_image_copy_end_ofs:
> > -	.word __image_copy_end - _start
> > -
> 
> This change should be mentioned in the commit message, or moved to a separate
> patch.

This is not a separate change; __image_copy_end_ofs is one of the offset
words used by relocate_code, only for some reason it was not initially
placed with the others at the end of the routine; so instead of putting
a second pair of conditionals around it, I move it where it should have
been in the first place, which also places it within the already added
pair of conditionals.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14 16:01           ` Benoît Thébaudeau
@ 2013-05-14 16:32             ` Albert ARIBAUD
  2013-05-14 17:17               ` Benoît Thébaudeau
  2013-05-15  7:31             ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14 16:32 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Tue, 14 May 2013 18:01:50 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,

> >  	.globl	c_runtime_cpu_setup
> >  c_runtime_cpu_setup:
> >  
> > -	bx	lr
> > +	/*
> > +	 * Unlock (actually, disable) the cache now that board_init_f
> > +	 * is done. We could do this earlier but we would need to add
> > +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> > +	 * exists.
> > +	 * As this routine is just a call to cpu_init_crit, let us
> > +	 * tail-optimize and do a simple branch here.
> > +	 */
> > +	b	cpu_init_crit
> 
> Shouldn't the "#ifdef CONFIG_CPU_PXA25X" from the original code be kept here?

Yes, it should indeed. Thanks for spotting this!

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-14 16:13       ` Albert ARIBAUD
@ 2013-05-14 17:10         ` Benoît Thébaudeau
  2013-05-14 18:24           ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 17:10 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 6:13:55 PM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Tue, 14 May 2013 17:14:12 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Tuesday, May 14, 2013 11:50:27 AM, Albert ARIBAUD wrote:
> > > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > > ---
> > > Changes in v2:
> > > - dropped relocate_code() call from mx31pdk SPL
> > > 
> > >  board/freescale/mx31pdk/mx31pdk.c |   16 +++++++++++++++-
> > >  1 file changed, 15 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/board/freescale/mx31pdk/mx31pdk.c
> > > b/board/freescale/mx31pdk/mx31pdk.c
> > > index 49158bd..4f6cfee 100644
> > > --- a/board/freescale/mx31pdk/mx31pdk.c
> > > +++ b/board/freescale/mx31pdk/mx31pdk.c
> > > @@ -39,7 +39,21 @@ DECLARE_GLOBAL_DATA_PTR;
> > >  #ifdef CONFIG_SPL_BUILD
> > >  void board_init_f(ulong bootflag)
> > >  {
> > > -	relocate_code(CONFIG_SPL_TEXT_BASE);
> > > +	/*
> > > +	 * copy ourselves from where we are running to where we were
> > > +	 * linked at. Use ulong pointers as all addresses involved
> > > +	 * are 4-byte-aligned.
> > > +	 */
> > > +	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
> > > +	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
> > > +	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
> > 
> > Why not __image_copy_start/end instead? I know that the result will be the
> > same
> > here, but the naming would be more appropriate. The existing u-boot-spl.lds
> > still gives access to __image_copy_*.
> 
> Well, yes, the naming seems appropriate, and I thought and said so
> myself some time ago. But then, I realize that __image_copy_start and
> __image_copy_end are tightly coupled with relocation, and I want to
> avoid creating any additional ties between relocation and SPL just when
> I am severing them. IOW, I want to keep the option of having a reduced
> SPL linker file, distinct from the u-boot one, and where none of
> __image_copy_*, __rel_dyn_* or __dynsym_start exist.

OK, that's fine.

Since _end is linker-generated contrary to the other symbols that you use in
those asm lines, have you checked that no R_ARM_ABS32 relocation data is
generated here? OTOH, -pie is not used with SPL, so there should be no
relocation data at all generated here, and the true final addresses should be in
the binary image.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-14 16:21           ` Albert ARIBAUD
@ 2013-05-14 17:12             ` Benoît Thébaudeau
  0 siblings, 0 replies; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 17:12 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 6:21:02 PM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Tue, 14 May 2013 17:21:51 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Tuesday, May 14, 2013 11:50:29 AM, Albert ARIBAUD wrote:
> > > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > > ---
> > > Changes in v2:
> > > - dropped all relocate_code instances from SPL builds
> > > 
> > >  arch/arm/cpu/arm1136/start.S   |   11 +++--------
> > >  arch/arm/cpu/arm1176/start.S   |   11 +++++------
> > >  arch/arm/cpu/arm720t/start.S   |   11 +++++------
> > >  arch/arm/cpu/arm920t/start.S   |   12 +++++-------
> > >  arch/arm/cpu/arm925t/start.S   |   11 +++++------
> > >  arch/arm/cpu/arm926ejs/start.S |   11 +++--------
> > >  arch/arm/cpu/arm946es/start.S  |   11 +++++------
> > >  arch/arm/cpu/arm_intcm/start.S |   11 +++++------
> > >  arch/arm/cpu/armv7/start.S     |    6 ++----
> > >  arch/arm/cpu/ixp/start.S       |   11 +++++------
> > >  arch/arm/cpu/pxa/start.S       |    8 ++------
> > >  arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
> > >  arch/arm/cpu/sa1100/start.S    |   11 +++++------
> > >  13 files changed, 55 insertions(+), 81 deletions(-)
> > > 
> > > diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
> > > index ccea2d5..1eec2e0 100644
> > > --- a/arch/arm/cpu/arm1136/start.S
> > > +++ b/arch/arm/cpu/arm1136/start.S
> > > @@ -104,10 +104,6 @@ _TEXT_BASE:
> > >  _bss_start_ofs:
> > >  	.word __bss_start - _start
> > >  
> > > -.globl _image_copy_end_ofs
> > > -_image_copy_end_ofs:
> > > -	.word __image_copy_end - _start
> > > -
> > 
> > This change should be mentioned in the commit message, or moved to a
> > separate
> > patch.
> 
> This is not a separate change; __image_copy_end_ofs is one of the offset
> words used by relocate_code, only for some reason it was not initially
> placed with the others at the end of the routine; so instead of putting
> a second pair of conditionals around it, I move it where it should have
> been in the first place, which also places it within the already added
> pair of conditionals.

OK.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14 16:32             ` Albert ARIBAUD
@ 2013-05-14 17:17               ` Benoît Thébaudeau
  2013-05-14 18:51                 ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 17:17 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 6:32:08 PM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Tue, 14 May 2013 18:01:50 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> 
> > >  	.globl	c_runtime_cpu_setup
> > >  c_runtime_cpu_setup:
> > >  
> > > -	bx	lr
> > > +	/*
> > > +	 * Unlock (actually, disable) the cache now that board_init_f
> > > +	 * is done. We could do this earlier but we would need to add
> > > +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> > > +	 * exists.
> > > +	 * As this routine is just a call to cpu_init_crit, let us
> > > +	 * tail-optimize and do a simple branch here.
> > > +	 */
> > > +	b	cpu_init_crit
> > 
> > Shouldn't the "#ifdef CONFIG_CPU_PXA25X" from the original code be kept
> > here?
> 
> Yes, it should indeed. Thanks for spotting this!

Have you seen the end of my notes for relocate.S? After all, keeping for later
your patches moving to compiler-generated symbols seems to complicate things and
to be more error-prone.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-14 17:10         ` Benoît Thébaudeau
@ 2013-05-14 18:24           ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14 18:24 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Tue, 14 May 2013 19:10:10 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Tuesday, May 14, 2013 6:13:55 PM, Albert ARIBAUD wrote:
> > Hi Beno?t,
> > 
> > On Tue, 14 May 2013 17:14:12 +0200 (CEST), Beno?t Th?baudeau
> > <benoit.thebaudeau@advansee.com> wrote:
> > 
> > > Hi Albert,
> > > 
> > > On Tuesday, May 14, 2013 11:50:27 AM, Albert ARIBAUD wrote:
> > > > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > > > ---
> > > > Changes in v2:
> > > > - dropped relocate_code() call from mx31pdk SPL
> > > > 
> > > >  board/freescale/mx31pdk/mx31pdk.c |   16 +++++++++++++++-
> > > >  1 file changed, 15 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/board/freescale/mx31pdk/mx31pdk.c
> > > > b/board/freescale/mx31pdk/mx31pdk.c
> > > > index 49158bd..4f6cfee 100644
> > > > --- a/board/freescale/mx31pdk/mx31pdk.c
> > > > +++ b/board/freescale/mx31pdk/mx31pdk.c
> > > > @@ -39,7 +39,21 @@ DECLARE_GLOBAL_DATA_PTR;
> > > >  #ifdef CONFIG_SPL_BUILD
> > > >  void board_init_f(ulong bootflag)
> > > >  {
> > > > -	relocate_code(CONFIG_SPL_TEXT_BASE);
> > > > +	/*
> > > > +	 * copy ourselves from where we are running to where we were
> > > > +	 * linked at. Use ulong pointers as all addresses involved
> > > > +	 * are 4-byte-aligned.
> > > > +	 */
> > > > +	ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
> > > > +	asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
> > > > +	asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
> > > 
> > > Why not __image_copy_start/end instead? I know that the result will be the
> > > same
> > > here, but the naming would be more appropriate. The existing u-boot-spl.lds
> > > still gives access to __image_copy_*.
> > 
> > Well, yes, the naming seems appropriate, and I thought and said so
> > myself some time ago. But then, I realize that __image_copy_start and
> > __image_copy_end are tightly coupled with relocation, and I want to
> > avoid creating any additional ties between relocation and SPL just when
> > I am severing them. IOW, I want to keep the option of having a reduced
> > SPL linker file, distinct from the u-boot one, and where none of
> > __image_copy_*, __rel_dyn_* or __dynsym_start exist.
> 
> OK, that's fine.
> 
> Since _end is linker-generated contrary to the other symbols that you use in
> those asm lines, have you checked that no R_ARM_ABS32 relocation data is
> generated here? OTOH, -pie is not used with SPL, so there should be no
> relocation data at all generated here, and the true final addresses should be in
> the binary image.

Indeed, SPL is meant to be loaded at its link-time address -- or, in the
case of mx31pdk and tx25, loaded in a read buffer then moved by itself
to its link-time address. In no case is SPL supposed to be relocated.
You can verify with readelf -r that no relocation records are generated
for SPL builds.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14 18:51                 ` Albert ARIBAUD
@ 2013-05-14 18:49                   ` Benoît Thébaudeau
  0 siblings, 0 replies; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-14 18:49 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tuesday, May 14, 2013 8:51:58 PM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Tue, 14 May 2013 19:17:46 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Tuesday, May 14, 2013 6:32:08 PM, Albert ARIBAUD wrote:
> > > Hi Beno?t,
> > > 
> > > On Tue, 14 May 2013 18:01:50 +0200 (CEST), Beno?t Th?baudeau
> > > <benoit.thebaudeau@advansee.com> wrote:
> > > 
> > > > Hi Albert,
> > > 
> > > > >  	.globl	c_runtime_cpu_setup
> > > > >  c_runtime_cpu_setup:
> > > > >  
> > > > > -	bx	lr
> > > > > +	/*
> > > > > +	 * Unlock (actually, disable) the cache now that board_init_f
> > > > > +	 * is done. We could do this earlier but we would need to add
> > > > > +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> > > > > +	 * exists.
> > > > > +	 * As this routine is just a call to cpu_init_crit, let us
> > > > > +	 * tail-optimize and do a simple branch here.
> > > > > +	 */
> > > > > +	b	cpu_init_crit
> > > > 
> > > > Shouldn't the "#ifdef CONFIG_CPU_PXA25X" from the original code be kept
> > > > here?
> > > 
> > > Yes, it should indeed. Thanks for spotting this!
> > 
> > Have you seen the end of my notes for relocate.S? After all, keeping for
> > later
> > your patches moving to compiler-generated symbols seems to complicate
> > things and
> > to be more error-prone.
> 
> (that's unrelated to the PXA25X stuff above, right?)

Yes.

> I don't think deferring the compiler-generated symbols patches
> complicates things, as anyway, they would only apply after this
> patch (so as to apply only on a single instance of relocate_code) so
> there's no way they could simplify things occurring before them.
> 
> OTOH, they do simplify the code of relocate_code. That's why I put them
> in a separate series dealing with optimizing relocate_code. I'll post
> this second series right away, and let people decide whether both
> series should be merged in a single one.

Yes, this is what I meant.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14 17:17               ` Benoît Thébaudeau
@ 2013-05-14 18:51                 ` Albert ARIBAUD
  2013-05-14 18:49                   ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-14 18:51 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Tue, 14 May 2013 19:17:46 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Tuesday, May 14, 2013 6:32:08 PM, Albert ARIBAUD wrote:
> > Hi Beno?t,
> > 
> > On Tue, 14 May 2013 18:01:50 +0200 (CEST), Beno?t Th?baudeau
> > <benoit.thebaudeau@advansee.com> wrote:
> > 
> > > Hi Albert,
> > 
> > > >  	.globl	c_runtime_cpu_setup
> > > >  c_runtime_cpu_setup:
> > > >  
> > > > -	bx	lr
> > > > +	/*
> > > > +	 * Unlock (actually, disable) the cache now that board_init_f
> > > > +	 * is done. We could do this earlier but we would need to add
> > > > +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> > > > +	 * exists.
> > > > +	 * As this routine is just a call to cpu_init_crit, let us
> > > > +	 * tail-optimize and do a simple branch here.
> > > > +	 */
> > > > +	b	cpu_init_crit
> > > 
> > > Shouldn't the "#ifdef CONFIG_CPU_PXA25X" from the original code be kept
> > > here?
> > 
> > Yes, it should indeed. Thanks for spotting this!
> 
> Have you seen the end of my notes for relocate.S? After all, keeping for later
> your patches moving to compiler-generated symbols seems to complicate things and
> to be more error-prone.

(that's unrelated to the PXA25X stuff above, right?)

I don't think deferring the compiler-generated symbols patches
complicates things, as anyway, they would only apply after this
patch (so as to apply only on a single instance of relocate_code) so
there's no way they could simplify things occurring before them.

OTOH, they do simplify the code of relocate_code. That's why I put them
in a separate series dealing with optimizing relocate_code. I'll post
this second series right away, and let people decide whether both
series should be merged in a single one.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-14 16:01           ` Benoît Thébaudeau
  2013-05-14 16:32             ` Albert ARIBAUD
@ 2013-05-15  7:31             ` Albert ARIBAUD
  2013-05-15  8:30               ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-15  7:31 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

(I had indeed missed remarks in your reply; apologies for this)

On Tue, 14 May 2013 18:01:50 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,

> > +/*
> > + * These are defined in the board-specific linker script.
> > + * Subtracting _start from them lets the linker put their
> > + * relative position in the executable instead of leaving
> > + * them null.
> > + */  
> 
> This comment is obsolete. It should either be removed or updated.

Correct.

> > +
> > +/*
> > + * void relocate_code(addr_moni)
> > + *
> > + * This function relocates the monitor code.
> > + */
> > +ENTRY(relocate_code)
> > +	mov	r6, r0	/* save addr of destination */
> > +
> > +	ldr	r0, =_start  
> 
> If you are avoiding the "ldr =" construct below, why do you use it
> here? You could "ldr r0, _TEXT_BASE".

_start is defined in a compilation unit, not in the linker file.
References to _start such as the one above are therefore correct before
as well as after relocation.

> > +	subs	r9, r6, r0		/* r9 <- relocation offset */
> > +	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	    */
> 
> Adding _start to a relocate_code-relative _image_copy_end_ofs?!

You're correct. For some reason I did not complete the rewrite here. :(

I'd made the offsets relative to relocate_code in order to avoid
the linker issues with subtracting symbols not defined in the current
compilation unit.

Then I should add =relocate_code to r3, not =_start, and also -- as r9
is not the right offset here -- compute r7 as the delta between the
link-time =_start and the run-time relocate_code (r7 becomes useless
once R10, r2 and r3 are fixed).

I'd run-tested tested each commit but apparently this bug did not
cause any immediately visible issue. This time I'll step-test it.

> > +	/*
> > +	 * fix .rel.dyn relocations
> > +	 */
> > +	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> > +	add	r10, r10, r9		/* r10 <- sym table in FLASH */
> > +	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> > +	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
> > +	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> > +	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */
> 
> This is mixing relocate_code-relative offsets with the relocation offset!

Correct, that's where r7 kicks in to replace r9.

Again, apologies for missing this.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-15  7:31             ` Albert ARIBAUD
@ 2013-05-15  8:30               ` Albert ARIBAUD
  2013-05-15 16:36                 ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-15  8:30 UTC (permalink / raw)
  To: u-boot

On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> Then I should add =relocate_code to r3, not =_start, and also -- as r9
> is not the right offset here -- compute r7 as the delta between the
> link-time =_start and the run-time relocate_code (r7 becomes useless
> once R10, r2 and r3 are fixed).

I badly need a coffee break... Make this "r7 equal to =relocate_code",
simply.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-15  8:30               ` Albert ARIBAUD
@ 2013-05-15 16:36                 ` Benoît Thébaudeau
  2013-05-15 17:55                   ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-15 16:36 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> 
> > Then I should add =relocate_code to r3, not =_start, and also -- as r9
> > is not the right offset here -- compute r7 as the delta between the
> > link-time =_start and the run-time relocate_code (r7 becomes useless
> > once R10, r2 and r3 are fixed).
> 
> I badly need a coffee break... Make this "r7 equal to =relocate_code",
> simply.

Or "adr r7, relocate_code" for the same result in order to avoid using the
literal pool when useless.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-15 16:36                 ` Benoît Thébaudeau
@ 2013-05-15 17:55                   ` Albert ARIBAUD
  2013-05-16 14:29                     ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-15 17:55 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Wed, 15 May 2013 18:36:05 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> > On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> > <albert.u.boot@aribaud.net> wrote:
> > 
> > > Then I should add =relocate_code to r3, not =_start, and also -- as r9
> > > is not the right offset here -- compute r7 as the delta between the
> > > link-time =_start and the run-time relocate_code (r7 becomes useless
> > > once R10, r2 and r3 are fixed).
> > 
> > I badly need a coffee break... Make this "r7 equal to =relocate_code",
> > simply.
> 
> Or "adr r7, relocate_code" for the same result in order to avoid using the
> literal pool when useless.

Correct. That'll be in v3.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances
  2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
  2013-05-14  9:55   ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
@ 2013-05-16 12:02   ` Albert ARIBAUD
  2013-05-16 12:02     ` [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
                       ` (2 more replies)
  2 siblings, 3 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 12:02 UTC (permalink / raw)
  To: u-boot

This series replaces all instances of relocate_code in
various start.S files from the ARM architecture with a
single instance in arch/arm/lib/relocate.S.

This is done in steps, each step keeping the whole of ARM
U-Boot buildable and runnable and touching as little code
as necessary.

1. Drop mx31pdk SPL call to relocate_code

In SPL of mx31pdk, board_init_f calls relocate_code to
move SPL from the NAND read buffer to SRAM. This move
is not a relocation and is thus better implemented as
a simple ad hoc copy loop.

2. Drop tx25 SPL call to relocate_code

Same as mx31pdk.

3. Prevent all SPLs from assembling relocate_code

Now that no SPL uses relocate_code any more, remove
it completely from SPL builds by putting it entirely
between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
conditional.

4. Actual factorization of relocate_code

Remove all instances of relocate_code from start.S and
create a new file, arch/arm/lib/relocate.S, to provide
the new single instance of relocate_code.

The only non-trivial change is that for PXA25X, a call
to unlock (actually disable) dcache is moved from before
relocating to after relocating. As this cache is either
locked-as-RAM or disabled, but never used as actual DDR
cache, this move has no performance effect on relocation
and no functional impact either.

The relocation routine was step-tested on versatileqemu
under gdb. Especially, both relocation offset (from
_start to addr_moni and local offsets (from relocate_code
to several linker script symbols) have been verified.

Changes in v3:
- fixed bugs in relocation offset computations
- moved and fixed comment regarding linker symbols
- fix missing conditionals on PXA25X dcache code
- replaced FLASH/RAM mentions with SRC/DST ones

Changes in v2:
- dropped relocate_code() call from mx31pdk SPL
- dropped relocate_code() call from tx25 SPL
- dropped all relocate_code instances from SPL builds

Albert ARIBAUD (4):
  mx31pdk: copy SPL directly, not using relocate_code.
  tx25: copy SPL directly, not using relocate_code.
  arm: do not compile relocate_code() for SPL builds
  arm: factorize relocate_code routine

 arch/arm/cpu/arm1136/start.S      |   81 ----------------------------
 arch/arm/cpu/arm1176/start.S      |   77 ---------------------------
 arch/arm/cpu/arm720t/start.S      |   77 ---------------------------
 arch/arm/cpu/arm920t/start.S      |   77 ---------------------------
 arch/arm/cpu/arm925t/start.S      |   77 ---------------------------
 arch/arm/cpu/arm926ejs/start.S    |   81 ----------------------------
 arch/arm/cpu/arm946es/start.S     |   77 ---------------------------
 arch/arm/cpu/arm_intcm/start.S    |   77 ---------------------------
 arch/arm/cpu/armv7/start.S        |   78 ---------------------------
 arch/arm/cpu/ixp/start.S          |   77 ---------------------------
 arch/arm/cpu/pxa/start.S          |   97 ++++-----------------------------
 arch/arm/cpu/s3c44b0/start.S      |   77 ---------------------------
 arch/arm/cpu/sa1100/start.S       |   77 ---------------------------
 arch/arm/lib/Makefile             |    1 +
 arch/arm/lib/relocate.S           |  106 +++++++++++++++++++++++++++++++++++++
 board/freescale/mx31pdk/mx31pdk.c |   16 +++++-
 board/karo/tx25/tx25.c            |   16 +++++-
 17 files changed, 148 insertions(+), 1021 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

-- 
1.7.10.4

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

* [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
@ 2013-05-16 12:02     ` Albert ARIBAUD
  2013-05-16 12:02       ` [U-Boot] [PATCH v3 2/4] tx25: " Albert ARIBAUD
  2013-05-16 14:53     ` [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
  2013-05-19 11:48     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 12:02 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- none
Changes in v2:
- drop relocate_code() call from mx31pdk SPL

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

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

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

* [U-Boot] [PATCH v3 2/4] tx25: copy SPL directly, not using relocate_code.
  2013-05-16 12:02     ` [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-16 12:02       ` Albert ARIBAUD
  2013-05-16 12:02         ` [U-Boot] [PATCH v3 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 12:02 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- none
Changes in v2:
- drop relocate_code() call from tx25 SPL

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

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

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

* [U-Boot] [PATCH v3 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-16 12:02       ` [U-Boot] [PATCH v3 2/4] tx25: " Albert ARIBAUD
@ 2013-05-16 12:02         ` Albert ARIBAUD
  2013-05-16 12:02           ` [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 12:02 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- none
Changes in v2:
- drop all relocate_code instances from SPL builds

 arch/arm/cpu/arm1136/start.S   |   11 +++--------
 arch/arm/cpu/arm1176/start.S   |   11 +++++------
 arch/arm/cpu/arm720t/start.S   |   11 +++++------
 arch/arm/cpu/arm920t/start.S   |   12 +++++-------
 arch/arm/cpu/arm925t/start.S   |   11 +++++------
 arch/arm/cpu/arm926ejs/start.S |   11 +++--------
 arch/arm/cpu/arm946es/start.S  |   11 +++++------
 arch/arm/cpu/arm_intcm/start.S |   11 +++++------
 arch/arm/cpu/armv7/start.S     |    6 ++----
 arch/arm/cpu/ixp/start.S       |   11 +++++------
 arch/arm/cpu/pxa/start.S       |    8 ++------
 arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
 arch/arm/cpu/sa1100/start.S    |   11 +++++------
 13 files changed, 55 insertions(+), 81 deletions(-)

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index ccea2d5..1eec2e0 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -104,10 +104,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -173,6 +169,7 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -195,7 +192,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -233,14 +229,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index f20da8e..3c2a52c 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -112,10 +112,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -225,6 +221,7 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -247,7 +244,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -285,12 +281,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -298,6 +295,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 9facc7e..983f8ad 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 6250025..889329f 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -89,10 +89,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -194,6 +190,7 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -216,7 +213,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -254,12 +250,12 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
-
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -267,6 +263,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 021e241..64e8ae5 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -95,10 +95,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -184,6 +180,7 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -206,7 +203,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -244,12 +240,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -257,6 +254,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 4c56711..d5c4ab2 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -136,10 +136,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -190,6 +186,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -212,7 +209,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -250,14 +246,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 9c2b70d..2fc730c 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -105,10 +105,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -159,6 +155,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -181,7 +178,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -219,12 +215,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -232,6 +229,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index 5e8c528..c483b53 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index e9e57e6..3ade510 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -94,10 +94,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -231,6 +227,8 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 69ef8aa..8458f45 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -114,10 +114,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -257,6 +253,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -279,7 +276,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -317,12 +313,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -330,6 +327,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index ada91a6..595778a 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -118,10 +118,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -201,7 +197,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -239,12 +234,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 7361aa2..33a0a81 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -80,10 +80,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -140,6 +136,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -162,7 +159,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -200,12 +196,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -213,6 +210,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 8a2eafd..e0c45d6 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -90,10 +90,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -144,6 +140,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -166,7 +163,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -204,12 +200,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -217,6 +214,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
-- 
1.7.10.4

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

* [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine
  2013-05-16 12:02         ` [U-Boot] [PATCH v3 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
@ 2013-05-16 12:02           ` Albert ARIBAUD
  2013-05-16 15:56             ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 12:02 UTC (permalink / raw)
  To: u-boot

Replace all relocate_code routines from ARM start.S files
with a single instance in file arch/arm/lib/relocate.S.
For PXA, this requires moving the dcache unlocking code
from within relocate_code into c_runtime_cpu_setup.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- fix bugs in relocation offset computations
- move and fix comment regarding linker symbols
- fix missing conditionals on PXA25X dcache code
- replace FLASH/RAM mentions with SRC/DST ones

Changes in v2:
- use ENTRY / ENDPROC macros
- preserve PXA25X dcache unlocking

 arch/arm/cpu/arm1136/start.S   |   76 ----------------------------
 arch/arm/cpu/arm1176/start.S   |   76 ----------------------------
 arch/arm/cpu/arm720t/start.S   |   76 ----------------------------
 arch/arm/cpu/arm920t/start.S   |   75 ----------------------------
 arch/arm/cpu/arm925t/start.S   |   76 ----------------------------
 arch/arm/cpu/arm926ejs/start.S |   76 ----------------------------
 arch/arm/cpu/arm946es/start.S  |   76 ----------------------------
 arch/arm/cpu/arm_intcm/start.S |   76 ----------------------------
 arch/arm/cpu/armv7/start.S     |   76 ----------------------------
 arch/arm/cpu/ixp/start.S       |   76 ----------------------------
 arch/arm/cpu/pxa/start.S       |   93 +++++------------------------------
 arch/arm/cpu/s3c44b0/start.S   |   76 ----------------------------
 arch/arm/cpu/sa1100/start.S    |   76 ----------------------------
 arch/arm/lib/Makefile          |    1 +
 arch/arm/lib/relocate.S        |  106 ++++++++++++++++++++++++++++++++++++++++
 15 files changed, 118 insertions(+), 993 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 1eec2e0..edf249d 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -169,82 +169,6 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 3c2a52c..65292bc 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -221,82 +221,6 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 983f8ad..a0444de 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 889329f..3232065 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -190,81 +190,6 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 64e8ae5..97eb276 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -180,82 +180,6 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index d5c4ab2..5fc8e04 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -186,82 +186,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 2fc730c..e9d0c34 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -155,82 +155,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index c483b53..8dfd919 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 3ade510..8e9cb19 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -163,82 +163,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-ENTRY(relocate_code)
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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)
-
-#endif
-
 ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 8458f45..46cba0c 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -253,82 +253,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 595778a..21fa84c 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -167,94 +167,23 @@ reset:
 	bl	_main
 
 /*------------------------------------------------------------------------------*/
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
 
-/* Disable the Dcache RAM lock for stack now */
-#ifdef	CONFIG_CPU_PXA25X
-	mov	r12, lr
-	bl	cpu_init_crit
-	mov	lr, r12
-#endif
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
 
+#ifdef CONFIG_CPU_PXA25X
 	/*
-	 * fix .rel.dyn relocations
+	 * Unlock (actually, disable) the cache now that board_init_f
+	 * is done. We could do this earlier but we would need to add
+	 * a new C runtime hook, whereas c_runtime_cpu_setup already
+	 * exists.
+	 * As this routine is just a call to cpu_init_crit, let us
+	 * tail-optimize and do a simple branch here.
 	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
+	b	cpu_init_crit
+#else
 	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
 #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 33a0a81..78183fc 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -136,82 +136,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index e0c45d6..30d5a90 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -140,82 +140,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6ae161a..30e3290 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -39,6 +39,7 @@ GLCOBJS	+= div0.o
 SOBJS-y += crt0.o
 
 ifndef CONFIG_SPL_BUILD
+SOBJS-y += relocate.o
 ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
 endif
diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
new file mode 100644
index 0000000..e391822
--- /dev/null
+++ b/arch/arm/lib/relocate.S
@@ -0,0 +1,106 @@
+/*
+ *  relocate - common relocation function for ARM U-Boot
+ *
+ *  Copyright (c) 2013  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 <linux/linkage.h>
+
+/*
+ * void relocate_code(addr_moni)
+ *
+ * This function relocates the monitor code.
+ *
+ * NOTE:
+ * To prevent the code below from containing references with an R_ARM_ABS32
+ * relocation record type, we never refer to linker-defined symbols directly.
+ * Instead, we declare literals which contain their relative location with
+ * respect to relocate_code, and at run time, add relocate_code back to them.
+ */
+
+ENTRY(relocate_code)
+	mov	r6, r0	/* save addr of destination */
+
+	ldr	r0, =_start		/* r0 <- SRC _start */
+	subs	r9, r6, r0		/* r9 <- relocation offset */
+	beq	relocate_done		/* skip relocation */
+	mov	r1, r6			/* r1 <- scratch for copy loop */
+	adr	r7, relocate_code	/* r7 <- SRC &relocate_code */
+	ldr	r3, _image_copy_end_ofs	/* r3 <- __image_copy_end local ofs */
+	add	r2, r7, r3		/* r2 <- SRC &__image_copy_end */
+
+copy_loop:
+	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
+	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
+	cmp	r0, r2			/* until source end address [r2]    */
+	blo	copy_loop
+
+	/*
+	 * fix .rel.dyn relocations
+	 */
+	ldr	r10, _dynsym_start_ofs	/* r10 <- __dynsym_start local ofs */
+	add	r10, r10, r7		/* r10 <- SRC &__dynsym_start */
+	ldr	r2, _rel_dyn_start_ofs	/* r2 <- _rel_dyn_start local ofs */
+	add	r2, r2, r7		/* r2 <- SRC &_rel_dyn_start */
+	ldr	r3, _rel_dyn_end_ofs	/* r3 <- _rel_dyn_end local ofs */
+	add	r3, r3, r7		/* r3 <- SRC &_rel_dyn_end */
+fixloop:
+	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
+	add	r0, r0, r9		/* r0 <- DST location to fix up */
+	ldr	r1, [r2, #4]
+	and	r7, r1, #0xff
+	cmp	r7, #23			/* relative fixup? */
+	beq	fixrel
+	cmp	r7, #2			/* absolute fixup? */
+	beq	fixabs
+	/* ignore unknown type of fixup */
+	b	fixnext
+fixabs:
+	/* absolute fix: set location to (offset) symbol value */
+	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
+	add	r1, r10, r1		/* r1 <- address of symbol in table */
+	ldr	r1, [r1, #4]		/* r1 <- symbol value */
+	add	r1, r1, r9		/* r1 <- relocated sym addr */
+	b	fixnext
+fixrel:
+	/* relative fix: increase location by offset */
+	ldr	r1, [r0]
+	add	r1, r1, r9
+fixnext:
+	str	r1, [r0]
+	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
+	cmp	r2, r3
+	blo	fixloop
+
+relocate_done:
+
+	bx	lr
+
+_image_copy_end_ofs:
+	.word __image_copy_end - relocate_code
+_rel_dyn_start_ofs:
+	.word __rel_dyn_start - relocate_code
+_rel_dyn_end_ofs:
+	.word __rel_dyn_end - relocate_code
+_dynsym_start_ofs:
+	.word __dynsym_start - relocate_code
+
+ENDPROC(relocate_code)
-- 
1.7.10.4

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-16 14:29                     ` Albert ARIBAUD
@ 2013-05-16 14:28                       ` Benoît Thébaudeau
  2013-05-16 14:52                         ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-16 14:28 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Thursday, May 16, 2013 4:29:49 PM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Wed, 15 May 2013 19:55:31 +0200, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> 
> > Hi Beno?t,
> > 
> > On Wed, 15 May 2013 18:36:05 +0200 (CEST), Beno?t Th?baudeau
> > <benoit.thebaudeau@advansee.com> wrote:
> > 
> > > Hi Albert,
> > > 
> > > On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> > > > On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> > > > <albert.u.boot@aribaud.net> wrote:
> > > > 
> > > > > Then I should add =relocate_code to r3, not =_start, and also -- as
> > > > > r9
> > > > > is not the right offset here -- compute r7 as the delta between the
> > > > > link-time =_start and the run-time relocate_code (r7 becomes useless
> > > > > once R10, r2 and r3 are fixed).
> > > > 
> > > > I badly need a coffee break... Make this "r7 equal to =relocate_code",
> > > > simply.
> > > 
> > > Or "adr r7, relocate_code" for the same result in order to avoid using
> > > the
> > > literal pool when useless.
> > 
> > Correct. That'll be in v3.
> 
> Sorry, I missed this change in V3 and left the ldr. Functionally it
> does not have any impact, since as already mentioned, this code always
> runs at the link-time location. You may want Want me to fix it anyway?

I have not yet looked at your V3, but yes, I'd prefer.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-15 17:55                   ` Albert ARIBAUD
@ 2013-05-16 14:29                     ` Albert ARIBAUD
  2013-05-16 14:28                       ` Benoît Thébaudeau
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 14:29 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Wed, 15 May 2013 19:55:31 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> Hi Beno?t,
> 
> On Wed, 15 May 2013 18:36:05 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> > > On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> > > <albert.u.boot@aribaud.net> wrote:
> > > 
> > > > Then I should add =relocate_code to r3, not =_start, and also -- as r9
> > > > is not the right offset here -- compute r7 as the delta between the
> > > > link-time =_start and the run-time relocate_code (r7 becomes useless
> > > > once R10, r2 and r3 are fixed).
> > > 
> > > I badly need a coffee break... Make this "r7 equal to =relocate_code",
> > > simply.
> > 
> > Or "adr r7, relocate_code" for the same result in order to avoid using the
> > literal pool when useless.
> 
> Correct. That'll be in v3.

Sorry, I missed this change in V3 and left the ldr. Functionally it
does not have any impact, since as already mentioned, this code always
runs at the link-time location. You may want Want me to fix it anyway?

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-16 14:28                       ` Benoît Thébaudeau
@ 2013-05-16 14:52                         ` Albert ARIBAUD
  2013-05-16 14:56                           ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 14:52 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Thu, 16 May 2013 16:28:55 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Thursday, May 16, 2013 4:29:49 PM, Albert ARIBAUD wrote:
> > Hi Beno?t,
> > 
> > On Wed, 15 May 2013 19:55:31 +0200, Albert ARIBAUD
> > <albert.u.boot@aribaud.net> wrote:
> > 
> > > Hi Beno?t,
> > > 
> > > On Wed, 15 May 2013 18:36:05 +0200 (CEST), Beno?t Th?baudeau
> > > <benoit.thebaudeau@advansee.com> wrote:
> > > 
> > > > Hi Albert,
> > > > 
> > > > On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> > > > > On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> > > > > <albert.u.boot@aribaud.net> wrote:
> > > > > 
> > > > > > Then I should add =relocate_code to r3, not =_start, and also -- as
> > > > > > r9
> > > > > > is not the right offset here -- compute r7 as the delta between the
> > > > > > link-time =_start and the run-time relocate_code (r7 becomes useless
> > > > > > once R10, r2 and r3 are fixed).
> > > > > 
> > > > > I badly need a coffee break... Make this "r7 equal to =relocate_code",
> > > > > simply.
> > > > 
> > > > Or "adr r7, relocate_code" for the same result in order to avoid using
> > > > the
> > > > literal pool when useless.
> > > 
> > > Correct. That'll be in v3.
> > 
> > Sorry, I missed this change in V3 and left the ldr. Functionally it
> > does not have any impact, since as already mentioned, this code always
> > runs at the link-time location. You may want Want me to fix it anyway?
> 
> I have not yet looked at your V3, but yes, I'd prefer.

Alright, then, V4 it is.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances
  2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2013-05-16 12:02     ` [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-16 14:53     ` Albert ARIBAUD
  2013-05-16 14:55       ` Albert ARIBAUD
  2013-05-19 11:48     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 14:53 UTC (permalink / raw)
  To: u-boot

On Thu, 16 May 2013 14:02:53 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> This series replaces all instances of relocate_code in
> various start.S files from the ARM architecture with a
> single instance in arch/arm/lib/relocate.S.

Please ignore. Will post V4 in a few minutes.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances
  2013-05-16 14:53     ` [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
@ 2013-05-16 14:55       ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 14:55 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Thu, 16 May 2013 16:53:25 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> On Thu, 16 May 2013 14:02:53 +0200, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> 
> > This series replaces all instances of relocate_code in
> > various start.S files from the ARM architecture with a
> > single instance in arch/arm/lib/relocate.S.
> 
> Please ignore. Will post V4 in a few minutes.

Correction, V3 is correct and can be reviewed.

> Amicalement,

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine
  2013-05-16 14:52                         ` Albert ARIBAUD
@ 2013-05-16 14:56                           ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 14:56 UTC (permalink / raw)
  To: u-boot

On Thu, 16 May 2013 16:52:38 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> Hi Beno?t,
> 
> On Thu, 16 May 2013 16:28:55 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Thursday, May 16, 2013 4:29:49 PM, Albert ARIBAUD wrote:
> > > Hi Beno?t,
> > > 
> > > On Wed, 15 May 2013 19:55:31 +0200, Albert ARIBAUD
> > > <albert.u.boot@aribaud.net> wrote:
> > > 
> > > > Hi Beno?t,
> > > > 
> > > > On Wed, 15 May 2013 18:36:05 +0200 (CEST), Beno?t Th?baudeau
> > > > <benoit.thebaudeau@advansee.com> wrote:
> > > > 
> > > > > Hi Albert,
> > > > > 
> > > > > On Wednesday, May 15, 2013 10:30:00 AM, Albert ARIBAUD wrote:
> > > > > > On Wed, 15 May 2013 09:31:37 +0200, Albert ARIBAUD
> > > > > > <albert.u.boot@aribaud.net> wrote:
> > > > > > 
> > > > > > > Then I should add =relocate_code to r3, not =_start, and also -- as
> > > > > > > r9
> > > > > > > is not the right offset here -- compute r7 as the delta between the
> > > > > > > link-time =_start and the run-time relocate_code (r7 becomes useless
> > > > > > > once R10, r2 and r3 are fixed).
> > > > > > 
> > > > > > I badly need a coffee break... Make this "r7 equal to =relocate_code",
> > > > > > simply.
> > > > > 
> > > > > Or "adr r7, relocate_code" for the same result in order to avoid using
> > > > > the
> > > > > literal pool when useless.
> > > > 
> > > > Correct. That'll be in v3.
> > > 
> > > Sorry, I missed this change in V3 and left the ldr. Functionally it
> > > does not have any impact, since as already mentioned, this code always
> > > runs at the link-time location. You may want Want me to fix it anyway?
> > 
> > I have not yet looked at your V3, but yes, I'd prefer.
> 
> Alright, then, V4 it is.

Hmm -- I'd actually made the ldr to adr fix in V3, so no V4 for now, V3
is fine.

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine
  2013-05-16 12:02           ` [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine Albert ARIBAUD
@ 2013-05-16 15:56             ` Benoît Thébaudeau
  2013-05-16 16:57               ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-16 15:56 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Thursday, May 16, 2013 2:02:57 PM, Albert ARIBAUD wrote:
> Replace all relocate_code routines from ARM start.S files
> with a single instance in file arch/arm/lib/relocate.S.
> For PXA, this requires moving the dcache unlocking code
> from within relocate_code into c_runtime_cpu_setup.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v3:
> - fix bugs in relocation offset computations
> - move and fix comment regarding linker symbols
> - fix missing conditionals on PXA25X dcache code
> - replace FLASH/RAM mentions with SRC/DST ones
> 
> Changes in v2:
> - use ENTRY / ENDPROC macros
> - preserve PXA25X dcache unlocking

[...]

> diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
> index 595778a..21fa84c 100644
> --- a/arch/arm/cpu/pxa/start.S
> +++ b/arch/arm/cpu/pxa/start.S
> @@ -167,94 +167,23 @@ reset:
>  	bl	_main
>  
>  /*------------------------------------------------------------------------------*/
> -#ifndef CONFIG_SPL_BUILD
> -/*
> - * void relocate_code(addr_moni)
> - *
> - * This function relocates the monitor code.
> - */
> -	.globl	relocate_code
> -relocate_code:
> -	mov	r6, r0	/* save addr of destination */
>  
> -/* Disable the Dcache RAM lock for stack now */
> -#ifdef	CONFIG_CPU_PXA25X
> -	mov	r12, lr
> -	bl	cpu_init_crit
> -	mov	lr, r12
> -#endif
> -
> -	adr	r0, _start
> -	subs	r9, r6, r0		/* r9 <- relocation offset */
> -	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	    */
> -
> -copy_loop:
> -	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> -	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> -	cmp	r0, r2			/* until source end address [r2]    */
> -	blo	copy_loop
> +	.globl	c_runtime_cpu_setup
> +c_runtime_cpu_setup:
>  
> +#ifdef CONFIG_CPU_PXA25X
>  	/*
> -	 * fix .rel.dyn relocations
> +	 * Unlock (actually, disable) the cache now that board_init_f
> +	 * is done. We could do this earlier but we would need to add
> +	 * a new C runtime hook, whereas c_runtime_cpu_setup already
> +	 * exists.
> +	 * As this routine is just a call to cpu_init_crit, let us
> +	 * tail-optimize and do a simple branch here.
>  	 */
> -	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
> -	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> -	add	r10, r10, r0		/* r10 <- sym table in FLASH */
> -	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> -	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
> -	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> -	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
> -fixloop:
> -	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
> -	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
> -	ldr	r1, [r2, #4]
> -	and	r7, r1, #0xff
> -	cmp	r7, #23			/* relative fixup? */
> -	beq	fixrel
> -	cmp	r7, #2			/* absolute fixup? */
> -	beq	fixabs
> -	/* ignore unknown type of fixup */
> -	b	fixnext
> -fixabs:
> -	/* absolute fix: set location to (offset) symbol value */
> -	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> -	add	r1, r10, r1		/* r1 <- address of symbol in table */
> -	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> -	add	r1, r1, r9		/* r1 <- relocated sym addr */
> -	b	fixnext
> -fixrel:
> -	/* relative fix: increase location by offset */
> -	ldr	r1, [r0]
> -	add	r1, r1, r9
> -fixnext:
> -	str	r1, [r0]
> -	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> -	cmp	r2, r3
> -	blo	fixloop
> -
> -relocate_done:
> -
> +	b	cpu_init_crit
> +#else
>  	bx	lr
> -
> -_image_copy_end_ofs:
> -	.word __image_copy_end - _start
> -_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
> -
>  #endif
> -
> -	.globl	c_runtime_cpu_setup
> -c_runtime_cpu_setup:
> -
> -	bx	lr
> -

Keeping an empty line here would be good for code clarity.

>  /*
>   *************************************************************************
>   *

[...]

> diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> new file mode 100644
> index 0000000..e391822
> --- /dev/null
> +++ b/arch/arm/lib/relocate.S
> @@ -0,0 +1,106 @@
> +/*
> + *  relocate - common relocation function for ARM U-Boot
> + *
> + *  Copyright (c) 2013  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 <linux/linkage.h>
> +
> +/*
> + * void relocate_code(addr_moni)
> + *
> + * This function relocates the monitor code.
> + *
> + * NOTE:
> + * To prevent the code below from containing references with an R_ARM_ABS32
> + * relocation record type, we never refer to linker-defined symbols
> directly.
> + * Instead, we declare literals which contain their relative location with
> + * respect to relocate_code, and at run time, add relocate_code back to
> them.
> + */
> +
> +ENTRY(relocate_code)
> +	mov	r6, r0	/* save addr of destination */
> +
> +	ldr	r0, =_start		/* r0 <- SRC _start */

Or "&_start" in the comment above to be more consistent with the comments below.

> +	subs	r9, r6, r0		/* r9 <- relocation offset */
> +	beq	relocate_done		/* skip relocation */
> +	mov	r1, r6			/* r1 <- scratch for copy loop */
> +	adr	r7, relocate_code	/* r7 <- SRC &relocate_code */
> +	ldr	r3, _image_copy_end_ofs	/* r3 <- __image_copy_end local ofs */
> +	add	r2, r7, r3		/* r2 <- SRC &__image_copy_end */
> +
> +copy_loop:
> +	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
> +	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
> +	cmp	r0, r2			/* until source end address [r2]    */
> +	blo	copy_loop
> +
> +	/*
> +	 * fix .rel.dyn relocations
> +	 */
> +	ldr	r10, _dynsym_start_ofs	/* r10 <- __dynsym_start local ofs */
> +	add	r10, r10, r7		/* r10 <- SRC &__dynsym_start */
> +	ldr	r2, _rel_dyn_start_ofs	/* r2 <- _rel_dyn_start local ofs */
> +	add	r2, r2, r7		/* r2 <- SRC &_rel_dyn_start */
> +	ldr	r3, _rel_dyn_end_ofs	/* r3 <- _rel_dyn_end local ofs */
> +	add	r3, r3, r7		/* r3 <- SRC &_rel_dyn_end */

It's __rel_dyn_start and __rel_dyn_end with 2 leading underscores in the 4
comments above.

> +fixloop:
> +	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
> +	add	r0, r0, r9		/* r0 <- DST location to fix up */
> +	ldr	r1, [r2, #4]
> +	and	r7, r1, #0xff
> +	cmp	r7, #23			/* relative fixup? */
> +	beq	fixrel
> +	cmp	r7, #2			/* absolute fixup? */
> +	beq	fixabs
> +	/* ignore unknown type of fixup */
> +	b	fixnext
> +fixabs:
> +	/* absolute fix: set location to (offset) symbol value */
> +	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
> +	add	r1, r10, r1		/* r1 <- address of symbol in table */
> +	ldr	r1, [r1, #4]		/* r1 <- symbol value */
> +	add	r1, r1, r9		/* r1 <- relocated sym addr */
> +	b	fixnext
> +fixrel:
> +	/* relative fix: increase location by offset */
> +	ldr	r1, [r0]
> +	add	r1, r1, r9
> +fixnext:
> +	str	r1, [r0]
> +	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
> +	cmp	r2, r3
> +	blo	fixloop
> +
> +relocate_done:
> +
> +	bx	lr

Argh! The "bx lr" issue is back. That was correct in v2.

> +
> +_image_copy_end_ofs:
> +	.word __image_copy_end - relocate_code
> +_rel_dyn_start_ofs:
> +	.word __rel_dyn_start - relocate_code
> +_rel_dyn_end_ofs:
> +	.word __rel_dyn_end - relocate_code
> +_dynsym_start_ofs:
> +	.word __dynsym_start - relocate_code
> +
> +ENDPROC(relocate_code)
> --
> 1.7.10.4

The rest of the v3 series is fine.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine
  2013-05-16 15:56             ` Benoît Thébaudeau
@ 2013-05-16 16:57               ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-16 16:57 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Thu, 16 May 2013 17:56:29 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,

> Keeping an empty line here would be good for code clarity.

> Or "&_start" in the comment above to be more consistent with the comments below.

> It's __rel_dyn_start and __rel_dyn_end with 2 leading underscores in the 4
> comments above.

Will fix all three, thanks.

> Argh! The "bx lr" issue is back. That was correct in v2.

As you say: argh! Will fix, and apologies.

> The rest of the v3 series is fine.

Thanks for your review!

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
  2013-05-16 12:02     ` [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
  2013-05-16 14:53     ` [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
@ 2013-05-19 11:48     ` Albert ARIBAUD
  2013-05-19 11:48       ` [U-Boot] [PATCH v4 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
  2013-05-19 15:57       ` [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances Benoît Thébaudeau
  2 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-19 11:48 UTC (permalink / raw)
  To: u-boot

This series replaces all instances of relocate_code in
various start.S files from the ARM architecture with a
single instance in arch/arm/lib/relocate.S.

This is done in steps, each step keeping the whole of ARM
U-Boot buildable and runnable and touching as little code
as necessary.

1. Drop mx31pdk SPL call to relocate_code

In SPL of mx31pdk, board_init_f calls relocate_code to
move SPL from the NAND read buffer to SRAM. This move
is not a relocation and is thus better implemented as
a simple ad hoc copy loop.

2. Drop tx25 SPL call to relocate_code

Same as mx31pdk.

3. Prevent all SPLs from assembling relocate_code

Now that no SPL uses relocate_code any more, remove
it completely from SPL builds by putting it entirely
between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
conditional.

4. Actual factorization of relocate_code

Remove all instances of relocate_code from start.S and
create a new file, arch/arm/lib/relocate.S, to provide
the new single instance of relocate_code.

The only non-trivial change is that for PXA25X, a call
to unlock (actually disable) dcache is moved from before
relocating to after relocating. As this cache is either
locked-as-RAM or disabled, but never used as actual DDR
cache, this move has no performance effect on relocation
and no functional impact either.

The relocation routine was step-tested on versatileqemu
under gdb. Especially, both relocation offset (from
_start to addr_moni and local offsets (from relocate_code
to several linker script symbols) have been verified.

Changes in v4:
- added blank line after PXA25X conditional code
- fixed typos in relocate_code comments
- brought back 'mov pc,lr' instead of 'bx lr' for ARMv4

Changes in v3:
- fixed bugs in relocation offset computations
- moved and fixed comment regarding linker symbols
- fix missing conditionals on PXA25X dcache code
- replaced FLASH/RAM mentions with SRC/DST ones

Changes in v2:
- dropped relocate_code() call from mx31pdk SPL
- dropped relocate_code() call from tx25 SPL
- dropped all relocate_code instances from SPL builds

Albert ARIBAUD (4):
  mx31pdk: copy SPL directly, not using relocate_code.
  tx25: copy SPL directly, not using relocate_code.
  arm: do not compile relocate_code() for SPL builds
  arm: factorize relocate_code routine

 arch/arm/cpu/arm1136/start.S      |   81 ---------------------------
 arch/arm/cpu/arm1176/start.S      |   77 -------------------------
 arch/arm/cpu/arm720t/start.S      |   77 -------------------------
 arch/arm/cpu/arm920t/start.S      |   77 -------------------------
 arch/arm/cpu/arm925t/start.S      |   77 -------------------------
 arch/arm/cpu/arm926ejs/start.S    |   81 ---------------------------
 arch/arm/cpu/arm946es/start.S     |   77 -------------------------
 arch/arm/cpu/arm_intcm/start.S    |   77 -------------------------
 arch/arm/cpu/armv7/start.S        |   78 --------------------------
 arch/arm/cpu/ixp/start.S          |   77 -------------------------
 arch/arm/cpu/pxa/start.S          |   96 ++++---------------------------
 arch/arm/cpu/s3c44b0/start.S      |   77 -------------------------
 arch/arm/cpu/sa1100/start.S       |   77 -------------------------
 arch/arm/lib/Makefile             |    1 +
 arch/arm/lib/relocate.S           |  112 +++++++++++++++++++++++++++++++++++++
 board/freescale/mx31pdk/mx31pdk.c |   16 +++++-
 board/karo/tx25/tx25.c            |   16 +++++-
 17 files changed, 154 insertions(+), 1020 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

-- 
1.7.10.4

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

* [U-Boot] [PATCH v4 1/4] mx31pdk: copy SPL directly, not using relocate_code.
  2013-05-19 11:48     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
@ 2013-05-19 11:48       ` Albert ARIBAUD
  2013-05-19 11:48         ` [U-Boot] [PATCH v4 2/4] tx25: " Albert ARIBAUD
  2013-05-19 15:57       ` [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances Benoît Thébaudeau
  1 sibling, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-19 11:48 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4: None
Changes in v3: None
Changes in v2:
- dropped relocate_code() call from mx31pdk SPL

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

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

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

* [U-Boot] [PATCH v4 2/4] tx25: copy SPL directly, not using relocate_code.
  2013-05-19 11:48       ` [U-Boot] [PATCH v4 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-19 11:48         ` Albert ARIBAUD
  2013-05-19 11:48           ` [U-Boot] [PATCH v4 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-19 11:48 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4: None
Changes in v3: None
Changes in v2:
- dropped relocate_code() call from tx25 SPL

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

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

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

* [U-Boot] [PATCH v4 3/4] arm: do not compile relocate_code() for SPL builds
  2013-05-19 11:48         ` [U-Boot] [PATCH v4 2/4] tx25: " Albert ARIBAUD
@ 2013-05-19 11:48           ` Albert ARIBAUD
  2013-05-19 11:48             ` [U-Boot] [PATCH v4 4/4] arm: factorize relocate_code routine Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-19 11:48 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4: None
Changes in v3: None
Changes in v2:
- dropped all relocate_code instances from SPL builds

 arch/arm/cpu/arm1136/start.S   |   11 +++--------
 arch/arm/cpu/arm1176/start.S   |   11 +++++------
 arch/arm/cpu/arm720t/start.S   |   11 +++++------
 arch/arm/cpu/arm920t/start.S   |   12 +++++-------
 arch/arm/cpu/arm925t/start.S   |   11 +++++------
 arch/arm/cpu/arm926ejs/start.S |   11 +++--------
 arch/arm/cpu/arm946es/start.S  |   11 +++++------
 arch/arm/cpu/arm_intcm/start.S |   11 +++++------
 arch/arm/cpu/armv7/start.S     |    6 ++----
 arch/arm/cpu/ixp/start.S       |   11 +++++------
 arch/arm/cpu/pxa/start.S       |    8 ++------
 arch/arm/cpu/s3c44b0/start.S   |   11 +++++------
 arch/arm/cpu/sa1100/start.S    |   11 +++++------
 13 files changed, 55 insertions(+), 81 deletions(-)

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index ccea2d5..1eec2e0 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -104,10 +104,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -173,6 +169,7 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -195,7 +192,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -233,14 +229,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index f20da8e..3c2a52c 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -112,10 +112,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -225,6 +221,7 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -247,7 +244,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -285,12 +281,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -298,6 +295,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 9facc7e..983f8ad 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 6250025..889329f 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -89,10 +89,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -194,6 +190,7 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -216,7 +213,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -254,12 +250,12 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
-
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -267,6 +263,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 021e241..64e8ae5 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -95,10 +95,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -184,6 +180,7 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -206,7 +203,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -244,12 +240,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -257,6 +254,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 4c56711..d5c4ab2 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -136,10 +136,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -190,6 +186,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -212,7 +209,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -250,14 +246,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
-#ifndef CONFIG_SPL_BUILD
-
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 9c2b70d..2fc730c 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -105,10 +105,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -159,6 +155,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -181,7 +178,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -219,12 +215,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -232,6 +229,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index 5e8c528..c483b53 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -101,10 +101,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -155,6 +151,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -177,7 +174,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -215,12 +211,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -228,6 +225,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index e9e57e6..3ade510 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -94,10 +94,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -231,6 +227,8 @@ relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 69ef8aa..8458f45 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -114,10 +114,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -257,6 +253,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -279,7 +276,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -317,12 +313,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -330,6 +327,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index ada91a6..595778a 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -118,10 +118,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -201,7 +197,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -239,12 +234,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
diff --git a/arch/arm/cpu/s3c44b0/start.S b/arch/arm/cpu/s3c44b0/start.S
index 7361aa2..33a0a81 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -80,10 +80,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -140,6 +136,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -162,7 +159,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -200,12 +196,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	bx	lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -213,6 +210,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index 8a2eafd..e0c45d6 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -90,10 +90,6 @@ _TEXT_BASE:
 _bss_start_ofs:
 	.word __bss_start - _start
 
-.globl _image_copy_end_ofs
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-
 .globl _bss_end_ofs
 _bss_end_ofs:
 	.word __bss_end - _start
@@ -144,6 +140,7 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
+#ifndef CONFIG_SPL_BUILD
 /*
  * void relocate_code(addr_moni)
  *
@@ -166,7 +163,6 @@ copy_loop:
 	cmp	r0, r2			/* until source end address [r2]    */
 	blo	copy_loop
 
-#ifndef CONFIG_SPL_BUILD
 	/*
 	 * fix .rel.dyn relocations
 	 */
@@ -204,12 +200,13 @@ fixnext:
 	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
 	cmp	r2, r3
 	blo	fixloop
-#endif
 
 relocate_done:
 
 	mov	pc, lr
 
+_image_copy_end_ofs:
+	.word __image_copy_end - _start
 _rel_dyn_start_ofs:
 	.word __rel_dyn_start - _start
 _rel_dyn_end_ofs:
@@ -217,6 +214,8 @@ _rel_dyn_end_ofs:
 _dynsym_start_ofs:
 	.word __dynsym_start - _start
 
+#endif
+
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
-- 
1.7.10.4

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

* [U-Boot] [PATCH v4 4/4] arm: factorize relocate_code routine
  2013-05-19 11:48           ` [U-Boot] [PATCH v4 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
@ 2013-05-19 11:48             ` Albert ARIBAUD
  0 siblings, 0 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-19 11:48 UTC (permalink / raw)
  To: u-boot

Replace all relocate_code routines from ARM start.S files
with a single instance in file arch/arm/lib/relocate.S.
For PXA, this requires moving the dcache unlocking code
from within relocate_code into c_runtime_cpu_setup.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v4:
- added blank line after PXA25X conditional code
- fixed typos in relocate_code comments
- brought back 'mov pc,lr' instead of 'bx lr' for ARMv4

Changes in v3:
- fixed bugs in relocation offset computations
- moved and fixed comment regarding linker symbols
- fix missing conditionals on PXA25X dcache code
- replaced FLASH/RAM mentions with SRC/DST ones

Changes in v2: None

 arch/arm/cpu/arm1136/start.S   |   76 ---------------------------
 arch/arm/cpu/arm1176/start.S   |   76 ---------------------------
 arch/arm/cpu/arm720t/start.S   |   76 ---------------------------
 arch/arm/cpu/arm920t/start.S   |   75 ---------------------------
 arch/arm/cpu/arm925t/start.S   |   76 ---------------------------
 arch/arm/cpu/arm926ejs/start.S |   76 ---------------------------
 arch/arm/cpu/arm946es/start.S  |   76 ---------------------------
 arch/arm/cpu/arm_intcm/start.S |   76 ---------------------------
 arch/arm/cpu/armv7/start.S     |   76 ---------------------------
 arch/arm/cpu/ixp/start.S       |   76 ---------------------------
 arch/arm/cpu/pxa/start.S       |   92 ++++-----------------------------
 arch/arm/cpu/s3c44b0/start.S   |   76 ---------------------------
 arch/arm/cpu/sa1100/start.S    |   76 ---------------------------
 arch/arm/lib/Makefile          |    1 +
 arch/arm/lib/relocate.S        |  112 ++++++++++++++++++++++++++++++++++++++++
 15 files changed, 124 insertions(+), 992 deletions(-)
 create mode 100644 arch/arm/lib/relocate.S

diff --git a/arch/arm/cpu/arm1136/start.S b/arch/arm/cpu/arm1136/start.S
index 1eec2e0..edf249d 100644
--- a/arch/arm/cpu/arm1136/start.S
+++ b/arch/arm/cpu/arm1136/start.S
@@ -169,82 +169,6 @@ next:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
index 3c2a52c..65292bc 100644
--- a/arch/arm/cpu/arm1176/start.S
+++ b/arch/arm/cpu/arm1176/start.S
@@ -221,82 +221,6 @@ skip_tcmdisable:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm720t/start.S b/arch/arm/cpu/arm720t/start.S
index 983f8ad..a0444de 100644
--- a/arch/arm/cpu/arm720t/start.S
+++ b/arch/arm/cpu/arm720t/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S
index 889329f..3232065 100644
--- a/arch/arm/cpu/arm920t/start.S
+++ b/arch/arm/cpu/arm920t/start.S
@@ -190,81 +190,6 @@ copyex:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm925t/start.S b/arch/arm/cpu/arm925t/start.S
index 64e8ae5..97eb276 100644
--- a/arch/arm/cpu/arm925t/start.S
+++ b/arch/arm/cpu/arm925t/start.S
@@ -180,82 +180,6 @@ poll1:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index d5c4ab2..5fc8e04 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -186,82 +186,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm946es/start.S b/arch/arm/cpu/arm946es/start.S
index 2fc730c..e9d0c34 100644
--- a/arch/arm/cpu/arm946es/start.S
+++ b/arch/arm/cpu/arm946es/start.S
@@ -155,82 +155,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/arm_intcm/start.S b/arch/arm/cpu/arm_intcm/start.S
index c483b53..8dfd919 100644
--- a/arch/arm/cpu/arm_intcm/start.S
+++ b/arch/arm/cpu/arm_intcm/start.S
@@ -151,82 +151,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 3ade510..8e9cb19 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -163,82 +163,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-ENTRY(relocate_code)
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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)
-
-#endif
-
 ENTRY(c_runtime_cpu_setup)
 /*
  * If I-cache is enabled invalidate it
diff --git a/arch/arm/cpu/ixp/start.S b/arch/arm/cpu/ixp/start.S
index 8458f45..46cba0c 100644
--- a/arch/arm/cpu/ixp/start.S
+++ b/arch/arm/cpu/ixp/start.S
@@ -253,82 +253,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/pxa/start.S b/arch/arm/cpu/pxa/start.S
index 595778a..2e3f65e 100644
--- a/arch/arm/cpu/pxa/start.S
+++ b/arch/arm/cpu/pxa/start.S
@@ -167,94 +167,24 @@ reset:
 	bl	_main
 
 /*------------------------------------------------------------------------------*/
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-/* Disable the Dcache RAM lock for stack now */
-#ifdef	CONFIG_CPU_PXA25X
-	mov	r12, lr
-	bl	cpu_init_crit
-	mov	lr, r12
-#endif
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
 
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
+	.globl	c_runtime_cpu_setup
+c_runtime_cpu_setup:
 
+#ifdef CONFIG_CPU_PXA25X
 	/*
-	 * fix .rel.dyn relocations
+	 * Unlock (actually, disable) the cache now that board_init_f
+	 * is done. We could do this earlier but we would need to add
+	 * a new C runtime hook, whereas c_runtime_cpu_setup already
+	 * exists.
+	 * As this routine is just a call to cpu_init_crit, let us
+	 * tail-optimize and do a simple branch here.
 	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
+	b	cpu_init_crit
+#else
 	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
 #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 33a0a81..78183fc 100644
--- a/arch/arm/cpu/s3c44b0/start.S
+++ b/arch/arm/cpu/s3c44b0/start.S
@@ -136,82 +136,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	bx	lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/cpu/sa1100/start.S b/arch/arm/cpu/sa1100/start.S
index e0c45d6..30d5a90 100644
--- a/arch/arm/cpu/sa1100/start.S
+++ b/arch/arm/cpu/sa1100/start.S
@@ -140,82 +140,6 @@ reset:
 
 /*------------------------------------------------------------------------------*/
 
-#ifndef CONFIG_SPL_BUILD
-/*
- * void relocate_code(addr_moni)
- *
- * This function relocates the monitor code.
- */
-	.globl	relocate_code
-relocate_code:
-	mov	r6, r0	/* save addr of destination */
-
-	adr	r0, _start
-	subs	r9, r6, r0		/* r9 <- relocation offset */
-	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	    */
-
-copy_loop:
-	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
-	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end address [r2]    */
-	blo	copy_loop
-
-	/*
-	 * fix .rel.dyn relocations
-	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r0		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
-fixloop:
-	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
-	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
-	ldr	r1, [r2, #4]
-	and	r7, r1, #0xff
-	cmp	r7, #23			/* relative fixup? */
-	beq	fixrel
-	cmp	r7, #2			/* absolute fixup? */
-	beq	fixabs
-	/* ignore unknown type of fixup */
-	b	fixnext
-fixabs:
-	/* absolute fix: set location to (offset) symbol value */
-	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
-	add	r1, r10, r1		/* r1 <- address of symbol in table */
-	ldr	r1, [r1, #4]		/* r1 <- symbol value */
-	add	r1, r1, r9		/* r1 <- relocated sym addr */
-	b	fixnext
-fixrel:
-	/* relative fix: increase location by offset */
-	ldr	r1, [r0]
-	add	r1, r1, r9
-fixnext:
-	str	r1, [r0]
-	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
-	cmp	r2, r3
-	blo	fixloop
-
-relocate_done:
-
-	mov	pc, lr
-
-_image_copy_end_ofs:
-	.word __image_copy_end - _start
-_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
-
-#endif
-
 	.globl	c_runtime_cpu_setup
 c_runtime_cpu_setup:
 
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6ae161a..30e3290 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -39,6 +39,7 @@ GLCOBJS	+= div0.o
 SOBJS-y += crt0.o
 
 ifndef CONFIG_SPL_BUILD
+SOBJS-y += relocate.o
 ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
 endif
diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
new file mode 100644
index 0000000..4446da9
--- /dev/null
+++ b/arch/arm/lib/relocate.S
@@ -0,0 +1,112 @@
+/*
+ *  relocate - common relocation function for ARM U-Boot
+ *
+ *  Copyright (c) 2013  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 <linux/linkage.h>
+
+/*
+ * void relocate_code(addr_moni)
+ *
+ * This function relocates the monitor code.
+ *
+ * NOTE:
+ * To prevent the code below from containing references with an R_ARM_ABS32
+ * relocation record type, we never refer to linker-defined symbols directly.
+ * Instead, we declare literals which contain their relative location with
+ * respect to relocate_code, and at run time, add relocate_code back to them.
+ */
+
+ENTRY(relocate_code)
+	mov	r6, r0	/* save addr of destination */
+
+	ldr	r0, =_start		/* r0 <- SRC &_start */
+	subs	r9, r6, r0		/* r9 <- relocation offset */
+	beq	relocate_done		/* skip relocation */
+	mov	r1, r6			/* r1 <- scratch for copy loop */
+	adr	r7, relocate_code	/* r7 <- SRC &relocate_code */
+	ldr	r3, _image_copy_end_ofs	/* r3 <- __image_copy_end local ofs */
+	add	r2, r7, r3		/* r2 <- SRC &__image_copy_end */
+
+copy_loop:
+	ldmia	r0!, {r10-r11}		/* copy from source address [r0]    */
+	stmia	r1!, {r10-r11}		/* copy to   target address [r1]    */
+	cmp	r0, r2			/* until source end address [r2]    */
+	blo	copy_loop
+
+	/*
+	 * fix .rel.dyn relocations
+	 */
+	ldr	r10, _dynsym_start_ofs	/* r10 <- __dynsym_start local ofs */
+	add	r10, r10, r7		/* r10 <- SRC &__dynsym_start */
+	ldr	r2, _rel_dyn_start_ofs	/* r2 <- __rel_dyn_start local ofs */
+	add	r2, r2, r7		/* r2 <- SRC &__rel_dyn_start */
+	ldr	r3, _rel_dyn_end_ofs	/* r3 <- __rel_dyn_end local ofs */
+	add	r3, r3, r7		/* r3 <- SRC &__rel_dyn_end */
+fixloop:
+	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
+	add	r0, r0, r9		/* r0 <- DST location to fix up */
+	ldr	r1, [r2, #4]
+	and	r7, r1, #0xff
+	cmp	r7, #23			/* relative fixup? */
+	beq	fixrel
+	cmp	r7, #2			/* absolute fixup? */
+	beq	fixabs
+	/* ignore unknown type of fixup */
+	b	fixnext
+fixabs:
+	/* absolute fix: set location to (offset) symbol value */
+	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
+	add	r1, r10, r1		/* r1 <- address of symbol in table */
+	ldr	r1, [r1, #4]		/* r1 <- symbol value */
+	add	r1, r1, r9		/* r1 <- relocated sym addr */
+	b	fixnext
+fixrel:
+	/* relative fix: increase location by offset */
+	ldr	r1, [r0]
+	add	r1, r1, r9
+fixnext:
+	str	r1, [r0]
+	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
+	cmp	r2, r3
+	blo	fixloop
+
+relocate_done:
+
+	/* ARMv4- don't know bx lr but the assembler fails to see that */
+
+#ifdef __ARM_ARCH_4__
+        mov        pc, lr
+#else
+        bx        lr
+#endif
+
+_image_copy_end_ofs:
+	.word __image_copy_end - relocate_code
+_rel_dyn_start_ofs:
+	.word __rel_dyn_start - relocate_code
+_rel_dyn_end_ofs:
+	.word __rel_dyn_end - relocate_code
+_dynsym_start_ofs:
+	.word __dynsym_start - relocate_code
+
+ENDPROC(relocate_code)
-- 
1.7.10.4

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-19 11:48     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
  2013-05-19 11:48       ` [U-Boot] [PATCH v4 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
@ 2013-05-19 15:57       ` Benoît Thébaudeau
  2013-05-20  9:26         ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-19 15:57 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> This series replaces all instances of relocate_code in
> various start.S files from the ARM architecture with a
> single instance in arch/arm/lib/relocate.S.
> 
> This is done in steps, each step keeping the whole of ARM
> U-Boot buildable and runnable and touching as little code
> as necessary.
> 
> 1. Drop mx31pdk SPL call to relocate_code
> 
> In SPL of mx31pdk, board_init_f calls relocate_code to
> move SPL from the NAND read buffer to SRAM. This move
> is not a relocation and is thus better implemented as
> a simple ad hoc copy loop.
> 
> 2. Drop tx25 SPL call to relocate_code
> 
> Same as mx31pdk.
> 
> 3. Prevent all SPLs from assembling relocate_code
> 
> Now that no SPL uses relocate_code any more, remove
> it completely from SPL builds by putting it entirely
> between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> conditional.
> 
> 4. Actual factorization of relocate_code
> 
> Remove all instances of relocate_code from start.S and
> create a new file, arch/arm/lib/relocate.S, to provide
> the new single instance of relocate_code.
> 
> The only non-trivial change is that for PXA25X, a call
> to unlock (actually disable) dcache is moved from before
> relocating to after relocating. As this cache is either
> locked-as-RAM or disabled, but never used as actual DDR
> cache, this move has no performance effect on relocation
> and no functional impact either.
> 
> The relocation routine was step-tested on versatileqemu
> under gdb. Especially, both relocation offset (from
> _start to addr_moni and local offsets (from relocate_code
> to several linker script symbols) have been verified.
> 
> Changes in v4:
> - added blank line after PXA25X conditional code
> - fixed typos in relocate_code comments
> - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4

[...]

Perfect!

For this v4 series:
Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>

Best regards,
Beno?t

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-19 15:57       ` [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances Benoît Thébaudeau
@ 2013-05-20  9:26         ` Albert ARIBAUD
  2013-05-20 15:39           ` Benoît Thébaudeau
  2013-05-27 14:56           ` Simon Glass
  0 siblings, 2 replies; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-20  9:26 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Sun, 19 May 2013 17:57:59 +0200 (CEST), Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> > This series replaces all instances of relocate_code in
> > various start.S files from the ARM architecture with a
> > single instance in arch/arm/lib/relocate.S.
> > 
> > This is done in steps, each step keeping the whole of ARM
> > U-Boot buildable and runnable and touching as little code
> > as necessary.
> > 
> > 1. Drop mx31pdk SPL call to relocate_code
> > 
> > In SPL of mx31pdk, board_init_f calls relocate_code to
> > move SPL from the NAND read buffer to SRAM. This move
> > is not a relocation and is thus better implemented as
> > a simple ad hoc copy loop.
> > 
> > 2. Drop tx25 SPL call to relocate_code
> > 
> > Same as mx31pdk.
> > 
> > 3. Prevent all SPLs from assembling relocate_code
> > 
> > Now that no SPL uses relocate_code any more, remove
> > it completely from SPL builds by putting it entirely
> > between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> > conditional.
> > 
> > 4. Actual factorization of relocate_code
> > 
> > Remove all instances of relocate_code from start.S and
> > create a new file, arch/arm/lib/relocate.S, to provide
> > the new single instance of relocate_code.
> > 
> > The only non-trivial change is that for PXA25X, a call
> > to unlock (actually disable) dcache is moved from before
> > relocating to after relocating. As this cache is either
> > locked-as-RAM or disabled, but never used as actual DDR
> > cache, this move has no performance effect on relocation
> > and no functional impact either.
> > 
> > The relocation routine was step-tested on versatileqemu
> > under gdb. Especially, both relocation offset (from
> > _start to addr_moni and local offsets (from relocate_code
> > to several linker script symbols) have been verified.
> > 
> > Changes in v4:
> > - added blank line after PXA25X conditional code
> > - fixed typos in relocate_code comments
> > - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4
> 
> [...]
> 
> Perfect!
> 
> For this v4 series:
> Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>

Thanks Beno?t!

Now I need some people to regression-test it on their
HW, both ARM and non-ARM just in case.

> Best regards,
> Beno?t

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-20  9:26         ` Albert ARIBAUD
@ 2013-05-20 15:39           ` Benoît Thébaudeau
  2013-05-21 13:24             ` Fabio Estevam
  2013-05-27 14:56           ` Simon Glass
  1 sibling, 1 reply; 64+ messages in thread
From: Benoît Thébaudeau @ 2013-05-20 15:39 UTC (permalink / raw)
  To: u-boot

Hi Fabio, Stefano,

On Monday, May 20, 2013 11:26:10 AM, Albert ARIBAUD wrote:
> Hi Beno?t,
> 
> On Sun, 19 May 2013 17:57:59 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Hi Albert,
> > 
> > On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> > > This series replaces all instances of relocate_code in
> > > various start.S files from the ARM architecture with a
> > > single instance in arch/arm/lib/relocate.S.
> > > 
> > > This is done in steps, each step keeping the whole of ARM
> > > U-Boot buildable and runnable and touching as little code
> > > as necessary.
> > > 
> > > 1. Drop mx31pdk SPL call to relocate_code
> > > 
> > > In SPL of mx31pdk, board_init_f calls relocate_code to
> > > move SPL from the NAND read buffer to SRAM. This move
> > > is not a relocation and is thus better implemented as
> > > a simple ad hoc copy loop.
> > > 
> > > 2. Drop tx25 SPL call to relocate_code
> > > 
> > > Same as mx31pdk.
> > > 
> > > 3. Prevent all SPLs from assembling relocate_code
> > > 
> > > Now that no SPL uses relocate_code any more, remove
> > > it completely from SPL builds by putting it entirely
> > > between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> > > conditional.
> > > 
> > > 4. Actual factorization of relocate_code
> > > 
> > > Remove all instances of relocate_code from start.S and
> > > create a new file, arch/arm/lib/relocate.S, to provide
> > > the new single instance of relocate_code.
> > > 
> > > The only non-trivial change is that for PXA25X, a call
> > > to unlock (actually disable) dcache is moved from before
> > > relocating to after relocating. As this cache is either
> > > locked-as-RAM or disabled, but never used as actual DDR
> > > cache, this move has no performance effect on relocation
> > > and no functional impact either.
> > > 
> > > The relocation routine was step-tested on versatileqemu
> > > under gdb. Especially, both relocation offset (from
> > > _start to addr_moni and local offsets (from relocate_code
> > > to several linker script symbols) have been verified.
> > > 
> > > Changes in v4:
> > > - added blank line after PXA25X conditional code
> > > - fixed typos in relocate_code comments
> > > - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4
> > 
> > [...]
> > 
> > Perfect!
> > 
> > For this v4 series:
> > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
> 
> Thanks Beno?t!
> 
> Now I need some people to regression-test it on their
> HW, both ARM and non-ARM just in case.

Can you test this series on mx31pdk (directly changed by this series), and some
other i.MX EVK (e.g. ARMv7, so mx51evk or mx53*) board please? That should be
enough for ARM.

Best regards,
Beno?t

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-20 15:39           ` Benoît Thébaudeau
@ 2013-05-21 13:24             ` Fabio Estevam
  2013-05-28 13:28               ` Albert ARIBAUD
  0 siblings, 1 reply; 64+ messages in thread
From: Fabio Estevam @ 2013-05-21 13:24 UTC (permalink / raw)
  To: u-boot

Hi Beno?t,

On Mon, May 20, 2013 at 12:39 PM, Beno?t Th?baudeau
<benoit.thebaudeau@advansee.com> wrote:

> Can you test this series on mx31pdk (directly changed by this series), and some
> other i.MX EVK (e.g. ARMv7, so mx51evk or mx53*) board please? That should be
> enough for ARM.

I don't have access to my mx31pdk currently, but I will try to get
access to it later this week.

Then I can test this series on mx31pdk and also on mx53loco.

Regards,

Fabio Estevam

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-20  9:26         ` Albert ARIBAUD
  2013-05-20 15:39           ` Benoît Thébaudeau
@ 2013-05-27 14:56           ` Simon Glass
  2013-05-27 16:16             ` Albert ARIBAUD
  1 sibling, 1 reply; 64+ messages in thread
From: Simon Glass @ 2013-05-27 14:56 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Mon, May 20, 2013 at 2:26 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net>wrote:

> Hi Beno?t,
>
> On Sun, 19 May 2013 17:57:59 +0200 (CEST), Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
>
> > Hi Albert,
> >
> > On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> > > This series replaces all instances of relocate_code in
> > > various start.S files from the ARM architecture with a
> > > single instance in arch/arm/lib/relocate.S.
> > >
> > > This is done in steps, each step keeping the whole of ARM
> > > U-Boot buildable and runnable and touching as little code
> > > as necessary.
> > >
> > > 1. Drop mx31pdk SPL call to relocate_code
> > >
> > > In SPL of mx31pdk, board_init_f calls relocate_code to
> > > move SPL from the NAND read buffer to SRAM. This move
> > > is not a relocation and is thus better implemented as
> > > a simple ad hoc copy loop.
> > >
> > > 2. Drop tx25 SPL call to relocate_code
> > >
> > > Same as mx31pdk.
> > >
> > > 3. Prevent all SPLs from assembling relocate_code
> > >
> > > Now that no SPL uses relocate_code any more, remove
> > > it completely from SPL builds by putting it entirely
> > > between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> > > conditional.
> > >
> > > 4. Actual factorization of relocate_code
> > >
> > > Remove all instances of relocate_code from start.S and
> > > create a new file, arch/arm/lib/relocate.S, to provide
> > > the new single instance of relocate_code.
> > >
> > > The only non-trivial change is that for PXA25X, a call
> > > to unlock (actually disable) dcache is moved from before
> > > relocating to after relocating. As this cache is either
> > > locked-as-RAM or disabled, but never used as actual DDR
> > > cache, this move has no performance effect on relocation
> > > and no functional impact either.
> > >
> > > The relocation routine was step-tested on versatileqemu
> > > under gdb. Especially, both relocation offset (from
> > > _start to addr_moni and local offsets (from relocate_code
> > > to several linker script symbols) have been verified.
> > >
> > > Changes in v4:
> > > - added blank line after PXA25X conditional code
> > > - fixed typos in relocate_code comments
> > > - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4
> >
> > [...]
> >
> > Perfect!
> >
> > For this v4 series:
> > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
>
> Thanks Beno?t!
>
> Now I need some people to regression-test it on their
> HW, both ARM and non-ARM just in case.
>

Tested on snow (ARMv7) and link (x86), seems fine.

The series:

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

Re your second series containing 'arm: optimize relocate_code
routine<http://patchwork.ozlabs.org/patch/243817/>',
I ended up with conflicts here - perhaps because the first series was
updated. I would like to test that also, as it should make it possible to
remove CONFIG_SYS_TEXT_BASE which is currently of interest.

Regards,
Simon


>
> > Best regards,
> > Beno?t
>
> Amicalement,
> --
> Albert.
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-27 14:56           ` Simon Glass
@ 2013-05-27 16:16             ` Albert ARIBAUD
  2013-05-27 16:37               ` Simon Glass
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-27 16:16 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Mon, 27 May 2013 07:56:48 -0700, Simon Glass <sjg@chromium.org>
wrote:

> Hi Albert,
> 
> On Mon, May 20, 2013 at 2:26 AM, Albert ARIBAUD
> <albert.u.boot@aribaud.net>wrote:
> 
> > Hi Beno?t,
> >
> > On Sun, 19 May 2013 17:57:59 +0200 (CEST), Beno?t Th?baudeau
> > <benoit.thebaudeau@advansee.com> wrote:
> >
> > > Hi Albert,
> > >
> > > On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> > > > This series replaces all instances of relocate_code in
> > > > various start.S files from the ARM architecture with a
> > > > single instance in arch/arm/lib/relocate.S.
> > > >
> > > > This is done in steps, each step keeping the whole of ARM
> > > > U-Boot buildable and runnable and touching as little code
> > > > as necessary.
> > > >
> > > > 1. Drop mx31pdk SPL call to relocate_code
> > > >
> > > > In SPL of mx31pdk, board_init_f calls relocate_code to
> > > > move SPL from the NAND read buffer to SRAM. This move
> > > > is not a relocation and is thus better implemented as
> > > > a simple ad hoc copy loop.
> > > >
> > > > 2. Drop tx25 SPL call to relocate_code
> > > >
> > > > Same as mx31pdk.
> > > >
> > > > 3. Prevent all SPLs from assembling relocate_code
> > > >
> > > > Now that no SPL uses relocate_code any more, remove
> > > > it completely from SPL builds by putting it entirely
> > > > between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> > > > conditional.
> > > >
> > > > 4. Actual factorization of relocate_code
> > > >
> > > > Remove all instances of relocate_code from start.S and
> > > > create a new file, arch/arm/lib/relocate.S, to provide
> > > > the new single instance of relocate_code.
> > > >
> > > > The only non-trivial change is that for PXA25X, a call
> > > > to unlock (actually disable) dcache is moved from before
> > > > relocating to after relocating. As this cache is either
> > > > locked-as-RAM or disabled, but never used as actual DDR
> > > > cache, this move has no performance effect on relocation
> > > > and no functional impact either.
> > > >
> > > > The relocation routine was step-tested on versatileqemu
> > > > under gdb. Especially, both relocation offset (from
> > > > _start to addr_moni and local offsets (from relocate_code
> > > > to several linker script symbols) have been verified.
> > > >
> > > > Changes in v4:
> > > > - added blank line after PXA25X conditional code
> > > > - fixed typos in relocate_code comments
> > > > - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4
> > >
> > > [...]
> > >
> > > Perfect!
> > >
> > > For this v4 series:
> > > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
> >
> > Thanks Beno?t!
> >
> > Now I need some people to regression-test it on their
> > HW, both ARM and non-ARM just in case.
> >
> 
> Tested on snow (ARMv7) and link (x86), seems fine.
> 
> The series:
> 
> Tested-by: Simon Glass <sjg@chromium.org>

thanks a lot!

> Re your second series containing 'arm: optimize relocate_code
> routine<http://patchwork.ozlabs.org/patch/243817/>',
> I ended up with conflicts here - perhaps because the first series was
> updated. I would like to test that also, as it should make it possible to
> remove CONFIG_SYS_TEXT_BASE which is currently of interest.

Thanks Simon. I have to rebase and repost the second series indeed;
will do this tonight. Note that it was first posted after merge window
closure, so if you need it for things planned in 2013.07, then I'll
have to ask for Tom's agreement to put the second series in 2013.07.

> Regards,
> Simon

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-27 16:16             ` Albert ARIBAUD
@ 2013-05-27 16:37               ` Simon Glass
  0 siblings, 0 replies; 64+ messages in thread
From: Simon Glass @ 2013-05-27 16:37 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Mon, May 27, 2013 at 9:16 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net>wrote:

> Hi Simon,
>
> On Mon, 27 May 2013 07:56:48 -0700, Simon Glass <sjg@chromium.org>
> wrote:
>
> > Hi Albert,
> >
> > On Mon, May 20, 2013 at 2:26 AM, Albert ARIBAUD
> > <albert.u.boot@aribaud.net>wrote:
> >
> > > Hi Beno?t,
> > >
> > > On Sun, 19 May 2013 17:57:59 +0200 (CEST), Beno?t Th?baudeau
> > > <benoit.thebaudeau@advansee.com> wrote:
> > >
> > > > Hi Albert,
> > > >
> > > > On Sunday, May 19, 2013 1:48:11 PM, Albert ARIBAUD wrote:
> > > > > This series replaces all instances of relocate_code in
> > > > > various start.S files from the ARM architecture with a
> > > > > single instance in arch/arm/lib/relocate.S.
> > > > >
> > > > > This is done in steps, each step keeping the whole of ARM
> > > > > U-Boot buildable and runnable and touching as little code
> > > > > as necessary.
> > > > >
> > > > > 1. Drop mx31pdk SPL call to relocate_code
> > > > >
> > > > > In SPL of mx31pdk, board_init_f calls relocate_code to
> > > > > move SPL from the NAND read buffer to SRAM. This move
> > > > > is not a relocation and is thus better implemented as
> > > > > a simple ad hoc copy loop.
> > > > >
> > > > > 2. Drop tx25 SPL call to relocate_code
> > > > >
> > > > > Same as mx31pdk.
> > > > >
> > > > > 3. Prevent all SPLs from assembling relocate_code
> > > > >
> > > > > Now that no SPL uses relocate_code any more, remove
> > > > > it completely from SPL builds by putting it entirely
> > > > > between #ifndef CONFIG_SPL_BUILD and #endif preprocessor
> > > > > conditional.
> > > > >
> > > > > 4. Actual factorization of relocate_code
> > > > >
> > > > > Remove all instances of relocate_code from start.S and
> > > > > create a new file, arch/arm/lib/relocate.S, to provide
> > > > > the new single instance of relocate_code.
> > > > >
> > > > > The only non-trivial change is that for PXA25X, a call
> > > > > to unlock (actually disable) dcache is moved from before
> > > > > relocating to after relocating. As this cache is either
> > > > > locked-as-RAM or disabled, but never used as actual DDR
> > > > > cache, this move has no performance effect on relocation
> > > > > and no functional impact either.
> > > > >
> > > > > The relocation routine was step-tested on versatileqemu
> > > > > under gdb. Especially, both relocation offset (from
> > > > > _start to addr_moni and local offsets (from relocate_code
> > > > > to several linker script symbols) have been verified.
> > > > >
> > > > > Changes in v4:
> > > > > - added blank line after PXA25X conditional code
> > > > > - fixed typos in relocate_code comments
> > > > > - brought back 'mov pc,lr' instead of 'bx lr' for ARMv4
> > > >
> > > > [...]
> > > >
> > > > Perfect!
> > > >
> > > > For this v4 series:
> > > > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
> > >
> > > Thanks Beno?t!
> > >
> > > Now I need some people to regression-test it on their
> > > HW, both ARM and non-ARM just in case.
> > >
> >
> > Tested on snow (ARMv7) and link (x86), seems fine.
> >
> > The series:
> >
> > Tested-by: Simon Glass <sjg@chromium.org>
>
> thanks a lot!
>
> > Re your second series containing 'arm: optimize relocate_code
> > routine<http://patchwork.ozlabs.org/patch/243817/>',
> > I ended up with conflicts here - perhaps because the first series was
> > updated. I would like to test that also, as it should make it possible to
> > remove CONFIG_SYS_TEXT_BASE which is currently of interest.
>
> Thanks Simon. I have to rebase and repost the second series indeed;
> will do this tonight. Note that it was first posted after merge window
> closure, so if you need it for things planned in 2013.07, then I'll
> have to ask for Tom's agreement to put the second series in 2013.07.
>

Sounds good. I think it would be really nice to clean all this up, not sure
about timeframe though. I don't have anything yet posted that depends on
it, but I will once I get it running (reprise the generic relocation idea).

Regards,
Simon


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

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-21 13:24             ` Fabio Estevam
@ 2013-05-28 13:28               ` Albert ARIBAUD
  2013-05-29 12:57                 ` Fabio Estevam
  0 siblings, 1 reply; 64+ messages in thread
From: Albert ARIBAUD @ 2013-05-28 13:28 UTC (permalink / raw)
  To: u-boot

Hi Fabio,

On Tue, 21 May 2013 10:24:19 -0300, Fabio Estevam <festevam@gmail.com>
wrote:

> Hi Beno?t,
> 
> On Mon, May 20, 2013 at 12:39 PM, Beno?t Th?baudeau
> <benoit.thebaudeau@advansee.com> wrote:
> 
> > Can you test this series on mx31pdk (directly changed by this series), and some
> > other i.MX EVK (e.g. ARMv7, so mx51evk or mx53*) board please? That should be
> > enough for ARM.
> 
> I don't have access to my mx31pdk currently, but I will try to get
> access to it later this week.
> 
> Then I can test this series on mx31pdk and also on mx53loco.

Did you manage this test? If you did and it succeeded, then I'll merge
the series into u-boot-arm.

> Regards,
> 
> Fabio Estevam

Amicalement,
-- 
Albert.

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

* [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances
  2013-05-28 13:28               ` Albert ARIBAUD
@ 2013-05-29 12:57                 ` Fabio Estevam
  0 siblings, 0 replies; 64+ messages in thread
From: Fabio Estevam @ 2013-05-29 12:57 UTC (permalink / raw)
  To: u-boot

Hi Albert,

On Tue, May 28, 2013 at 10:28 AM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> Did you manage this test? If you did and it succeeded, then I'll merge
> the series into u-boot-arm.

Unfortunately I did not manage to find some spare time to test this, sorry.

Please go ahead and apply them.

Hopefully I will be able to test next week and then I will report in
case of any issue.

Thanks,

Fabio Estevam

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

end of thread, other threads:[~2013-05-29 12:57 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-10 21:56 [U-Boot] [PATCH 0/4] Factorize ARM relocation code Albert ARIBAUD
2013-05-10 21:56 ` [U-Boot] [PATCH 1/4] Rename arch/arm/lib/bss.c to sections.c Albert ARIBAUD
2013-05-10 21:56   ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Albert ARIBAUD
2013-05-10 21:56     ` [U-Boot] [PATCH 3/4] arm: make relocation section symbols compiler-generated Albert ARIBAUD
2013-05-10 21:56       ` [U-Boot] [PATCH 4/4] arm: factorize relocate_code routine Albert ARIBAUD
2013-05-11  2:04         ` Benoît Thébaudeau
2013-05-11  7:40           ` Albert ARIBAUD
2013-05-11 13:40             ` Benoît Thébaudeau
2013-05-11 22:13         ` Simon Glass
2013-05-11  0:25     ` [U-Boot] [PATCH 2/4] arm: make __image_copy_{start, end} compiler-generated Benoît Thébaudeau
2013-05-11  8:02       ` Albert ARIBAUD
2013-05-11 17:52         ` Benoît Thébaudeau
2013-05-11 20:13           ` Albert ARIBAUD
2013-05-12  8:57             ` Albert ARIBAUD
2013-05-14  9:50 ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
2013-05-14  9:50   ` [U-Boot] [PATCH v2 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
2013-05-14  9:50     ` [U-Boot] [PATCH v2 2/4] tx25: " Albert ARIBAUD
2013-05-14  9:50       ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
2013-05-14  9:50         ` [U-Boot] [PATCH v2 4/4] arm: factorize relocate_code routine Albert ARIBAUD
2013-05-14 16:01           ` Benoît Thébaudeau
2013-05-14 16:32             ` Albert ARIBAUD
2013-05-14 17:17               ` Benoît Thébaudeau
2013-05-14 18:51                 ` Albert ARIBAUD
2013-05-14 18:49                   ` Benoît Thébaudeau
2013-05-15  7:31             ` Albert ARIBAUD
2013-05-15  8:30               ` Albert ARIBAUD
2013-05-15 16:36                 ` Benoît Thébaudeau
2013-05-15 17:55                   ` Albert ARIBAUD
2013-05-16 14:29                     ` Albert ARIBAUD
2013-05-16 14:28                       ` Benoît Thébaudeau
2013-05-16 14:52                         ` Albert ARIBAUD
2013-05-16 14:56                           ` Albert ARIBAUD
2013-05-14 15:21         ` [U-Boot] [PATCH v2 3/4] arm: do not compile relocate_code() for SPL builds Benoît Thébaudeau
2013-05-14 16:21           ` Albert ARIBAUD
2013-05-14 17:12             ` Benoît Thébaudeau
2013-05-14 15:15       ` [U-Boot] [PATCH v2 2/4] tx25: copy SPL directly, not using relocate_code Benoît Thébaudeau
2013-05-14 15:14     ` [U-Boot] [PATCH v2 1/4] mx31pdk: " Benoît Thébaudeau
2013-05-14 16:13       ` Albert ARIBAUD
2013-05-14 17:10         ` Benoît Thébaudeau
2013-05-14 18:24           ` Albert ARIBAUD
2013-05-14  9:55   ` [U-Boot] [PATCH v2 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
2013-05-16 12:02   ` [U-Boot] [PATCH v3 " Albert ARIBAUD
2013-05-16 12:02     ` [U-Boot] [PATCH v3 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
2013-05-16 12:02       ` [U-Boot] [PATCH v3 2/4] tx25: " Albert ARIBAUD
2013-05-16 12:02         ` [U-Boot] [PATCH v3 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
2013-05-16 12:02           ` [U-Boot] [PATCH v3 4/4] arm: factorize relocate_code routine Albert ARIBAUD
2013-05-16 15:56             ` Benoît Thébaudeau
2013-05-16 16:57               ` Albert ARIBAUD
2013-05-16 14:53     ` [U-Boot] [PATCH v3 0/4] Factorize ARM relocate_code instances Albert ARIBAUD
2013-05-16 14:55       ` Albert ARIBAUD
2013-05-19 11:48     ` [U-Boot] [PATCH v4 " Albert ARIBAUD
2013-05-19 11:48       ` [U-Boot] [PATCH v4 1/4] mx31pdk: copy SPL directly, not using relocate_code Albert ARIBAUD
2013-05-19 11:48         ` [U-Boot] [PATCH v4 2/4] tx25: " Albert ARIBAUD
2013-05-19 11:48           ` [U-Boot] [PATCH v4 3/4] arm: do not compile relocate_code() for SPL builds Albert ARIBAUD
2013-05-19 11:48             ` [U-Boot] [PATCH v4 4/4] arm: factorize relocate_code routine Albert ARIBAUD
2013-05-19 15:57       ` [U-Boot] [PATCH v4 0/4] Factorize ARM relocate_code instances Benoît Thébaudeau
2013-05-20  9:26         ` Albert ARIBAUD
2013-05-20 15:39           ` Benoît Thébaudeau
2013-05-21 13:24             ` Fabio Estevam
2013-05-28 13:28               ` Albert ARIBAUD
2013-05-29 12:57                 ` Fabio Estevam
2013-05-27 14:56           ` Simon Glass
2013-05-27 16:16             ` Albert ARIBAUD
2013-05-27 16:37               ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.