Blame view
doc/README.arm-relocation
5.79 KB
f1d2b313c
|
1 |
To make relocation on arm working, the following changes are done: |
92d5ecba4
|
2 |
At arch level: add linker flag -pie |
f1d2b313c
|
3 |
|
92d5ecba4
|
4 5 6 |
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. |
f1d2b313c
|
7 |
|
92d5ecba4
|
8 9 |
These fixups are described in the ARM ELF documentation as type 23 (program-base-relative) and 2 (symbol-relative) |
f1d2b313c
|
10 |
|
92d5ecba4
|
11 |
At cpu level: modify linker file and add a relocation and fixup loop |
f1d2b313c
|
12 |
|
92d5ecba4
|
13 14 15 |
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 |
f1d2b313c
|
16 |
|
92d5ecba4
|
17 18 19 |
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. |
f1d2b313c
|
20 |
|
92d5ecba4
|
21 |
At board level: |
f1d2b313c
|
22 |
|
92d5ecba4
|
23 24 25 |
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(). |
f1d2b313c
|
26 |
|
92d5ecba4
|
27 |
TODO: move also dram initialization there on boards where it is possible. |
f1d2b313c
|
28 |
|
92d5ecba4
|
29 30 |
Setup of the the bd_t dram bank info is done in the new function dram_init_banksize() called after bd is accessible. |
f1d2b313c
|
31 |
|
92d5ecba4
|
32 |
At lib level: |
f1d2b313c
|
33 |
|
92d5ecba4
|
34 |
Board.c code is adapted from ppc code |
f1d2b313c
|
35 |
|
92d5ecba4
|
36 37 38 |
* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING * Boards which are not fixed to support relocation will be REMOVED! |
92d5ecba4
|
39 |
----------------------------------------------------------------------------- |
da962b717
|
40 |
For boards which boot from spl, it is possible to save one copy |
14d0a02a1
|
41 |
if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code |
ab86f72c3
|
42 |
is copied again in relocate_code(). |
da962b717
|
43 |
example for the tx25 board booting from NAND Flash: |
ab86f72c3
|
44 45 46 |
a) cpu starts b) it copies the first page in nand to internal ram |
da962b717
|
47 |
(spl code) |
ab86f72c3
|
48 49 50 51 52 53 54 55 |
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 |
14d0a02a1
|
56 |
If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot |
ab86f72c3
|
57 |
in f) could be saved. |
92d5ecba4
|
58 |
----------------------------------------------------------------------------- |
ab86f72c3
|
59 |
|
92d5ecba4
|
60 |
TODO |
f1d2b313c
|
61 62 63 |
- fill in bd_t infos (check) - adapt all boards |
14d0a02a1
|
64 |
- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers) |
f1d2b313c
|
65 |
This *must* be done for boards, which boot from NOR flash |
14d0a02a1
|
66 |
on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves |
f1d2b313c
|
67 68 69 70 |
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 ? |
92d5ecba4
|
71 |
----------------------------------------------------------------------------- |
f1d2b313c
|
72 |
|
da962b717
|
73 |
Relocation with SPL (example for the tx25 booting from NAND Flash): |
f1d2b313c
|
74 75 76 |
- cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE) and start with code execution on this address. |
a430fa06a
|
77 |
- The First page contains u-boot code from drivers/mtd/nand/raw/mxc_nand_spl.c |
da962b717
|
78 |
which inits the dram, cpu registers, reloacte itself to CONFIG_SPL_TEXT_BASE and loads |
f1d2b313c
|
79 80 |
the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution @CONFIG_SYS_NAND_U_BOOT_START |
c8d76eaf6
|
81 82 83 |
- 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 |
da962b717
|
84 |
CONFIG_SPL_TEXT_BASE from the spl code), then there is no need |
c8d76eaf6
|
85 |
to copy, just go on with bss clear and jump to board_init_r. |
f1d2b313c
|
86 |
|
92d5ecba4
|
87 |
----------------------------------------------------------------------------- |
f1d2b313c
|
88 |
|
92d5ecba4
|
89 |
How ELF relocations 23 and 2 work. |
f1d2b313c
|
90 |
|
92d5ecba4
|
91 |
TBC |
f1d2b313c
|
92 93 94 95 96 |
------------------------------------------------------------------------------------- Debugging u-boot in RAM: (example on the qong board) |
f1d2b313c
|
97 |
----------------- |
f4379ceff
|
98 |
a) start debugger |
f1d2b313c
|
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
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) ----------------- |
f4379ceff
|
115 |
b) connect to target |
f1d2b313c
|
116 117 118 119 120 121 122 123 124 |
target remote bdi10:2001 (gdb) target remote bdi10:2001 Remote debugging using bdi10:2001 0x8ff17f10 in ?? () (gdb) ----------------- |
f4379ceff
|
125 |
c) discard symbol-file |
f1d2b313c
|
126 127 128 129 130 131 132 |
(gdb) symbol-file Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y No symbol file now. (gdb) ----------------- |
f4379ceff
|
133 |
d) load new symbol table: |
f1d2b313c
|
134 135 136 |
(gdb) add-symbol-file u-boot 0x8ff08000 add symbol table from file "u-boot" at |
071bc9233
|
137 |
.text_addr = 0x8ff08000 |
f1d2b313c
|
138 139 140 141 142 143 144 |
(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 |
071bc9233
|
145 |
192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY); |
f1d2b313c
|
146 147 148 |
(gdb) add-symbol-file u-boot 0x8ff08000 |
071bc9233
|
149 |
^^^^^^^^^^ |
f4379ceff
|
150 |
get this address from u-boot bdinfo command |
7124015ad
|
151 |
or get it from gd->relocaddr in gdb |
f4379ceff
|
152 153 154 155 156 157 158 159 160 161 162 163 |
=> 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 |
cd6881b51
|
164 |
^^^^^^^^^^ |
f4379ceff
|
165 |
reloc off = XXXXXXXXXX |
cd6881b51
|
166 |
irq_sp = XXXXXXXXXX |
f4379ceff
|
167 168 |
sp start = XXXXXXXXXX FB base = XXXXXXXXXX |
f1d2b313c
|
169 |
|
7124015ad
|
170 171 172 173 174 175 |
or interrupt execution by any means and re-load the symbols at the location specified by gd->relocaddr -- this is only valid after board_init_f. (gdb) set $s = gd->relocaddr (gdb) symbol-file (gdb) add-symbol-file u-boot $s |
f1d2b313c
|
176 |
Now you can use gdb as usual :-) |