From 97b920dab1e4fd9a05ff9dccc7853d588c73ae19 Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:12 +0100 Subject: MIPS: xburst: fix broken access to global_data Fix access to global_data which is broken since commits: commit 035cbe99cd2fd4adf9d7fd95aeebb5f814e37eb9 Author: Simon Glass Date: Thu Dec 13 20:49:08 2012 +0000 mips: Move per_clk and dev_clk to arch_global_data Move these field into arch_global_data and tidy up. The other CONFIG_JZSOC fields are used by various architectures, so just remove the #ifdef bracketing for these. Signed-off-by: Simon Glass commit 582601da2f90b1850aa19f7820b1623c79b3dac6 Author: Simon Glass Date: Thu Dec 13 20:48:35 2012 +0000 arm: Move lastinc to arch_global_data Move this field into arch_global_data and tidy up. Signed-off-by: Simon Glass commit 66ee69234795c0596f84b25f06b7fbc2e8ed214c Author: Simon Glass Date: Thu Dec 13 20:48:34 2012 +0000 arm: Move tbl to arch_global_data Move this field into arch_global_data and tidy up. Signed-off-by: Simon Glass Signed-off-by: Daniel Schwierzeck Cc: Xiangfu Liu --- arch/mips/include/asm/global_data.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'arch/mips/include/asm') diff --git a/arch/mips/include/asm/global_data.h b/arch/mips/include/asm/global_data.h index b39737fea3..f912428cae 100644 --- a/arch/mips/include/asm/global_data.h +++ b/arch/mips/include/asm/global_data.h @@ -32,6 +32,9 @@ struct arch_global_data { /* There are other clocks in the jz4740 */ unsigned long per_clk; /* Peripheral bus clock */ unsigned long dev_clk; /* Device clock */ + unsigned long sys_clk; + unsigned long tbl; + unsigned long lastinc; #endif }; -- cgit v1.2.3 From a52852c5a65fe6636c7408829eced892deefc1de Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:12 +0100 Subject: MIPS: u-boot.lds: merge all BSS sections and introduce symbols __bss_[start|end] These symbols are used in later patches for as addresses for clearing the BSS area in the relocated U-Boot image. Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/u-boot.lds | 11 ++++++----- arch/mips/include/asm/u-boot-mips.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'arch/mips/include/asm') diff --git a/arch/mips/cpu/u-boot.lds b/arch/mips/cpu/u-boot.lds index 58a49b2137..6980b86b9f 100644 --- a/arch/mips/cpu/u-boot.lds +++ b/arch/mips/cpu/u-boot.lds @@ -70,13 +70,14 @@ SECTIONS uboot_end_data = .; . = ALIGN(4); - .sbss : { - *(.sbss*) - } - .bss : { - *(.bss*) + __bss_start = .; + *(.sbss.*) + *(.bss.*) + *(COMMON) . = ALIGN(4); + __bss_end = .; } + uboot_end = .; } diff --git a/arch/mips/include/asm/u-boot-mips.h b/arch/mips/include/asm/u-boot-mips.h index 6f26dfac56..eda0498734 100644 --- a/arch/mips/include/asm/u-boot-mips.h +++ b/arch/mips/include/asm/u-boot-mips.h @@ -8,4 +8,16 @@ extern ulong uboot_end_data; extern ulong uboot_end; +static inline unsigned long bss_start(void) +{ + extern ulong __bss_start; + return (unsigned long) &__bss_start; +} + +static inline unsigned long bss_end(void) +{ + extern ulong __bss_end; + return (unsigned long) &__bss_end; +} + extern int incaip_set_cpuclk(void); -- cgit v1.2.3 From 3420bf1ca0631ef6347fece1e9f0eb38b1051a98 Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:12 +0100 Subject: MIPS: u-boot.lds: introduce symbol __image_copy_end This symbol is used in later patches as end address for relocation of the U-Boot image into RAM. Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/u-boot.lds | 2 ++ arch/mips/include/asm/u-boot-mips.h | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'arch/mips/include/asm') diff --git a/arch/mips/cpu/u-boot.lds b/arch/mips/cpu/u-boot.lds index 6980b86b9f..7b5fca0963 100644 --- a/arch/mips/cpu/u-boot.lds +++ b/arch/mips/cpu/u-boot.lds @@ -70,6 +70,8 @@ SECTIONS uboot_end_data = .; . = ALIGN(4); + __image_copy_end = .; + .bss : { __bss_start = .; *(.sbss.*) diff --git a/arch/mips/include/asm/u-boot-mips.h b/arch/mips/include/asm/u-boot-mips.h index eda0498734..bfb6a4a43a 100644 --- a/arch/mips/include/asm/u-boot-mips.h +++ b/arch/mips/include/asm/u-boot-mips.h @@ -20,4 +20,10 @@ static inline unsigned long bss_end(void) return (unsigned long) &__bss_end; } +static inline unsigned long image_copy_end(void) +{ + extern ulong __image_copy_end; + return (unsigned long) &__image_copy_end; +} + extern int incaip_set_cpuclk(void); -- cgit v1.2.3 From 28875e2c4731296ee7ed645d07f1c28c0301f1c4 Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:13 +0100 Subject: MIPS: start.S: use symbol __image_copy_end for U-Boot image relocation Use the newly introduced symbol __image_copy_end as end address for relocation of U-Boot image. This is needed for dynamic relocation added in later patches. This patch obsoletes the symbols uboot_end and uboot_end_data which are removed. Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/mips32/start.S | 7 +++---- arch/mips/cpu/mips64/start.S | 7 +++---- arch/mips/cpu/u-boot.lds | 4 ---- arch/mips/cpu/xburst/start.S | 7 +++---- arch/mips/include/asm/u-boot-mips.h | 3 --- 5 files changed, 9 insertions(+), 19 deletions(-) (limited to 'arch/mips/include/asm') diff --git a/arch/mips/cpu/mips32/start.S b/arch/mips/cpu/mips32/start.S index cd8b914da3..649c0bbf5c 100644 --- a/arch/mips/cpu/mips32/start.S +++ b/arch/mips/cpu/mips32/start.S @@ -173,7 +173,7 @@ relocate_code: sub s1, s2, t0 # s1 <-- relocation offset la t3, in_ram - lw t2, -12(t3) # t2 <-- uboot_end_data + lw t2, -12(t3) # t2 <-- __image_copy_end move t1, a2 add gp, s1 # adjust gp @@ -201,9 +201,8 @@ relocate_code: jr t0 nop + .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ - .word uboot_end_data - .word uboot_end .word num_got_entries in_ram: @@ -214,7 +213,7 @@ in_ram: * generated by GNU ld. Skip these reserved entries from relocation. */ lw t3, -4(t0) # t3 <-- num_got_entries - lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ + lw t4, -8(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ add t4, s1 # t4 now holds relocated _G_O_T_ addi t4, t4, 8 # skipping first two entries li t2, 2 diff --git a/arch/mips/cpu/mips64/start.S b/arch/mips/cpu/mips64/start.S index ba4ca4de38..5c2c7b5bad 100644 --- a/arch/mips/cpu/mips64/start.S +++ b/arch/mips/cpu/mips64/start.S @@ -165,7 +165,7 @@ relocate_code: dsub s1, s2, t0 # s1 <-- relocation offset dla t3, in_ram - ld t2, -24(t3) # t2 <-- uboot_end_data + ld t2, -24(t3) # t2 <-- __image_copy_end move t1, a2 dadd gp, s1 # adjust gp @@ -193,9 +193,8 @@ relocate_code: jr t0 nop + .dword __image_copy_end .dword _GLOBAL_OFFSET_TABLE_ - .dword uboot_end_data - .dword uboot_end .dword num_got_entries in_ram: @@ -206,7 +205,7 @@ in_ram: * generated by GNU ld. Skip these reserved entries from relocation. */ ld t3, -8(t0) # t3 <-- num_got_entries - ld t8, -32(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_ + ld t8, -16(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_ dadd t8, s1 # t8 now holds relocated _G_O_T_ daddi t8, t8, 16 # skipping first two entries dli t2, 2 diff --git a/arch/mips/cpu/u-boot.lds b/arch/mips/cpu/u-boot.lds index 7b5fca0963..4cd983ae4f 100644 --- a/arch/mips/cpu/u-boot.lds +++ b/arch/mips/cpu/u-boot.lds @@ -67,8 +67,6 @@ SECTIONS #include } - uboot_end_data = .; - . = ALIGN(4); __image_copy_end = .; @@ -80,6 +78,4 @@ SECTIONS . = ALIGN(4); __bss_end = .; } - - uboot_end = .; } diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index bd9390ae5e..6b30d3ee8a 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -67,7 +67,7 @@ relocate_code: sub t6, a2, t0 # t6 <-- relocation offset la t3, in_ram - lw t2, -12(t3) # t2 <-- uboot_end_data + lw t2, -12(t3) # t2 <-- __image_copy_end move t1, a2 add gp, t6 # adjust gp @@ -116,9 +116,8 @@ relocate_code: jr t0 nop + .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ - .word uboot_end_data - .word uboot_end .word num_got_entries in_ram: @@ -129,7 +128,7 @@ in_ram: * generated by GNU ld. Skip these reserved entries from relocation. */ lw t3, -4(t0) # t3 <-- num_got_entries - lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ + lw t4, -8(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ add t4, t6 # t4 now holds relocated _G_O_T_ addi t4, t4, 8 # skipping first two entries li t2, 2 diff --git a/arch/mips/include/asm/u-boot-mips.h b/arch/mips/include/asm/u-boot-mips.h index bfb6a4a43a..a483166a9c 100644 --- a/arch/mips/include/asm/u-boot-mips.h +++ b/arch/mips/include/asm/u-boot-mips.h @@ -5,9 +5,6 @@ * Copyright (C) 2003 Wolfgang Denk, DENX Software Engineering, wd@denx.de */ -extern ulong uboot_end_data; -extern ulong uboot_end; - static inline unsigned long bss_start(void) { extern ulong __bss_start; -- cgit v1.2.3 From 04380c651a2ff0d1495822321d2b7668dcd02537 Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Tue, 12 Feb 2013 22:22:13 +0100 Subject: MIPS: add dynamic relocation support The code handles relocation entries with the following relocation types only: mips32: R_MIPS_REL32 mips64: R_MIPS_REL+R_MIPS_64 xburst: R_MIPS_REL32 Other relocation entries are skipped without processing. The code must be extended if other relocation types must be supported. Add -pie to LDFLAGS_FINAL to generate the .rel.dyn fixup table, which will be applied to the relocated image before transferring control to it. The CONFIG_NEEDS_MANUAL_RELOC is not needed after the patch, so remove that as well. Signed-off-by: Gabor Juhos Signed-off-by: Daniel Schwierzeck --- arch/mips/config.mk | 3 ++- arch/mips/cpu/mips32/start.S | 28 ++++++++++++++++++++++++++++ arch/mips/cpu/mips64/start.S | 36 ++++++++++++++++++++++++++++++++++++ arch/mips/cpu/xburst/start.S | 28 ++++++++++++++++++++++++++++ arch/mips/include/asm/config.h | 2 -- arch/mips/lib/board.c | 9 --------- 6 files changed, 94 insertions(+), 12 deletions(-) (limited to 'arch/mips/include/asm') diff --git a/arch/mips/config.mk b/arch/mips/config.mk index de9140b67b..aaa94e8be2 100644 --- a/arch/mips/config.mk +++ b/arch/mips/config.mk @@ -65,4 +65,5 @@ PLATFORM_CPPFLAGS += -G 0 -mabicalls -fpic $(ENDIANNESS) PLATFORM_CPPFLAGS += -msoft-float PLATFORM_LDFLAGS += -G 0 -static -n -nostdlib $(ENDIANNESS) PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections -LDFLAGS_FINAL += --gc-sections +LDFLAGS_FINAL += --gc-sections -pie +OBJCFLAGS += --remove-section=.dynsym diff --git a/arch/mips/cpu/mips32/start.S b/arch/mips/cpu/mips32/start.S index 649c0bbf5c..76abbaa273 100644 --- a/arch/mips/cpu/mips32/start.S +++ b/arch/mips/cpu/mips32/start.S @@ -201,6 +201,8 @@ relocate_code: jr t0 nop + .word __rel_dyn_end + .word __rel_dyn_start .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ .word num_got_entries @@ -227,6 +229,32 @@ in_ram: blt t2, t3, 1b addi t4, 4 + /* Update dynamic relocations */ + lw t1, -16(t0) # t1 <-- __rel_dyn_start + lw t2, -20(t0) # t2 <-- __rel_dyn_end + + b 2f # skip first reserved entry + addi t1, 8 + +1: + lw t3, -4(t1) # t3 <-- relocation info + + sub t3, 3 + bnez t3, 2f # skip non R_MIPS_REL32 entries + nop + + lw t3, -8(t1) # t3 <-- location to fix up in FLASH + + lw t4, 0(t3) # t4 <-- original pointer + add t4, s1 # t4 <-- adjusted pointer + + add t3, s1 # t3 <-- location to fix up in RAM + sw t4, 0(t3) + +2: + blt t1, t2, 1b + addi t1, 8 # each rel.dyn entry is 8 bytes + /* * Clear BSS * diff --git a/arch/mips/cpu/mips64/start.S b/arch/mips/cpu/mips64/start.S index 5c2c7b5bad..dc7ce07ce7 100644 --- a/arch/mips/cpu/mips64/start.S +++ b/arch/mips/cpu/mips64/start.S @@ -31,6 +31,14 @@ #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT #endif +#ifdef CONFIG_SYS_LITTLE_ENDIAN +#define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \ + (((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym)) +#else +#define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \ + ((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24) +#endif + /* * For the moment disable interrupts, mark the kernel mode and * set ST0_KX so that the CPU does not spit fire when using @@ -193,6 +201,8 @@ relocate_code: jr t0 nop + .dword __rel_dyn_end + .dword __rel_dyn_start .dword __image_copy_end .dword _GLOBAL_OFFSET_TABLE_ .dword num_got_entries @@ -219,6 +229,32 @@ in_ram: blt t2, t3, 1b daddi t8, 8 + /* Update dynamic relocations */ + ld t1, -32(t0) # t1 <-- __rel_dyn_start + ld t2, -40(t0) # t2 <-- __rel_dyn_end + + b 2f # skip first reserved entry + daddi t1, 16 + +1: + lw t8, -4(t1) # t8 <-- relocation info + + dli t3, MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03) + bne t8, t3, 2f # skip non R_MIPS_REL32 entries + nop + + ld t3, -16(t1) # t3 <-- location to fix up in FLASH + + ld t8, 0(t3) # t8 <-- original pointer + dadd t8, s1 # t8 <-- adjusted pointer + + dadd t3, s1 # t3 <-- location to fix up in RAM + sd t8, 0(t3) + +2: + blt t1, t2, 1b + daddi t1, 16 # each rel.dyn entry is 16 bytes + /* * Clear BSS * diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 6b30d3ee8a..d2c064b017 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -116,6 +116,8 @@ relocate_code: jr t0 nop + .word __rel_dyn_end + .word __rel_dyn_start .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ .word num_got_entries @@ -142,6 +144,32 @@ in_ram: blt t2, t3, 1b addi t4, 4 + /* Update dynamic relocations */ + lw t1, -16(t0) # t1 <-- __rel_dyn_start + lw t2, -20(t0) # t2 <-- __rel_dyn_end + + b 2f # skip first reserved entry + addi t1, 8 + +1: + lw t3, -4(t1) # t3 <-- relocation info + + sub t3, 3 + bnez t3, 2f # skip non R_MIPS_REL32 entries + nop + + lw t3, -8(t1) # t3 <-- location to fix up in FLASH + + lw t4, 0(t3) # t4 <-- original pointer + add t4, t6 # t4 <-- adjusted pointer + + add t3, t6 # t3 <-- location to fix up in RAM + sw t4, 0(t3) + +2: + blt t1, t2, 1b + addi t1, 8 # each rel.dyn entry is 8 bytes + /* * Clear BSS * diff --git a/arch/mips/include/asm/config.h b/arch/mips/include/asm/config.h index 02fbfb3abf..049c44eaf8 100644 --- a/arch/mips/include/asm/config.h +++ b/arch/mips/include/asm/config.h @@ -21,6 +21,4 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_NEEDS_MANUAL_RELOC - #endif diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c index d494876b13..2ec0f7638c 100644 --- a/arch/mips/lib/board.c +++ b/arch/mips/lib/board.c @@ -266,14 +266,6 @@ void board_init_r(gd_t *id, ulong dest_addr) serial_initialize(); -#if defined(CONFIG_NEEDS_MANUAL_RELOC) - /* - * We have to relocate the command table manually - */ - fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd), - ll_entry_count(cmd_tbl_t, cmd)); -#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ - /* there are some other pointer constants we must deal with */ #ifndef CONFIG_ENV_IS_NOWHERE env_name_spec += gd->reloc_off; @@ -284,7 +276,6 @@ void board_init_r(gd_t *id, ulong dest_addr) /* The Malloc area is immediately below the monitor copy in DRAM */ mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off - TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN); - malloc_bin_reloc(); #ifndef CONFIG_SYS_NO_FLASH /* configure available FLASH banks */ -- cgit v1.2.3