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