]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - doc/README.arm-relocation
ARM: add relocation support
[karo-tx-uboot.git] / doc / README.arm-relocation
1 To make relocation on arm working, the following changes are done:
2
3 Add new compilerflag:
4
5 -fPIC
6
7         -> compiler generates position independent code
8
9 changes in board code:
10
11 - dram_init:
12   - bd pointer is now at this point not accessible, so only
13     detect the real dramsize, and store it in gd->ram_size.
14     best detected with get_ram_size();
15     ToDo: move there also the dram initialization on boards where
16           it is possible.
17   - setup the bd_t dram bank info in the new function
18     dram_init_banksize().
19
20 - board.c code is adapted from ppc code
21
22 - undef CONFIG_RELOC_FIXUP_WORKS
23
24   -> cmdtabl, and subcommand table must be handled from "hand"
25      collected in section "__datarellocal_start".
26
27   - How To fixup the sections:
28
29     __datarel_start, __datarelrolocal_start, __datarellocal_start and
30     __datarelro_start
31
32     automatically? Then it should be possible to define again
33     CONFIG_RELOC_FIXUP_WORKS
34
35 - irq stack setup is now not longer on a fix position, instead it is
36   calculated in board_init_f, and stored in gd->irq_sp
37
38 -------------------------------------------------------------------------------------
39
40 To compile a board without relocation, define CONFIG_SYS_ARM_WITHOUT_RELOC
41 This possibility will removed!! So please fix your board to compile without
42 CONFIG_SYS_ARM_WITHOUT_RELOC defined!!!
43
44 -------------------------------------------------------------------------------------
45
46 ToDo:
47
48 - fill in bd_t infos (check)
49 - adapt all boards
50
51 - maybe adapt TEXT_BASE (this must be checked from board maintainers)
52   This *must* be done for boards, which boot from NOR flash
53
54   on other boards if TEXT_BASE = relocation baseaddr, this saves
55   one copying from u-boot code.
56
57 - new function dram_init_banksize() is actual board specific. Maybe
58   we make a weak default function in arch/arm/lib/board.c ?
59
60 -------------------------------------------------------------------------------------
61
62 Relocation with NAND_SPL (example for the tx25):
63
64 - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
65   and start with code execution on this address.
66
67 - The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
68   which inits the dram, cpu registers, reloacte itself to TEXT_BASE  and loads
69   the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
70   @CONFIG_SYS_NAND_U_BOOT_START
71
72 - This u-boot does no ram int, nor cpu register setup. Just looks
73   where it have to relocate and relocate itself to this address.
74   If relocate address = TEXT_BASE(not the same, as the TEXT_BASE
75   from the nand_spl code), no need to copy, just go on with bss clear
76   and jump to board_init_r.
77
78 -------------------------------------------------------------------------------------
79
80 Relocation:
81 How to translate flash addresses in GOT to ram addresses.
82 This is automagically done from code, but this example
83 shows, how this magic code works ;-)
84 (example on the qong board)
85
86 Find a variable:
87
88 a) search it in System.map
89 (for example flash_info)
90
91 a005b4c0 B BootpID
92 a005b4c4 B BootpTry
93 a005b4c8 b slave
94 a005b4cc B flash_info
95 ^^^^^^^^
96 a005c908 b saved_sector.4002
97 a005c910 b cfi_mtd_info
98 a005c9c0 b cfi_mtd_names
99 a005c9d0 B mtd_table
100
101 ---------------------------------------
102
103 b) create hexdump from u-boot code:
104
105 hexdump -C u-boot > gnlmpfhex
106
107 ---------------------------------------
108
109 c) search the variables address in the hexdump
110
111
112 *
113 0005fc80  00 00 00 00 00 00 00 00  2c 06 01 a0 18 cd 05 a0  |........,.......|
114 0005fc90  9c d4 05 a0 bc b4 05 a0  1c 7f 05 a0 f0 05 01 a0  |................|
115 0005fca0  08 5a 04 a0 1c ab 05 a0  ec a4 05 a0 98 c3 01 a0  |.Z..............|
116 0005fcb0  a0 d6 05 a0 04 71 05 a0  c0 f9 00 a0 3c cd 05 a0  |.....q......<...|
117 0005fcc0  cc b4 05 a0 f0 fa 00 a0  f0 d6 05 a0 10 86 05 a0  |................|
118           ^^^^^^^^^^^
119 0005fcd0  a4 16 06 a0 dc 64 05 a0  18 86 05 a0 52 48 05 a0  |.....d......RH..|
120 0005fce0  c0 86 05 a0 24 6e 02 a0  b4 6c 05 a0 b0 94 01 a0  |....$n...l......|
121 0005fcf0  1c 86 05 a0 50 85 05 a0  d4 0c 06 a0 bc 0b 06 a0  |....P...........|
122
123
124 -> 0005fcc0
125
126 ----------------------------------------
127
128 d) know we calculate this address in RAM
129
130
131   8ff08000      (new address of code in RAM *1)
132
133 + 0005fcc0
134
135 - 00008000      (offset of text *2)
136
137 ----------
138
139   8ff5fcc0      -> Addr GOT in RAM
140
141 *1:
142 activate debug and look for the line:
143 Now running in RAM - U-Boot at: 8ff08000
144                                 ^^^^^^^^
145                                 new address of u-boot code in RAM
146
147 *2:
148 Section Headers:
149   [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
150   [ 0]                   NULL            00000000 000000 000000 00      0   0  0
151   [ 1] .text             PROGBITS        a0000000 008000 04599c 00  AX  0   0 32
152                                                   ^^^^^^
153                                                   Offset of text
154
155 ----------------------------------------
156
157 e) now we look in 8ff5fcc0 (RAM)
158
159
160 QongEVB>md 0x8ff5fcc0
161 8ff5fcc0 : a005b4cc a000faf0 a005d6f0 a0058610  ................
162            ^^^^^^^^
163            Bingo, here we have the old flash address (when relocation
164            is working, here is the fixed ram address. see @ f, how
165            it gets calculated)
166
167
168 ----------------------------------------
169
170 f) now translate it in the new RAM address
171
172   a005b4cc
173
174 - a0000000     TextBase
175
176 + 8ff08000     new address of u-boot in ram
177 ----------
178   8ff634cc
179
180 QongEVB>mm 0x8ff5fcc0 0x8ff634cc 1
181 QongEVB>md 0x8ff5fcc0
182 8ff5fcc0 : 8ff634cc a000faf0 a005d6f0 a0058610  .4..............
183 8ff5fcd0 : a00616a4 a00564dc a0058618 a0054852  .....d......RH..
184
185 As this must be done for all address in the GOT, the u-boot
186 code did this automagically ... :-)
187
188 ----------------------------------------------
189
190 g) check if the new address is really in the bss section:
191
192 bss start:
193 8ff6054c        (8ff08000 + 0005854C monitorlen)
194
195 bss end:
196 8ff698ac        (8ff08000 + 618AC)
197
198 8ff634cc is in bss :-)
199
200 ----------------------------------------------
201
202 h) u-boot prints:
203
204 important  addresses:
205
206 U-Boot code: A0000000 -> A005854C  BSS: -> A00618AC     TextBase 0xa0000000
207 Now running in RAM - U-Boot at: 8ff08000                relocBase 0x8ff08000
208
209
210 ---------
211
212 U-Boot 2010.06-rc2-00002-gf8fbb25-dirty (Jun 18 2010 - 17:07:19)
213
214 U-Boot code: A0000000 -> A005854C  BSS: -> A00618AC
215 CPU:   Freescale i.MX31 at 398 MHz
216 Board: DAVE/DENX Qong
217 mon: FFFFFFFF gd->monLen: 000618AC
218 Top of RAM usable for U-Boot at: 90000000
219 LCD panel info: 640 x 480, 16 bit/pix
220 Reserving 600k for LCD Framebuffer at: 8ff6a000
221 Reserving 390k for U-Boot at: 8ff08000
222 Reserving 1280k for malloc() at: 8fdc8000
223 Reserving 28 Bytes for Board Info at: 8fdc7fe4
224 Reserving 48 Bytes for Global Data at: 8fdc7fb4
225 New Stack Pointer is: 8fdc7fb0
226 RAM Configuration:
227 Bank #0: 80000000 256 MiB
228 mon: 0005854C gd->monLen: 000618AC
229 Now running in RAM - U-Boot at: 8ff08000
230
231 -------------------------------------------------------------------------------------
232
233 Debugging u-boot in RAM:
234 (example on the qong board)
235
236 a) add in config.mk:
237
238 PLATFORM_CPPFLAGS += -DDEBUG
239
240 -----------------
241
242 b) start debugger
243
244 arm-linux-gdb u-boot
245
246 [hs@pollux u-boot]$ arm-linux-gdb u-boot
247 GNU gdb Red Hat Linux (6.7-2rh)
248 Copyright (C) 2007 Free Software Foundation, Inc.
249 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
250 This is free software: you are free to change and redistribute it.
251 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
252 and "show warranty" for details.
253 This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
254 The target architecture is set automatically (currently arm)
255 ..
256 (gdb)
257
258 -----------------
259
260 c) connect to target
261
262 target remote bdi10:2001
263
264 (gdb) target remote bdi10:2001
265 Remote debugging using bdi10:2001
266 0x8ff17f10 in ?? ()
267 (gdb)
268
269 -----------------
270
271 d) discard symbol-file
272
273 (gdb) symbol-file
274 Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
275 No symbol file now.
276 (gdb)
277
278 -----------------
279
280 e) load new symbol table:
281
282 (gdb) add-symbol-file u-boot 0x8ff08000
283 add symbol table from file "u-boot" at
284         .text_addr = 0x8ff08000
285 (y or n) y
286 Reading symbols from /home/hs/celf/u-boot/u-boot...done.
287 (gdb) c
288 Continuing.
289 ^C
290 Program received signal SIGSTOP, Stopped (signal).
291 0x8ff17f18 in serial_getc () at serial_mxc.c:192
292 192             while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
293 (gdb)
294
295 add-symbol-file u-boot 0x8ff08000
296                        ^^^^^^^^^^
297                        get this address from u-boot debug printfs
298
299 U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
300
301 U-Boot code: A0000000 -> A0058BAC  BSS: -> A0061F10
302 CPU:   Freescale i.MX31 at 398 MHz
303 Board: DAVE/DENX Qong
304 mon: FFFFFFFF gd->monLen: 00061F10
305 Top of RAM usable for U-Boot at: 90000000
306 LCD panel info: 640 x 480, 16 bit/pix
307 Reserving 600k for LCD Framebuffer at: 8ff6a000
308 Reserving 391k for U-Boot at: 8ff08000
309                               ^^^^^^^^
310 Reserving 1280k for malloc() at: 8fdc8000
311 Reserving 24 Bytes for Board Info at: 8fdc7fe8
312 Reserving 52 Bytes for Global Data at: 8fdc7fb4
313 New Stack Pointer is: 8fdc7fb0
314 RAM Configuration:
315 Bank #0: 80000000 256 MiB
316 relocation Offset is: eff08000
317 mon: 00058BAC gd->monLen: 00061F10
318 Now running in RAM - U-Boot at: 8ff08000
319                                 ^^^^^^^^
320
321 Now you can use gdb as usual :-)