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