summaryrefslogtreecommitdiff
path: root/arch/arm/lib
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2017-11-02 18:11:27 -0600
committerTom Rini <trini@konsulko.com>2017-11-17 07:44:13 -0500
commit49e93875a62fb9e96a4a7483b9bd5d8ae27ea76e (patch)
tree8daa16b3ccae7e5fa772f32e9b2f0b76d532f17e /arch/arm/lib
parent9679d339ad2d4c495d734bad3a0fb7be6c4215eb (diff)
downloadu-boot-49e93875a62fb9e96a4a7483b9bd5d8ae27ea76e.tar.gz
arm64: support running at addr other than linked to
This is required in the case where U-Boot is typically loaded and run at a particular address, but for some reason the RAM at that location is not available, e.g. due to memory fragmentation loading other boot binaries or firmware, splitting an SMP complex between various different OSs without using e.g. the EL2 second-stage page tables to hide the memory asignments, or due to known ECC failures. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'arch/arm/lib')
-rw-r--r--arch/arm/lib/crt0_64.S8
-rw-r--r--arch/arm/lib/relocate_64.S23
2 files changed, 26 insertions, 5 deletions
diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
index 9c46c93ca4..da7c62cbe0 100644
--- a/arch/arm/lib/crt0_64.S
+++ b/arch/arm/lib/crt0_64.S
@@ -98,6 +98,14 @@ ENTRY(_main)
ldr x18, [x18, #GD_NEW_GD] /* x18 <- gd->new_gd */
adr lr, relocation_return
+#if CONFIG_POSITION_INDEPENDENT
+ /* Add in link-vs-runtime offset */
+ adr x0, _start /* x0 <- Runtime value of _start */
+ ldr x9, _TEXT_BASE /* x9 <- Linked value of _start */
+ sub x9, x9, x0 /* x9 <- Run-vs-link offset */
+ add lr, lr, x9
+#endif
+ /* Add in link-vs-relocation offset */
ldr x9, [x18, #GD_RELOC_OFF] /* x9 <- gd->reloc_off */
add lr, lr, x9 /* new return address after relocation */
ldr x0, [x18, #GD_RELOCADDR] /* x0 <- gd->relocaddr */
diff --git a/arch/arm/lib/relocate_64.S b/arch/arm/lib/relocate_64.S
index fdba004363..04804524ed 100644
--- a/arch/arm/lib/relocate_64.S
+++ b/arch/arm/lib/relocate_64.S
@@ -27,11 +27,24 @@ ENTRY(relocate_code)
/*
* Copy u-boot from flash to RAM
*/
- ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */
- subs x9, x0, x1 /* x9 <- relocation offset */
+ adr x1, __image_copy_start /* x1 <- Run &__image_copy_start */
+ subs x9, x0, x1 /* x8 <- Run to copy offset */
b.eq relocate_done /* skip relocation */
- ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */
+ /*
+ * Don't ldr x1, __image_copy_start here, since if the code is already
+ * running at an address other than it was linked to, that instruction
+ * will load the relocated value of __image_copy_start. To
+ * correctly apply relocations, we need to know the linked value.
+ *
+ * Linked &__image_copy_start, which we know was at
+ * CONFIG_SYS_TEXT_BASE, which is stored in _TEXT_BASE, as a non-
+ * relocated value, since it isn't a symbol reference.
+ */
+ ldr x1, _TEXT_BASE /* x1 <- Linked &__image_copy_start */
+ subs x9, x0, x1 /* x9 <- Link to copy offset */
+ adr x1, __image_copy_start /* x1 <- Run &__image_copy_start */
+ adr x2, __image_copy_end /* x2 <- Run &__image_copy_end */
copy_loop:
ldp x10, x11, [x1], #16 /* copy from source address [x1] */
stp x10, x11, [x0], #16 /* copy to target address [x0] */
@@ -42,8 +55,8 @@ copy_loop:
/*
* Fix .rela.dyn relocations
*/
- ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */
- ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */
+ adr x2, __rel_dyn_start /* x2 <- Run &__rel_dyn_start */
+ adr x3, __rel_dyn_end /* x3 <- Run &__rel_dyn_end */
fixloop:
ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */
ldr x4, [x2], #8 /* x4 <- addend */