arm: implement ELF relocations
PATCH 1/2 arm: implement ELF relocations
ELF relocation tables generated with linker option -pie can be used to fixup code and data in a single loop at relocation, removing the need for manual fixups anywhere else in the code.
--- arch/arm/config.mk | 10 +- arch/arm/cpu/arm926ejs/start.S | 172 ++++++++++++++++------------- arch/arm/cpu/arm926ejs/u-boot.lds | 14 +++ arch/arm/include/asm/u-boot-arm.h | 14 +- arch/arm/lib/board.c | 8 +- doc/README.arm-relocation | 222 +++++++------------------------------ 6 files changed, 167 insertions(+), 273 deletions(-)
arch/arm/config.mk +5 -5
@@ -33,11 +33,6 @@ STANDALONE_LOAD_ADDR = 0xc100000 endif endif -ifndef CONFIG_SYS_ARM_WITHOUT_RELOC -# needed for relocation -PLATFORM_RELFLAGS += -fPIC -endif - ifdef CONFIG_SYS_ARM_WITHOUT_RELOC PLATFORM_CPPFLAGS += -DCONFIG_SYS_ARM_WITHOUT_RELOC endif
@@ -72,3 +67,8 @@ PLATFORM_LIBS += $(OBJTREE)/arch/arm/lib/eabi_compat.o endif endif LDSCRIPT := $(SRCTREE)/$(CPUDIR)/u-boot.lds + +ifndef CONFIG_SYS_ARM_WITHOUT_RELOC +# needed for relocation +PLATFORM_LDFLAGS += -pie +endif
arch/arm/cpu/arm926ejs/start.S +96 -76
267 lines not on this page · raw message
arch/arm/cpu/arm926ejs/u-boot.lds +14 -0
@@ -51,6 +51,14 @@ SECTIONS *(.data.rel.ro) } + . = ALIGN(4); + __rel_dyn_start = .; + .rel.dyn : { *(.rel.dyn) } + __rel_dyn_end = .; + + __dynsym_start = .; + .dynsym : { *(.dynsym) } + __got_start = .; . = ALIGN(4); .got : { *(.got) }
@@ -65,4 +73,10 @@ SECTIONS __bss_start = .; .bss (NOLOAD) : { *(.bss) . = ALIGN(4); } _end = .; + + /DISCARD/ : { *(.dynstr*) } + /DISCARD/ : { *(.dynamic*) } + /DISCARD/ : { *(.plt*) } + /DISCARD/ : { *(.interp*) } + /DISCARD/ : { *(.gnu*) } }
arch/arm/include/asm/u-boot-arm.h +7 -7
@@ -30,18 +30,18 @@#define _U_BOOT_ARM_H_ 1/* for the following variables, see start.S */ -extern ulong _bss_start;/* code + data end == BSS start */ -extern ulong _bss_end;/* BSS end */ +extern ulong _bss_start_ofs;/* BSS start relative to _start */ +extern ulong _bss_end_ofs;/* BSS end relative to _start */ extern ulong IRQ_STACK_START ;/* top of IRQ stack */ extern ulong FIQ_STACK_START ;/* top of FIQ stack */ #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC ) -extern ulong _armboot_start;/* code start */ +extern ulong _armboot_start_ofs;/* code start */ #else extern ulong _TEXT_BASE;/* code start */ -extern ulong _datarel_start; -extern ulong _datarelrolocal_start; -extern ulong _datarellocal_start; -extern ulong _datarelro_start; +extern ulong _datarel_start_ofs; +extern ulong _datarelrolocal_start_ofs; +extern ulong _datarellocal_start_ofs; +extern ulong _datarelro_start_ofs;extern ulong IRQ_STACK_START_IN ;/* 8 bytes in IRQ stack */ #endif
arch/arm/lib/board.c +5 -3
@@ -147,7 +147,7 @@ static int display_banner (void)#else _armboot_start, #endif - _bss_start, _bss_end); + _bss_start_ofs+_TEXT_BASE, _bss_end_ofs+_TEXT_BASE);#ifdef CONFIG_MODEM_SUPPORT debug ("Modem Support enabled\n" );#endif
@@ -517,7 +517,7 @@ void board_init_f (ulong bootflag)memset ((void *)gd,0 ,sizeof (gd_t)); - gd->mon_len = _bss_end - _TEXT_BASE; + gd->mon_len = _bss_end_ofs;for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {if ((*init_fnc_ptr)() !=0 ) {
@@ -679,6 +679,7 @@ static char *failed = "*** failed ***\n";* ************************************************************************ */ +void board_init_r (gd_t *id,ulong dest_addr) {char *s;
@@ -702,7 +703,7 @@ void board_init_r (gd_t *id, ulong dest_addr) gd->flags |=GD_FLG_RELOC ;/* tell others: relocation done */ - monitor_flash_len = _bss_start - _TEXT_BASE; + monitor_flash_len = _bss_start_ofs;debug ("monitor flash len: %08lX\n" , monitor_flash_len);board_init ();/* Setup chipselects */
@@ -914,6 +915,7 @@ extern void davinci_eth_set_mac_addr (const u_int8_t *addr); /* NOTREACHED - no way out of command loop except booting */ } +#endif /* defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ void hang (void )
doc/README.arm-relocation +40 -182
263 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 2/2 edminiv2: add support for ELF relocations
--- board/LaCie/edminiv2/config.mk | 4 ++-- include/configs/edminiv2.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-)
board/LaCie/edminiv2/config.mk +2 -2
@@ -23,5 +23,5 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA # - -TEXT_BASE = 0x00100000 +# TEXT_BASE must equal the intended FLASH location of u-boot. +TEXT_BASE = 0xfff90000
include/configs/edminiv2.h +7 -0
@@ -223,4 +223,11 @@#define CONFIG_SYS_RESET_ADDRESS 0xffff0000#define CONFIG_SYS_MAXARGS 16 +/* additions for new relocation code, must be added to all boards */ +#define CONFIG_RELOC_FIXUP_WORKS +#undef CONFIG_SYS_ARM_WITHOUT_RELOC +#define CONFIG_SYS_SDRAM_BASE 0 +#define CONFIG_SYS_INIT_SP_ADDR \ + (CONFIG_SYS_SDRAM_BASE + 0x1000 - CONFIG_SYS_GBL_DATA_SIZE) +#endif /* _CONFIG_EDMINIV2_H */
Signature · 1 line
1.7.0.4
PATCH 2/2 edminiv2: add support for ELF relocations
Hello Albert,
Quoted 24 lines · Albert Aribaud
Signed-off-by Albert Aribaud <[email protected]>--- board/LaCie/edminiv2/config.mk | 4 ++-- include/configs/edminiv2.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-)board/LaCie/edminiv2/config.mk +2
-2@@ -23,5 +23,5 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA # - -TEXT_BASE = 0x00100000 +# TEXT_BASE must equal the intended FLASH location of u-boot. +TEXT_BASE = 0xfff90000include/configs/edminiv2.h +0
-0
include/configs/edminiv2.h line 227
Quoted 5 lines
include/configs/edminiv2.h +2
-0@@ -223,4 +223,11 @@#define CONFIG_SYS_RESET_ADDRESS 0xffff0000#define CONFIG_SYS_MAXARGS 16 +/* additions for new relocation code, must be added to all boards */ +#define CONFIG_RELOC_FIXUP_WORKS
Instead defining this in every board-config.h we should define it in arch/arm/include/asm/config.h, as it is valid with this relocation version for every arm board.
Can you add this to your 1/2 patch ?
include/configs/edminiv2.h line 228
Quoted 1 line
include/configs/edminiv2.h +1
-0+#undef CONFIG_SYS_ARM_WITHOUT_RELOC
We don;t need this undef
include/configs/edminiv2.h line 233
Quoted 5 lines
include/configs/edminiv2.h +4
-0+#define CONFIG_SYS_SDRAM_BASE 0 +#define CONFIG_SYS_INIT_SP_ADDR \ + (CONFIG_SYS_SDRAM_BASE + 0x1000 - CONFIG_SYS_GBL_DATA_SIZE) +#endif /* _CONFIG_EDMINIV2_H */
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 2/2 edminiv2: add support for ELF relocations
Le 06/10/2010 07:30, Heiko Schocher a ?crit :
Quoted 11 lines
Quoted 1 line
+#define
CONFIG_RELOC_FIXUP_WORKSInstead defining this in every
board-config.hwe should define it inarch/arm/include/asm/config.h, as it is valid with this relocation version for every arm board.Can you add this to your 1/2 patch ?
Quoted 1 line
+#undef
CONFIG_SYS_ARM_WITHOUT_RELOCWe don;t need this undef
Thanks. All of this will go in V2.
Quoted 2 lines
bye,
Heiko
Amicalement,
Signature · 1 line
Albert.
PATCH 1/2 arm: implement ELF relocations
In reply to Albert AribaudHello albert,
Quoted 14 lines · Albert Aribaud
ELF relocation tables generated with linker option -pie can be used to fixup code and data in a single loop at relocation, removing the need for manual fixups anywhere else in the code.
Signed-off-by Albert Aribaud <[email protected]>--- arch/arm/config.mk | 10 +- arch/arm/cpu/arm926ejs/start.S | 172 ++++++++++++++++------------- arch/arm/cpu/arm926ejs/u-boot.lds | 14 +++ arch/arm/include/asm/u-boot-arm.h | 14 +- arch/arm/lib/board.c | 8 +- doc/README.arm-relocation | 222 +++++++------------------------------ 6 files changed, 167 insertions(+), 273 deletions(-)
[...]
Quoted 4 lines
arch/arm/cpu/arm926ejs/start.S +0
-0
[...]
Quoted 15 lines
arch/arm/cpu/arm926ejs/start.S +0
-11@@ -153,29 +151,21 @@ FIQ_STACK_START: IRQ_STACK_START_IN: .word 0x0badc0de -.globl _datarel_start -_datarel_start: - .word __datarel_start - -.globl _datarelrolocal_start -_datarelrolocal_start: - .word __datarelrolocal_start - -.globl _datarellocal_start -_datarellocal_start: - .word __datarellocal_start
arch/arm/cpu/arm926ejs/start.S FIQ_STACK_START: · line 160
Quoted 10 lines
arch/arm/cpu/arm926ejs/start.S +6
-3+.globl _datarel_start_ofs +_datarel_start_ofs: + .word __datarel_start - _start -.globl _datarelro_start -_datarelro_start: - .word __datarelro_start +.globl _datarelrolocal_start_ofs +_datarelrolocal_start_ofs: + .word __datarelrolocal_start - _start
We no longer need this __datarel* vars with your version of relocation, please delete!
Thanks!
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/2 arm: implement ELF relocations
Le 06/10/2010 07:37, Heiko Schocher a ?crit :
Quoted 4 lines
Hello albert,
We no longer need this __datarel* vars with your version of relocation, please delete!
Thanks for pointing this out.
Quoted 4 lines
Thanks!
bye,
Heiko
Amicalement,
Signature · 1 line
Albert.
PATCH 1/2 arm: implement ELF relocations
In reply to Heiko SchocherDear Albert Aribaud, Heiko Schocher,
Quoted 3 lines
Quoted 3 lines
ELF relocation tables generated with linker option -pie can be used to fixup code and data in a single loop at relocation, removing the need for manual fixups anywhere else in the code.
To me it looks now like we have dangling use of
CONFIG_SKIP_RELOCATE_UBOOT and CONFIG_SYS_ARM_WITHOUT_RELOC
all over the source, but it appears to me that they can't really work anymore (I have not tested that).
Although I am not happy to have that removed right now (for code size concerns), I would suggest to remove all relocation preventing code which should make the code much more readable. If really required, a new introduction of a define, mainly changing the linker options not to emit relocation information and skipping a few lines of relocation business _could_ be introduced.
Best Regards,
Reinhard
PATCH 1/2 arm: implement ELF relocations
Le 06/10/2010 08:01, Reinhard Meyer a ?crit :
Quoted 5 lines
To me it looks now like we have dangling use of
CONFIG_SKIP_RELOCATE_UBOOTandCONFIG_SYS_ARM_WITHOUT_RELOCall over the source, but it appears to me that they can't really work anymore (I have not tested that).
Indeed, CONFIG_SYS_ARM_WITHOUT_RELOC should disappear eventually -- it's still there only to give board maintainers a way to build with and without relocation e.g. for testing purposes, and it was announced that it would disappear when relocation makes it into an official release.
As for CONFIG_SKIP_RELOCATE_UBOOT, it was useful in getting a smaller u-boot that would not relocated because it was already at the right place to execute; perfect (along with CONFIG_SKIP_LOWLEVEL_INIT) for building a RAM-based, run-where-it-is u-boot.
Now with relocation, we may not need it any more; but you're right that it cannot stay if it does not work.
Quoted 3 lines
Although I am not happy to have that removed right now (for code size concerns), I would suggest to remove all relocation preventing code which should make the code much more readable.
What do you mean by 'relocation-*preventing* code'?
Quoted 3 lines
If really required, a new introduction of a define, mainly changing the linker options not to emit relocation information and skipping a few lines of relocation business _could_ be introduced.
That would be a cleaner thing, yes.
Right now I don't think that should go into the ELF relocation patch, though; I'll make sure CONFIG_SKIP_RELOCATE_UBOOT either works or goes away, but unless instructed otherwise, I won't introduce a system-wide "don't relocate" feature.
Quoted 2 lines
Best Regards,
Reinhard
Amicalement,
Signature · 1 line
Albert.
PATCH 1/2 arm: implement ELF relocations
Dear Albert ARIBAUD,
Quoted 9 lines
Indeed,
CONFIG_SYS_ARM_WITHOUT_RELOCshould disappear eventually -- it's still there only to give board maintainers a way to build with and without relocation e.g. for testing purposes, and it was announced that it would disappear when relocation makes it into an official release.As for
CONFIG_SKIP_RELOCATE_UBOOT, it was useful in getting a smaller u-boot that would not relocated because it was already at the right place to execute; perfect (along withCONFIG_SKIP_LOWLEVEL_INIT) for building a RAM-based, run-where-it-is u-boot.
CONFIG_SKIP_RELOCATE_UBOOT could remain, making CONFIG_SYS_ARM_WITHOUT_RELOC obsolete. Both must now anyway be defined together or both not!
Also I observed problems with old AT91 code since without CONFIG_SYS_ARM_WITHOUT_RELOC board_init() is called very early, with it is called after relocation is done. I think most AT91 boards that copied code from AT91SAM9***-EK's have to correct their code because "early init" stuff is done in board_init().
Quoted 9 lines
Now with relocation, we may not need it any more; but you're right that it cannot stay if it does not work.
Quoted 3 lines
Although I am not happy to have that removed right now (for code size concerns), I would suggest to remove all relocation preventing code which should make the code much more readable.
What do you mean by 'relocation-*preventing* code'?
Everything, including the #if's that is there for the non-relocating cases. (preventing was a bad choice of word)
Quoted 11 lines
Quoted 4 lines
If really required, a new introduction of a define, mainly changing the linker options not to emit relocation information and skipping a few lines of relocation business _could_ be introduced.
That would be a cleaner thing, yes.
Right now I don't think that should go into the ELF relocation patch, though; I'll make sure
CONFIG_SKIP_RELOCATE_UBOOTeither works or goes away, but unless instructed otherwise, I won't introduce a system-wide "don't relocate" feature.
CONFIG_RELOCATE_UBOOT definitely worked before the relocation patches, I am not sure whether it still works, especially when CONFIG_SYS_ARM_WITHOUT_RELOC is removed.
Best Regards,
Reinhard
PATCH 1/2 arm: implement ELF relocations
Le 06/10/2010 08:45, Reinhard Meyer a ?crit :
Quoted 7 lines
Dear Albert ARIBAUD,
Also I observed problems with old AT91 code since without
CONFIG_SYS_ARM_WITHOUT_RELOCboard_init()is called very early, with it is called after relocation is done. I think most AT91 boards that copied code from AT91SAM9***-EK's have to correct their code because "early init" stuff is done inboard_init().
This was to be expected whatever relocation method is used. Before relocation, board_init_f was running in the final memory mapping. Now it runs (as it should always have) in a limited C environment, with read-only globals, no BSS, only partial gd access... FTR, it hit my orion5x based edminiv2 too in places.
Quoted 3 lines
Quoted 1 line
What do you mean by 'relocation-*preventing* code'?
Everything, including the #if's that is there for the non-relocating cases.
Ok.
Quoted 2 lines
Best Regards,
Reinhard
Amicalement,
Signature · 1 line
Albert.