[U-Boot] [PATCH V3 2/2] [NEXT] arm926ejs: reduce code size with -msingle-pic-base

Albert Aribaud
2010-09-28T13:14:13Z

Add -msingle-pic-base to the relocation flags, and compute the pic base
in start.S twice and for all -- once before relocation to run board_init_f,
and once after relocation to run board_init_r and the rest of u-boot.
This further reduces code size by 2.5% compared to -fPIE alone.

Signed-off-by: Albert Aribaud <albert.aribaud@free.fr>
---
arch/arm/cpu/arm926ejs/config.mk | 5 ++++
arch/arm/cpu/arm926ejs/start.S | 40 +++++++++++++++++++++++++++++-----
arch/arm/cpu/arm926ejs/u-boot.lds | 1 +
board/karo/tx25/config.mk | 2 +-
include/configs/tx25.h | 2 +-
nand_spl/board/karo/tx25/u-boot.lds | 1 +
6 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/config.mk b/arch/arm/cpu/arm926ejs/config.mk
index f8ef90f..aa84706 100644
--- a/arch/arm/cpu/arm926ejs/config.mk
+++ b/arch/arm/cpu/arm926ejs/config.mk
@@ -23,6 +23,11 @@

PLATFORM_RELFLAGS += -fno-common -ffixed-r8 -msoft-float

+ifndef CONFIG_SYS_ARM_WITHOUT_RELOC
+# needed for optimal relocation
+PLATFORM_RELFLAGS += -msingle-pic-base
+endif
+
PLATFORM_CPPFLAGS += -march=armv5te
# =========================================================================
#
diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index 16ee972..904bd8d 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -198,9 +198,23 @@ reset:
bl cpu_init_crit
#endif

-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
+ /*
+ * Set stack pointer in internal RAM
+ */
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
+
+ /*
+ * Set pic base register to the link-time GOT position.
+ * At the moment this is also our run-time position.
+ * Set both r10 and r9 because either could be used as pic base
+ * depending on whether stack checking is off or on.
+ */
+ ldr r10, _got_base
+ mov r9, r10
+
+ /*
+ * Call board_init_f, passing it 0 for bootflag
+ */
ldr r0,=0x00000000
bl board_init_f

@@ -220,7 +234,9 @@ relocate_code:
mov r6, r2 /* save addr of destination */
mov r7, r2 /* save addr of destination */

- /* Set up the stack */
+ /*
+ * Set up the stack
+ */
stack_setup:
mov sp, r4

@@ -234,9 +250,9 @@ stack_setup:

#ifndef CONFIG_SKIP_RELOCATE_UBOOT
copy_loop:
- ldmia r0!, {r9-r10} /* copy from source address [r0] */
- stmia r6!, {r9-r10} /* copy to target address [r1] */
- cmp r0, r2 /* until source end addreee [r2] */
+ ldmia r0!, {r11-r12} /* copy from source address [r0] */
+ stmia r6!, {r11-r12} /* copy to target address [r6] */
+ cmp r0, r2 /* until source end address [r2] */
ble copy_loop

#ifndef CONFIG_PRELOADER
@@ -259,6 +275,15 @@ fixloop:
cmp r2, r3
bne fixloop
#endif
+
+ /*
+ * Fix pic base register as well
+ */
+ sub r9, r9, r1
+ add r9, r9, r0
+ sub r10, r10, r1
+ add r10, r10, r0
+
#endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */

clear_bss:
@@ -305,6 +330,9 @@ _nand_boot: .word nand_boot
_board_init_r: .word board_init_r
#endif

+_got_base:
+ .word __got_base
+
#else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
/*
* the actual reset code
diff --git a/arch/arm/cpu/arm926ejs/u-boot.lds b/arch/arm/cpu/arm926ejs/u-boot.lds
index 02eb8ca..b6e21f2 100644
--- a/arch/arm/cpu/arm926ejs/u-boot.lds
+++ b/arch/arm/cpu/arm926ejs/u-boot.lds
@@ -53,6 +53,7 @@ SECTIONS

__got_start = .;
. = ALIGN(4);
+ __got_base = .;
.got : { *(.got) }

__got_end = .;
diff --git a/board/karo/tx25/config.mk b/board/karo/tx25/config.mk
index 51ca1ab..1a32c87 100644
--- a/board/karo/tx25/config.mk
+++ b/board/karo/tx25/config.mk
@@ -1,5 +1,5 @@
ifdef CONFIG_NAND_SPL
TEXT_BASE = 0x810c0000
else
-TEXT_BASE = 0x81fc0000
+TEXT_BASE = 0x81fc1000
endif
diff --git a/include/configs/tx25.h b/include/configs/tx25.h
index c798570..b83c95f 100644
--- a/include/configs/tx25.h
+++ b/include/configs/tx25.h
@@ -41,7 +41,7 @@
#define CONFIG_SYS_NAND_U_BOOT_OFFS 0x800
#define CONFIG_SYS_NAND_U_BOOT_SIZE 0x30000

-#define CONFIG_SYS_NAND_U_BOOT_DST (0x81fc0000)
+#define CONFIG_SYS_NAND_U_BOOT_DST (0x81fc1000)
#define CONFIG_SYS_NAND_U_BOOT_START CONFIG_SYS_NAND_U_BOOT_DST

#define CONFIG_SYS_NAND_PAGE_SIZE 2048
diff --git a/nand_spl/board/karo/tx25/u-boot.lds b/nand_spl/board/karo/tx25/u-boot.lds
index c572557..b60c0df 100644
--- a/nand_spl/board/karo/tx25/u-boot.lds
+++ b/nand_spl/board/karo/tx25/u-boot.lds
@@ -55,6 +55,7 @@ SECTIONS

__got_start = .;
. = ALIGN(4);
+ __got_base = .;
.got : { *(.got) }

__got_end = .;
--
1.7.0.4