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