[U-Boot] [PATCH] arm1176: fix relocation

Heiko Schocher
2010-10-25T06:17:14Z

Hello Darius,

Darius Augulis wrote:
> Fix relocation code for arm1176, do it like other ARM
> CPU's are doing.
> Tested only with CONFIG_SKIP_RELOCATE_UBOOT defined
> and using nand_spl (booting from nand). Test done on
> s3c6410 based board (not yet supported in main line).
>
> Signed-off-by: Darius Augulis <augulis.darius@gmail.com>
> ---
> arch/arm/cpu/arm1176/start.S | 139 +++++++++++++++++++++++----------------
> arch/arm/cpu/arm1176/u-boot.lds | 15 +++-
> 2 files changed, 94 insertions(+), 60 deletions(-)

Thanks, some comments below:

> diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S
> index 24e5bf4..0d733f7 100644
> --- a/arch/arm/cpu/arm1176/start.S
> +++ b/arch/arm/cpu/arm1176/start.S
[...]
> @@ -288,24 +295,44 @@ copy_loop:
> blo copy_loop
>
> #ifndef CONFIG_PRELOADER
> - /* fix got entries */
> - ldr r1, _TEXT_BASE /* Text base */
> - mov r0, r7 /* reloc addr */
> - ldr r2, _got_start /* addr in Flash */
> - ldr r3, _got_end /* addr in Flash */
> - sub r3, r3, r1
> - add r3, r3, r0
> - sub r2, r2, r1
> - add r2, r2, r0
> -
> + /*
> + * fix .rel.dyn relocations
> + */
> + ldr r0, _TEXT_BASE /* r0 <- Text base */
> + sub r9, r7, r0 /* r9 <- relocation offset */
> + ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
> + add r10, r10, r0 /* r10 <- sym table in FLASH */
> + ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
> + add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
> + ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
> + add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
> fixloop:
> - ldr r4, [r2]
> - sub r4, r4, r1
> - add r4, r4, r0
> - str r4, [r2]
> - add r2, r2, #4
> + ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
> + add r0, r9 /* r0 <- location to fix up in RAM */

should be

add r0, r0, r9

> + ldr r1, [r2, #4]
> + and r8, r1, #0xff
> + cmp r8, #23 /* relative fixup? */
> + beq fixrel
> + cmp r8, #2 /* absolute fixup? */
> + beq fixabs
> + /* ignore unknown type of fixup */
> + b fixnext
> +fixabs:
> + /* absolute fix: set location to (offset) symbol value */
> + mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
> + add r1, r10, r1 /* r1 <- address of symbol in table */
> + ldr r1, [r1, #4] /* r1 <- symbol value */
> + add r1, r9 /* r1 <- relocated sym addr */

should be

add r1, r1, r9

> + b fixnext
> +fixrel:
> + /* relative fix: increase location by offset */
> + ldr r1, [r0]
> + add r1, r1, r9
> +fixnext:
> + str r1, [r0]
> + add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
> cmp r2, r3
> - bne fixloop
> + ble fixloop

should be blo instead of blo

> #endif
> #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
>
[...]

bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany