Patchwork [U-Boot] arm relocation: Fix calculation of board_init_r

login
register
mail settings
Submitter Alexander Stein
Date Feb. 3, 2011, 8:52 p.m.
Message ID <1296766349-4695-1-git-send-email-alexander.stein@informatik.tu-chemnitz.de>
Download mbox | patch
Permalink /patch/81723/
State Accepted
Commit 6087f1a90cb2f275752496229b96f0e00aa0a7cd
Delegated to: Albert ARIBAUD
Headers show

Comments

Alexander Stein - Feb. 3, 2011, 8:52 p.m.
Signed-off-by: Alexander Stein <alexander.stein@informatik.tu-chemnitz.de>
---
Hello,

I just played a bit with my at91sam9g20ek and tried using a new u-boot.
So I compiled 656b990daa84bfdd512407ee2e3d2610e305a455 (atmel/wip110202) load
it into memory using jtag to 0x22000000 while it was linked to 0x20000000.
I stepped through the relocation code and at start.S:291 'mov pc, lr' the pc
gets an invalid address (0x25F81D70 while memory ends at 0x24000000).
While stepping to start.S:286 some registers have the following contents:
r0: 00000d70
r1: 22000000
r9: 03f81000
lr: 22000d70
The content if r0 seems ok, but r1 seems wrong, it should be 0x20000000.
Indeed r1 should contain the linked address of _start not the address
relative from the current code.

Just for the records, here is the output of u-boot while DEBUG is set in
board.c:
U-Boot 2010.12-00322-g656b990-dirty (Feb 03 2011 - 20:40:07)

U-Boot code: 20000000 -> 2002DAE8  BSS: -> 2006EE80
CPU: AT91SAM9G20
Crystal frequency:   18.432 MHz
CPU clock        :  396.288 MHz
Master clock     :  132.096 MHz
monitor len: 0006EE80
ramsize: 04000000
TLB table at: 23ff0000
Top of RAM usable for U-Boot at: 23ff0000
Reserving 443k for U-Boot at: 23f81000
Reserving 644k for malloc() at: 23ee0000
Reserving 24 Bytes for Board Info at: 23edffe8
Reserving 144 Bytes for Global Data at: 23edff58
New Stack Pointer is: 23edff50
RAM Configuration:
Bank #0: 20000000 64 MiB
relocation Offset is: 03f81000

If I load u-boot to the linking address (no relocation needed), everything
works fine, obviously.

Best regards,
Alexander

 arch/arm/cpu/arm926ejs/start.S |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Albert ARIBAUD - Feb. 5, 2011, 7:53 a.m.
Hi Alexander,

Le 03/02/2011 21:52, Alexander Stein a écrit :
> Signed-off-by: Alexander Stein<alexander.stein@informatik.tu-chemnitz.de>
> ---
> Hello,
>
> I just played a bit with my at91sam9g20ek and tried using a new u-boot.
> So I compiled 656b990daa84bfdd512407ee2e3d2610e305a455 (atmel/wip110202) load
> it into memory using jtag to 0x22000000 while it was linked to 0x20000000.

Side note: loading and starting U-Boot at an address different from the 
one which it was linked for is not currently supported.

> I stepped through the relocation code and at start.S:291 'mov pc, lr' the pc
> gets an invalid address (0x25F81D70 while memory ends at 0x24000000).
> While stepping to start.S:286 some registers have the following contents:
> r0: 00000d70
> r1: 22000000
> r9: 03f81000
> lr: 22000d70
> The content if r0 seems ok, but r1 seems wrong, it should be 0x20000000.
> Indeed r1 should contain the linked address of _start not the address
> relative from the current code.

Correct, since we're trying to find the post-relocation address of 
board_init_r, we should add the relocation offet to its link-time 
address, not run-time address -- the fact that both are the same right 
now is only incidental. Thus:

Applied to u-boot-arm, thanks.

Amicalement,

Patch

diff --git a/arch/arm/cpu/arm926ejs/start.S b/arch/arm/cpu/arm926ejs/start.S
index eb93ac9..f4c177e 100644
--- a/arch/arm/cpu/arm926ejs/start.S
+++ b/arch/arm/cpu/arm926ejs/start.S
@@ -281,7 +281,7 @@  _nand_boot_ofs:
 	.word nand_boot
 #else
 	ldr	r0, _board_init_r_ofs
-	adr	r1, _start
+	ldr	r1, _TEXT_BASE
 	add	lr, r0, r1
 	add	lr, lr, r9
 	/* setup parameters for board_init_r */