]> git.ipfire.org Git - people/ms/u-boot.git/blame - doc/README.arm-relocation
Drop support for CONFIG_SYS_ARM_WITHOUT_RELOC
[people/ms/u-boot.git] / doc / README.arm-relocation
CommitLineData
f1d2b313
HS
1To make relocation on arm working, the following changes are done:
2
92d5ecba 3At arch level: add linker flag -pie
f1d2b313 4
92d5ecba
AA
5 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.
f1d2b313 8
92d5ecba
AA
9 These fixups are described in the ARM ELF documentation as type 23
10 (program-base-relative) and 2 (symbol-relative)
f1d2b313 11
92d5ecba 12At cpu level: modify linker file and add a relocation and fixup loop
f1d2b313 13
92d5ecba
AA
14 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
f1d2b313 17
92d5ecba
AA
18 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.
f1d2b313 21
92d5ecba 22At board level:
f1d2b313 23
92d5ecba
AA
24 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().
f1d2b313 27
92d5ecba 28TODO: move also dram initialization there on boards where it is possible.
f1d2b313 29
92d5ecba
AA
30 Setup of the the bd_t dram bank info is done in the new function
31 dram_init_banksize() called after bd is accessible.
f1d2b313 32
92d5ecba 33At lib level:
f1d2b313 34
92d5ecba 35 Board.c code is adapted from ppc code
f1d2b313 36
92d5ecba
AA
37* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
38
39Boards which are not fixed to support relocation will be REMOVED!
40
92d5ecba
AA
41-----------------------------------------------------------------------------
42
43For boards which boot from nand_spl, it is possible to save one copy
14d0a02a 44if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
ab86f72c
HS
45is 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
14d0a02a 61If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
ab86f72c
HS
62in f) could be saved.
63
92d5ecba 64-----------------------------------------------------------------------------
ab86f72c 65
92d5ecba 66TODO
f1d2b313
HS
67
68- fill in bd_t infos (check)
69- adapt all boards
70
14d0a02a 71- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
f1d2b313
HS
72 This *must* be done for boards, which boot from NOR flash
73
14d0a02a 74 on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
f1d2b313
HS
75 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
92d5ecba 80-----------------------------------------------------------------------------
f1d2b313
HS
81
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
071bc923 88 which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
f1d2b313
HS
89 the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
90 @CONFIG_SYS_NAND_U_BOOT_START
91
c8d76eaf
WD
92- 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.
f1d2b313 97
92d5ecba 98-----------------------------------------------------------------------------
f1d2b313 99
92d5ecba 100How ELF relocations 23 and 2 work.
f1d2b313 101
92d5ecba 102TBC
f1d2b313
HS
103
104-------------------------------------------------------------------------------------
105
106Debugging u-boot in RAM:
107(example on the qong board)
108
109a) add in config.mk:
110
111PLATFORM_CPPFLAGS += -DDEBUG
112
113-----------------
114
115b) start debugger
116
117arm-linux-gdb u-boot
118
119[hs@pollux u-boot]$ arm-linux-gdb u-boot
120GNU gdb Red Hat Linux (6.7-2rh)
121Copyright (C) 2007 Free Software Foundation, Inc.
122License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
123This is free software: you are free to change and redistribute it.
124There is NO WARRANTY, to the extent permitted by law. Type "show copying"
125and "show warranty" for details.
126This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
127The target architecture is set automatically (currently arm)
128..
129(gdb)
130
131-----------------
132
133c) connect to target
134
135target remote bdi10:2001
136
137(gdb) target remote bdi10:2001
138Remote debugging using bdi10:2001
1390x8ff17f10 in ?? ()
140(gdb)
141
142-----------------
143
144d) discard symbol-file
145
146(gdb) symbol-file
147Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
148No symbol file now.
149(gdb)
150
151-----------------
152
153e) load new symbol table:
154
155(gdb) add-symbol-file u-boot 0x8ff08000
156add symbol table from file "u-boot" at
071bc923 157 .text_addr = 0x8ff08000
f1d2b313
HS
158(y or n) y
159Reading symbols from /home/hs/celf/u-boot/u-boot...done.
160(gdb) c
161Continuing.
162^C
163Program received signal SIGSTOP, Stopped (signal).
1640x8ff17f18 in serial_getc () at serial_mxc.c:192
071bc923 165192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
f1d2b313
HS
166(gdb)
167
168add-symbol-file u-boot 0x8ff08000
071bc923
WD
169 ^^^^^^^^^^
170 get this address from u-boot debug printfs
f1d2b313
HS
171
172U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
173
174U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10
175CPU: Freescale i.MX31 at 398 MHz
176Board: DAVE/DENX Qong
177mon: FFFFFFFF gd->monLen: 00061F10
178Top of RAM usable for U-Boot at: 90000000
179LCD panel info: 640 x 480, 16 bit/pix
180Reserving 600k for LCD Framebuffer at: 8ff6a000
181Reserving 391k for U-Boot at: 8ff08000
071bc923 182 ^^^^^^^^
f1d2b313
HS
183Reserving 1280k for malloc() at: 8fdc8000
184Reserving 24 Bytes for Board Info at: 8fdc7fe8
185Reserving 52 Bytes for Global Data at: 8fdc7fb4
186New Stack Pointer is: 8fdc7fb0
187RAM Configuration:
188Bank #0: 80000000 256 MiB
189relocation Offset is: eff08000
190mon: 00058BAC gd->monLen: 00061F10
191Now running in RAM - U-Boot at: 8ff08000
071bc923 192 ^^^^^^^^
f1d2b313
HS
193
194Now you can use gdb as usual :-)