blob: 5a9a2fb07105b5aefe3a4cda44082a894950569c [file] [log] [blame]
Heiko Schocherf1d2b312010-09-17 13:10:39 +02001To make relocation on arm working, the following changes are done:
2
Albert Aribaud92d5ecb2010-10-11 13:13:28 +02003At arch level: add linker flag -pie
Heiko Schocherf1d2b312010-09-17 13:10:39 +02004
Albert Aribaud92d5ecb2010-10-11 13:13:28 +02005 This causes the linker to generate fixup tables .rel.dyn and .dynsym,
6 which must be applied to the relocated image before transferring
7 control to it.
Heiko Schocherf1d2b312010-09-17 13:10:39 +02008
Albert Aribaud92d5ecb2010-10-11 13:13:28 +02009 These fixups are described in the ARM ELF documentation as type 23
10 (program-base-relative) and 2 (symbol-relative)
Heiko Schocherf1d2b312010-09-17 13:10:39 +020011
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020012At cpu level: modify linker file and add a relocation and fixup loop
Heiko Schocherf1d2b312010-09-17 13:10:39 +020013
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020014 the linker file must be modified to include the .rel.dyn and .dynsym
15 tables in the binary image, and to provide symbols for the relocation
16 code to access these tables
Heiko Schocherf1d2b312010-09-17 13:10:39 +020017
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020018 The relocation and fixup loop must be executed after executing
19 board_init_f at initial location and before executing board_init_r
20 at final location.
Heiko Schocherf1d2b312010-09-17 13:10:39 +020021
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020022At board level:
Heiko Schocherf1d2b312010-09-17 13:10:39 +020023
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020024 dram_init(): bd pointer is now at this point not accessible, so only
25 detect the real dramsize, and store it in gd->ram_size. Bst detected
26 with get_ram_size().
Heiko Schocherf1d2b312010-09-17 13:10:39 +020027
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020028TODO: move also dram initialization there on boards where it is possible.
Heiko Schocherf1d2b312010-09-17 13:10:39 +020029
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020030 Setup of the the bd_t dram bank info is done in the new function
31 dram_init_banksize() called after bd is accessible.
Heiko Schocherf1d2b312010-09-17 13:10:39 +020032
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020033At lib level:
Heiko Schocherf1d2b312010-09-17 13:10:39 +020034
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020035 Board.c code is adapted from ppc code
Heiko Schocherf1d2b312010-09-17 13:10:39 +020036
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020037* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
Heiko Schocherf1d2b312010-09-17 13:10:39 +020038
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020039Boards which are not fixed to support relocation will be REMOVED!
40
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020041-----------------------------------------------------------------------------
42
43For boards which boot from nand_spl, it is possible to save one copy
Wolfgang Denk14d0a022010-10-07 21:51:12 +020044if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
Heiko Schocherab86f722010-09-17 13:10:42 +020045is copied again in relocate_code().
46
47example for the tx25 board:
48
49a) cpu starts
50b) it copies the first page in nand to internal ram
51 (nand_spl_code)
52c) end executes this code
53d) this initialize CPU, RAM, ... and copy itself to RAM
54 (this bin must fit in one page, so board_init_f()
55 don;t fit in it ... )
56e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
57 starts this image @ CONFIG_SYS_NAND_U_BOOT_START
58f) u-boot code steps through board_init_f() and calculates
59 the relocation address and copy itself to it
60
Wolfgang Denk14d0a022010-10-07 21:51:12 +020061If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
Heiko Schocherab86f722010-09-17 13:10:42 +020062in f) could be saved.
63
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020064-----------------------------------------------------------------------------
Heiko Schocherab86f722010-09-17 13:10:42 +020065
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020066TODO
Heiko Schocherf1d2b312010-09-17 13:10:39 +020067
68- fill in bd_t infos (check)
69- adapt all boards
70
Wolfgang Denk14d0a022010-10-07 21:51:12 +020071- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
Heiko Schocherf1d2b312010-09-17 13:10:39 +020072 This *must* be done for boards, which boot from NOR flash
73
Wolfgang Denk14d0a022010-10-07 21:51:12 +020074 on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
Heiko Schocherf1d2b312010-09-17 13:10:39 +020075 one copying from u-boot code.
76
77- new function dram_init_banksize() is actual board specific. Maybe
78 we make a weak default function in arch/arm/lib/board.c ?
79
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020080-----------------------------------------------------------------------------
Heiko Schocherf1d2b312010-09-17 13:10:39 +020081
82Relocation with NAND_SPL (example for the tx25):
83
84- cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
85 and start with code execution on this address.
86
87- The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
Wolfgang Denk071bc922010-10-27 22:48:30 +020088 which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
Heiko Schocherf1d2b312010-09-17 13:10:39 +020089 the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
90 @CONFIG_SYS_NAND_U_BOOT_START
91
Wolfgang Denkc8d76ea2010-10-18 23:43:37 +020092- This u-boot does no RAM init, nor CPU register setup. Just look
93 where it has to copy and relocate itself to this address. If
94 relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the
95 CONFIG_SYS_TEXT_BASE from the nand_spl code), then there is no need
96 to copy, just go on with bss clear and jump to board_init_r.
Heiko Schocherf1d2b312010-09-17 13:10:39 +020097
Albert Aribaud92d5ecb2010-10-11 13:13:28 +020098-----------------------------------------------------------------------------
Heiko Schocherf1d2b312010-09-17 13:10:39 +020099
Albert Aribaud92d5ecb2010-10-11 13:13:28 +0200100How ELF relocations 23 and 2 work.
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200101
Albert Aribaud92d5ecb2010-10-11 13:13:28 +0200102TBC
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200103
104-------------------------------------------------------------------------------------
105
106Debugging u-boot in RAM:
107(example on the qong board)
108
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200109-----------------
110
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000111a) start debugger
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200112
113arm-linux-gdb u-boot
114
115[hs@pollux u-boot]$ arm-linux-gdb u-boot
116GNU gdb Red Hat Linux (6.7-2rh)
117Copyright (C) 2007 Free Software Foundation, Inc.
118License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
119This is free software: you are free to change and redistribute it.
120There is NO WARRANTY, to the extent permitted by law. Type "show copying"
121and "show warranty" for details.
122This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
123The target architecture is set automatically (currently arm)
124..
125(gdb)
126
127-----------------
128
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000129b) connect to target
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200130
131target remote bdi10:2001
132
133(gdb) target remote bdi10:2001
134Remote debugging using bdi10:2001
1350x8ff17f10 in ?? ()
136(gdb)
137
138-----------------
139
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000140c) discard symbol-file
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200141
142(gdb) symbol-file
143Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
144No symbol file now.
145(gdb)
146
147-----------------
148
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000149d) load new symbol table:
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200150
151(gdb) add-symbol-file u-boot 0x8ff08000
152add symbol table from file "u-boot" at
Wolfgang Denk071bc922010-10-27 22:48:30 +0200153 .text_addr = 0x8ff08000
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200154(y or n) y
155Reading symbols from /home/hs/celf/u-boot/u-boot...done.
156(gdb) c
157Continuing.
158^C
159Program received signal SIGSTOP, Stopped (signal).
1600x8ff17f18 in serial_getc () at serial_mxc.c:192
Wolfgang Denk071bc922010-10-27 22:48:30 +0200161192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200162(gdb)
163
164add-symbol-file u-boot 0x8ff08000
Wolfgang Denk071bc922010-10-27 22:48:30 +0200165 ^^^^^^^^^^
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000166 get this address from u-boot bdinfo command
Ben Gardiner71240152011-04-28 11:03:21 +0000167 or get it from gd->relocaddr in gdb
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200168
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000169 => bdinfo
170rch_number = XXXXXXXXXX
171boot_params = XXXXXXXXXX
172DRAM bank = XXXXXXXXXX
173-> start = XXXXXXXXXX
174-> size = XXXXXXXXXX
175ethaddr = XXXXXXXXXX
176ip_addr = XXXXXXXXXX
177baudrate = XXXXXXXXXX
178TLB addr = XXXXXXXXXX
179relocaddr = 0x8ff08000
Wolfgang Denkcd6881b2011-05-19 22:21:41 +0200180 ^^^^^^^^^^
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000181reloc off = XXXXXXXXXX
Wolfgang Denkcd6881b2011-05-19 22:21:41 +0200182irq_sp = XXXXXXXXXX
Ben Gardinerf4379ce2011-04-28 06:49:47 +0000183sp start = XXXXXXXXXX
184FB base = XXXXXXXXXX
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200185
Ben Gardiner71240152011-04-28 11:03:21 +0000186or interrupt execution by any means and re-load the symbols at the location
187specified by gd->relocaddr -- this is only valid after board_init_f.
188
189(gdb) set $s = gd->relocaddr
190(gdb) symbol-file
191(gdb) add-symbol-file u-boot $s
192
Heiko Schocherf1d2b312010-09-17 13:10:39 +0200193Now you can use gdb as usual :-)