Add generic relocation feature
Subsystems (2)
PATCH v5 3/14 Add generic relocation feature
Add a relocation implementation as the first thing in the generic board library. This library is needed by SPL also.
We create a separate header file for link symbols defined by the link scripts. It is helpful to have these all in one place and try to make them common across architectures. Since Linux already has a similar file, we bring this in even though many of the symbols there are not relevant to us.
The __relocate_code() function is what we expect all architectures which support relocation will use eventually. For now, they all override this with their own version.
Note: The conflict with the generic board series is that the file include/asm-generic/sections.h is created in both. This should be easy to resolve once we know the order in which these series will be applied.
---
Changes in v2:
- Add README file for relocation
- Add function comments
- Import asm-generic/sections.h from Linux and add U-Boot extras
- Move reloc.c into common/
- Squash generic link symbols patch into generic relocation patch
- Use memset, memcpy instead of inline code
Changes in v4:
- Use renamed start_call_board_init_r() function
Changes in v5:
- Rename start_call_board_init_r() to pivot_to_board_init_r()
common/Makefile | 4 + common/reloc.c | 121 ++++++++++++++++++++++++++++++++++++++++ doc/README.relocation | 87 ++++++++++++++++++++++++++++ include/asm-generic/sections.h | 92 ++++++++++++++++++++++++++++++ include/reloc.h | 17 +++++- 5 files changed, 320 insertions(+), 1 deletions(-) create mode 100644 common/reloc.c create mode 100644 doc/README.relocation create mode 100644 include/asm-generic/sections.h
common/Makefile +4 -0
@@ -189,6 +189,10 @@ COBJS-y += dlmalloc.o COBJS-y += memsize.o COBJS-y += stdio.o +ifndef CONFIG_SYS_SKIP_RELOC +COBJS-y += reloc.o +endif + COBJS := $(sort $(COBJS-y)) XCOBJS := $(sort $(XCOBJS-y))
common/reloc.c new file +121 -0
121 lines not on this page · raw message
doc/README.relocation new file +87 -0
87 lines not on this page · raw message
include/asm-generic/sections.h new file +92 -0
92 lines not on this page · raw message
include/reloc.h +16 -1
@@ -23,12 +23,27 @@#ifndef __RELOC_H#define __RELOC_H +/* This is the prototype for the post-relocation init function */ +typedef void (*board_init_r_func )(gd_t *,ulong ); + +/** +* Call the relocated U-Boot. This is the last thing that is done after +* relocation. This function does not return. +* +* @param new_gd Pointer to the relocated global data +* @param dest_addr Base code address of relocated U-Boot +* @param board_init_r_func Pointer to relocated function to call +*/ +void pivot_to_board_init_r (gd_t *new_gd,ulong dest_addr, +board_init_r_func board_init_r,ulong dest_addr_sp) + __attribute__ ((noreturn)); +/** * Relocate U-Boot and jump to the relocated coded * * This copies U-Boot to a new location, zeroes the BSS, sets up a new stack * and jumps to board_init_r() in the relocated code using the -* proc_call_board_init_r() function. It does not return. +* pivot_to_board_init_r() function. It does not return. * * @param dest_sp New stack pointer to use * @param new_gd Pointer to the relocated global data
Signature · 1 line
1.7.7.3
PATCH v5 5/14 arm: Add pivot_to_board_init_r() to each start.S
We don't want this in a common file, or at least not yet, so add this function to every start.S individually. The existing code tacked on the end of a long relocation function and does not suit our needs since it doesn't allow the address of board_init_r() to be passed in and cannot be called from C since it expects values in registers r4 and above.
---
Changes in v4:
- Put start_call_board_init_r() into each start.S, sadly
- Split out start_call_board_init_r() addition into new patch
Changes in v5:
- Rename start_call_board_init_r() to pivot_to_board_init_r()
arch/arm/cpu/arm1136/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm1176/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm720t/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm920t/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm925t/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm926ejs/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm946es/start.S | 19 +++++++++++++++++++ arch/arm/cpu/arm_intcm/start.S | 19 +++++++++++++++++++ arch/arm/cpu/armv7/start.S | 19 +++++++++++++++++++ arch/arm/cpu/ixp/start.S | 19 +++++++++++++++++++ arch/arm/cpu/lh7a40x/start.S | 19 +++++++++++++++++++ arch/arm/cpu/pxa/start.S | 20 ++++++++++++++++++++ arch/arm/cpu/s3c44b0/start.S | 19 +++++++++++++++++++ arch/arm/cpu/sa1100/start.S | 19 +++++++++++++++++++ 14 files changed, 267 insertions(+), 0 deletions(-)
arch/arm/cpu/arm1136/start.S +19 -0
@@ -295,6 +295,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm1176/start.S +19 -0
@@ -397,6 +397,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + #ifdef CONFIG_ENABLE_MMU _mmu_table_base: .word mmu_table
arch/arm/cpu/arm720t/start.S +19 -0
@@ -266,6 +266,25 @@ clbss_l:str r2, [r0] /* clear loop... */ _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm920t/start.S +19 -0
@@ -317,6 +317,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm925t/start.S +19 -0
@@ -311,6 +311,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm926ejs/start.S +19 -0
@@ -350,6 +350,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm946es/start.S +19 -0
@@ -277,6 +277,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/arm_intcm/start.S +19 -0
@@ -278,6 +278,25 @@ _board_init_r_ofs: .word board_init_r - _start #endif +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/armv7/start.S +19 -0
@@ -298,6 +298,25 @@ jump_2_ram: _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /************************************************************************* * * cpu_init_cp15
arch/arm/cpu/ixp/start.S +19 -0
@@ -372,6 +372,25 @@ clbss_l:str r2, [r0] /* clear loop... */ _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /****************************************************************************/ /* */ /* Interrupt handling */
arch/arm/cpu/lh7a40x/start.S +19 -0
@@ -280,6 +280,25 @@ clbss_l:str r2, [r0] /* clear loop... */ _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/pxa/start.S +20 -0
@@ -303,6 +303,26 @@ _board_init_r_ofs: #endif #endif + +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/s3c44b0/start.S +19 -0
@@ -255,6 +255,25 @@ clbss_l:str r2, [r0] /* clear loop... */ _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
arch/arm/cpu/sa1100/start.S +19 -0
@@ -256,6 +256,25 @@ clbss_l:str r2, [r0] /* clear loop... */ _board_init_r_ofs: .word board_init_r - _start +/** + * Jump to board_init_r with a new stack pointer + * + * @param gd Pointer to global data + * @param dest_addr Destination address from global data + * @param func Address of board_init_r function (relocated) + * @param sp New stack pointer + */ +.globl pivot_to_board_init_r +pivot_to_board_init_r: +#ifndef CONFIG_SYS_ICACHE_OFF + mcr p15, 0, r0, c7, c5, 0 @ invalidate icache + mcr p15, 0, r0, c7, c10, 4 @ DSB + mcr p15, 0, r0, c7, c5, 4 @ ISB +#endif + mov sp, r3 + /* jump to it ... */ + mov pc, r2 + /* ************************************************************************* *
Signature · 1 line
1.7.7.3