2010-09-17 11:10:39 +00:00
|
|
|
To make relocation on arm working, the following changes are done:
|
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
At arch level: add linker flag -pie
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
This causes the linker to generate fixup tables .rel.dyn and .dynsym,
|
|
|
|
which must be applied to the relocated image before transferring
|
|
|
|
control to it.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
These fixups are described in the ARM ELF documentation as type 23
|
|
|
|
(program-base-relative) and 2 (symbol-relative)
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
At cpu level: modify linker file and add a relocation and fixup loop
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
the linker file must be modified to include the .rel.dyn and .dynsym
|
|
|
|
tables in the binary image, and to provide symbols for the relocation
|
|
|
|
code to access these tables
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
The relocation and fixup loop must be executed after executing
|
|
|
|
board_init_f at initial location and before executing board_init_r
|
|
|
|
at final location.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
At board level:
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
dram_init(): bd pointer is now at this point not accessible, so only
|
|
|
|
detect the real dramsize, and store it in gd->ram_size. Bst detected
|
|
|
|
with get_ram_size().
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
TODO: move also dram initialization there on boards where it is possible.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
Setup of the the bd_t dram bank info is done in the new function
|
|
|
|
dram_init_banksize() called after bd is accessible.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
At lib level:
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
Board.c code is adapted from ppc code
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
|
|
|
|
|
|
|
|
Boards which are not fixed to support relocation will be REMOVED!
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
For boards which boot from nand_spl, it is possible to save one copy
|
2010-10-07 19:51:12 +00:00
|
|
|
if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
|
2010-09-17 11:10:42 +00:00
|
|
|
is copied again in relocate_code().
|
|
|
|
|
|
|
|
example for the tx25 board:
|
|
|
|
|
|
|
|
a) cpu starts
|
|
|
|
b) it copies the first page in nand to internal ram
|
|
|
|
(nand_spl_code)
|
|
|
|
c) end executes this code
|
|
|
|
d) this initialize CPU, RAM, ... and copy itself to RAM
|
|
|
|
(this bin must fit in one page, so board_init_f()
|
|
|
|
don;t fit in it ... )
|
|
|
|
e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
|
|
|
|
starts this image @ CONFIG_SYS_NAND_U_BOOT_START
|
|
|
|
f) u-boot code steps through board_init_f() and calculates
|
|
|
|
the relocation address and copy itself to it
|
|
|
|
|
2010-10-07 19:51:12 +00:00
|
|
|
If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
|
2010-09-17 11:10:42 +00:00
|
|
|
in f) could be saved.
|
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
2010-09-17 11:10:42 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
TODO
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
- fill in bd_t infos (check)
|
|
|
|
- adapt all boards
|
|
|
|
|
2010-10-07 19:51:12 +00:00
|
|
|
- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
|
2010-09-17 11:10:39 +00:00
|
|
|
This *must* be done for boards, which boot from NOR flash
|
|
|
|
|
2010-10-07 19:51:12 +00:00
|
|
|
on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
|
2010-09-17 11:10:39 +00:00
|
|
|
one copying from u-boot code.
|
|
|
|
|
|
|
|
- new function dram_init_banksize() is actual board specific. Maybe
|
|
|
|
we make a weak default function in arch/arm/lib/board.c ?
|
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
Relocation with NAND_SPL (example for the tx25):
|
|
|
|
|
|
|
|
- cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
|
|
|
|
and start with code execution on this address.
|
|
|
|
|
|
|
|
- The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
|
2010-10-27 20:48:30 +00:00
|
|
|
which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
|
2010-09-17 11:10:39 +00:00
|
|
|
the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
|
|
|
|
@CONFIG_SYS_NAND_U_BOOT_START
|
|
|
|
|
2010-10-18 21:43:37 +00:00
|
|
|
- This u-boot does no RAM init, nor CPU register setup. Just look
|
|
|
|
where it has to copy and relocate itself to this address. If
|
|
|
|
relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the
|
|
|
|
CONFIG_SYS_TEXT_BASE from the nand_spl code), then there is no need
|
|
|
|
to copy, just go on with bss clear and jump to board_init_r.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
How ELF relocations 23 and 2 work.
|
2010-09-17 11:10:39 +00:00
|
|
|
|
2010-10-11 11:13:28 +00:00
|
|
|
TBC
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Debugging u-boot in RAM:
|
|
|
|
(example on the qong board)
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
2011-04-28 06:49:47 +00:00
|
|
|
a) start debugger
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
arm-linux-gdb u-boot
|
|
|
|
|
|
|
|
[hs@pollux u-boot]$ arm-linux-gdb u-boot
|
|
|
|
GNU gdb Red Hat Linux (6.7-2rh)
|
|
|
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
|
|
|
This is free software: you are free to change and redistribute it.
|
|
|
|
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
|
|
|
|
and "show warranty" for details.
|
|
|
|
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
|
|
|
|
The target architecture is set automatically (currently arm)
|
|
|
|
..
|
|
|
|
(gdb)
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
2011-04-28 06:49:47 +00:00
|
|
|
b) connect to target
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
target remote bdi10:2001
|
|
|
|
|
|
|
|
(gdb) target remote bdi10:2001
|
|
|
|
Remote debugging using bdi10:2001
|
|
|
|
0x8ff17f10 in ?? ()
|
|
|
|
(gdb)
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
2011-04-28 06:49:47 +00:00
|
|
|
c) discard symbol-file
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
(gdb) symbol-file
|
|
|
|
Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
|
|
|
|
No symbol file now.
|
|
|
|
(gdb)
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
2011-04-28 06:49:47 +00:00
|
|
|
d) load new symbol table:
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
(gdb) add-symbol-file u-boot 0x8ff08000
|
|
|
|
add symbol table from file "u-boot" at
|
2010-10-27 20:48:30 +00:00
|
|
|
.text_addr = 0x8ff08000
|
2010-09-17 11:10:39 +00:00
|
|
|
(y or n) y
|
|
|
|
Reading symbols from /home/hs/celf/u-boot/u-boot...done.
|
|
|
|
(gdb) c
|
|
|
|
Continuing.
|
|
|
|
^C
|
|
|
|
Program received signal SIGSTOP, Stopped (signal).
|
|
|
|
0x8ff17f18 in serial_getc () at serial_mxc.c:192
|
2010-10-27 20:48:30 +00:00
|
|
|
192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
|
2010-09-17 11:10:39 +00:00
|
|
|
(gdb)
|
|
|
|
|
|
|
|
add-symbol-file u-boot 0x8ff08000
|
2010-10-27 20:48:30 +00:00
|
|
|
^^^^^^^^^^
|
2011-04-28 06:49:47 +00:00
|
|
|
get this address from u-boot bdinfo command
|
|
|
|
|
|
|
|
=> bdinfo
|
|
|
|
rch_number = XXXXXXXXXX
|
|
|
|
boot_params = XXXXXXXXXX
|
|
|
|
DRAM bank = XXXXXXXXXX
|
|
|
|
-> start = XXXXXXXXXX
|
|
|
|
-> size = XXXXXXXXXX
|
|
|
|
ethaddr = XXXXXXXXXX
|
|
|
|
ip_addr = XXXXXXXXXX
|
|
|
|
baudrate = XXXXXXXXXX
|
|
|
|
TLB addr = XXXXXXXXXX
|
|
|
|
relocaddr = 0x8ff08000
|
|
|
|
^^^^^^^^^^
|
|
|
|
reloc off = XXXXXXXXXX
|
|
|
|
irq_sp = XXXXXXXXXX
|
|
|
|
sp start = XXXXXXXXXX
|
|
|
|
FB base = XXXXXXXXXX
|
2010-09-17 11:10:39 +00:00
|
|
|
|
|
|
|
Now you can use gdb as usual :-)
|