1f1d2b313SHeiko SchocherTo make relocation on arm working, the following changes are done: 2f1d2b313SHeiko Schocher 392d5ecbaSAlbert AribaudAt arch level: add linker flag -pie 4f1d2b313SHeiko Schocher 592d5ecbaSAlbert Aribaud This causes the linker to generate fixup tables .rel.dyn and .dynsym, 692d5ecbaSAlbert Aribaud which must be applied to the relocated image before transferring 792d5ecbaSAlbert Aribaud control to it. 8f1d2b313SHeiko Schocher 992d5ecbaSAlbert Aribaud These fixups are described in the ARM ELF documentation as type 23 1092d5ecbaSAlbert Aribaud (program-base-relative) and 2 (symbol-relative) 11f1d2b313SHeiko Schocher 1292d5ecbaSAlbert AribaudAt cpu level: modify linker file and add a relocation and fixup loop 13f1d2b313SHeiko Schocher 1492d5ecbaSAlbert Aribaud the linker file must be modified to include the .rel.dyn and .dynsym 1592d5ecbaSAlbert Aribaud tables in the binary image, and to provide symbols for the relocation 1692d5ecbaSAlbert Aribaud code to access these tables 17f1d2b313SHeiko Schocher 1892d5ecbaSAlbert Aribaud The relocation and fixup loop must be executed after executing 1992d5ecbaSAlbert Aribaud board_init_f at initial location and before executing board_init_r 2092d5ecbaSAlbert Aribaud at final location. 21f1d2b313SHeiko Schocher 2292d5ecbaSAlbert AribaudAt board level: 23f1d2b313SHeiko Schocher 2492d5ecbaSAlbert Aribaud dram_init(): bd pointer is now at this point not accessible, so only 2592d5ecbaSAlbert Aribaud detect the real dramsize, and store it in gd->ram_size. Bst detected 2692d5ecbaSAlbert Aribaud with get_ram_size(). 27f1d2b313SHeiko Schocher 2892d5ecbaSAlbert AribaudTODO: move also dram initialization there on boards where it is possible. 29f1d2b313SHeiko Schocher 3092d5ecbaSAlbert Aribaud Setup of the the bd_t dram bank info is done in the new function 3192d5ecbaSAlbert Aribaud dram_init_banksize() called after bd is accessible. 32f1d2b313SHeiko Schocher 3392d5ecbaSAlbert AribaudAt lib level: 34f1d2b313SHeiko Schocher 3592d5ecbaSAlbert Aribaud Board.c code is adapted from ppc code 36f1d2b313SHeiko Schocher 3792d5ecbaSAlbert Aribaud* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING * 38f1d2b313SHeiko Schocher 3992d5ecbaSAlbert AribaudBoards which are not fixed to support relocation will be REMOVED! 4092d5ecbaSAlbert Aribaud 4192d5ecbaSAlbert Aribaud----------------------------------------------------------------------------- 4292d5ecbaSAlbert Aribaud 43da962b71SBenoît ThébaudeauFor boards which boot from spl, it is possible to save one copy 4414d0a02aSWolfgang Denkif CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code 45ab86f72cSHeiko Schocheris copied again in relocate_code(). 46ab86f72cSHeiko Schocher 47da962b71SBenoît Thébaudeauexample for the tx25 board booting from NAND Flash: 48ab86f72cSHeiko Schocher 49ab86f72cSHeiko Schochera) cpu starts 50ab86f72cSHeiko Schocherb) it copies the first page in nand to internal ram 51da962b71SBenoît Thébaudeau (spl code) 52ab86f72cSHeiko Schocherc) end executes this code 53ab86f72cSHeiko Schocherd) this initialize CPU, RAM, ... and copy itself to RAM 54ab86f72cSHeiko Schocher (this bin must fit in one page, so board_init_f() 55ab86f72cSHeiko Schocher don;t fit in it ... ) 56ab86f72cSHeiko Schochere) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and 57ab86f72cSHeiko Schocher starts this image @ CONFIG_SYS_NAND_U_BOOT_START 58ab86f72cSHeiko Schocherf) u-boot code steps through board_init_f() and calculates 59ab86f72cSHeiko Schocher the relocation address and copy itself to it 60ab86f72cSHeiko Schocher 6114d0a02aSWolfgang DenkIf CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot 62ab86f72cSHeiko Schocherin f) could be saved. 63ab86f72cSHeiko Schocher 6492d5ecbaSAlbert Aribaud----------------------------------------------------------------------------- 65ab86f72cSHeiko Schocher 6692d5ecbaSAlbert AribaudTODO 67f1d2b313SHeiko Schocher 68f1d2b313SHeiko Schocher- fill in bd_t infos (check) 69f1d2b313SHeiko Schocher- adapt all boards 70f1d2b313SHeiko Schocher 7114d0a02aSWolfgang Denk- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers) 72f1d2b313SHeiko Schocher This *must* be done for boards, which boot from NOR flash 73f1d2b313SHeiko Schocher 7414d0a02aSWolfgang Denk on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves 75f1d2b313SHeiko Schocher one copying from u-boot code. 76f1d2b313SHeiko Schocher 77f1d2b313SHeiko Schocher- new function dram_init_banksize() is actual board specific. Maybe 78f1d2b313SHeiko Schocher we make a weak default function in arch/arm/lib/board.c ? 79f1d2b313SHeiko Schocher 8092d5ecbaSAlbert Aribaud----------------------------------------------------------------------------- 81f1d2b313SHeiko Schocher 82da962b71SBenoît ThébaudeauRelocation with SPL (example for the tx25 booting from NAND Flash): 83f1d2b313SHeiko Schocher 84f1d2b313SHeiko Schocher- cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE) 85f1d2b313SHeiko Schocher and start with code execution on this address. 86f1d2b313SHeiko Schocher 87*a430fa06SMiquel Raynal- The First page contains u-boot code from drivers/mtd/nand/raw/mxc_nand_spl.c 88da962b71SBenoît Thébaudeau which inits the dram, cpu registers, reloacte itself to CONFIG_SPL_TEXT_BASE and loads 89f1d2b313SHeiko Schocher the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution 90f1d2b313SHeiko Schocher @CONFIG_SYS_NAND_U_BOOT_START 91f1d2b313SHeiko Schocher 92c8d76eafSWolfgang Denk- This u-boot does no RAM init, nor CPU register setup. Just look 93c8d76eafSWolfgang Denk where it has to copy and relocate itself to this address. If 94c8d76eafSWolfgang Denk relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the 95da962b71SBenoît Thébaudeau CONFIG_SPL_TEXT_BASE from the spl code), then there is no need 96c8d76eafSWolfgang Denk to copy, just go on with bss clear and jump to board_init_r. 97f1d2b313SHeiko Schocher 9892d5ecbaSAlbert Aribaud----------------------------------------------------------------------------- 99f1d2b313SHeiko Schocher 10092d5ecbaSAlbert AribaudHow ELF relocations 23 and 2 work. 101f1d2b313SHeiko Schocher 10292d5ecbaSAlbert AribaudTBC 103f1d2b313SHeiko Schocher 104f1d2b313SHeiko Schocher------------------------------------------------------------------------------------- 105f1d2b313SHeiko Schocher 106f1d2b313SHeiko SchocherDebugging u-boot in RAM: 107f1d2b313SHeiko Schocher(example on the qong board) 108f1d2b313SHeiko Schocher 109f1d2b313SHeiko Schocher----------------- 110f1d2b313SHeiko Schocher 111f4379cefSBen Gardinera) start debugger 112f1d2b313SHeiko Schocher 113f1d2b313SHeiko Schocherarm-linux-gdb u-boot 114f1d2b313SHeiko Schocher 115f1d2b313SHeiko Schocher[hs@pollux u-boot]$ arm-linux-gdb u-boot 116f1d2b313SHeiko SchocherGNU gdb Red Hat Linux (6.7-2rh) 117f1d2b313SHeiko SchocherCopyright (C) 2007 Free Software Foundation, Inc. 118f1d2b313SHeiko SchocherLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 119f1d2b313SHeiko SchocherThis is free software: you are free to change and redistribute it. 120f1d2b313SHeiko SchocherThere is NO WARRANTY, to the extent permitted by law. Type "show copying" 121f1d2b313SHeiko Schocherand "show warranty" for details. 122f1d2b313SHeiko SchocherThis GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux". 123f1d2b313SHeiko SchocherThe target architecture is set automatically (currently arm) 124f1d2b313SHeiko Schocher.. 125f1d2b313SHeiko Schocher(gdb) 126f1d2b313SHeiko Schocher 127f1d2b313SHeiko Schocher----------------- 128f1d2b313SHeiko Schocher 129f4379cefSBen Gardinerb) connect to target 130f1d2b313SHeiko Schocher 131f1d2b313SHeiko Schochertarget remote bdi10:2001 132f1d2b313SHeiko Schocher 133f1d2b313SHeiko Schocher(gdb) target remote bdi10:2001 134f1d2b313SHeiko SchocherRemote debugging using bdi10:2001 135f1d2b313SHeiko Schocher0x8ff17f10 in ?? () 136f1d2b313SHeiko Schocher(gdb) 137f1d2b313SHeiko Schocher 138f1d2b313SHeiko Schocher----------------- 139f1d2b313SHeiko Schocher 140f4379cefSBen Gardinerc) discard symbol-file 141f1d2b313SHeiko Schocher 142f1d2b313SHeiko Schocher(gdb) symbol-file 143f1d2b313SHeiko SchocherDiscard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y 144f1d2b313SHeiko SchocherNo symbol file now. 145f1d2b313SHeiko Schocher(gdb) 146f1d2b313SHeiko Schocher 147f1d2b313SHeiko Schocher----------------- 148f1d2b313SHeiko Schocher 149f4379cefSBen Gardinerd) load new symbol table: 150f1d2b313SHeiko Schocher 151f1d2b313SHeiko Schocher(gdb) add-symbol-file u-boot 0x8ff08000 152f1d2b313SHeiko Schocheradd symbol table from file "u-boot" at 153f1d2b313SHeiko Schocher .text_addr = 0x8ff08000 154f1d2b313SHeiko Schocher(y or n) y 155f1d2b313SHeiko SchocherReading symbols from /home/hs/celf/u-boot/u-boot...done. 156f1d2b313SHeiko Schocher(gdb) c 157f1d2b313SHeiko SchocherContinuing. 158f1d2b313SHeiko Schocher^C 159f1d2b313SHeiko SchocherProgram received signal SIGSTOP, Stopped (signal). 160f1d2b313SHeiko Schocher0x8ff17f18 in serial_getc () at serial_mxc.c:192 161f1d2b313SHeiko Schocher192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY); 162f1d2b313SHeiko Schocher(gdb) 163f1d2b313SHeiko Schocher 164f1d2b313SHeiko Schocheradd-symbol-file u-boot 0x8ff08000 165f1d2b313SHeiko Schocher ^^^^^^^^^^ 166f4379cefSBen Gardiner get this address from u-boot bdinfo command 1677124015aSBen Gardiner or get it from gd->relocaddr in gdb 168f1d2b313SHeiko Schocher 169f4379cefSBen Gardiner => bdinfo 170f4379cefSBen Gardinerrch_number = XXXXXXXXXX 171f4379cefSBen Gardinerboot_params = XXXXXXXXXX 172f4379cefSBen GardinerDRAM bank = XXXXXXXXXX 173f4379cefSBen Gardiner-> start = XXXXXXXXXX 174f4379cefSBen Gardiner-> size = XXXXXXXXXX 175f4379cefSBen Gardinerethaddr = XXXXXXXXXX 176f4379cefSBen Gardinerip_addr = XXXXXXXXXX 177f4379cefSBen Gardinerbaudrate = XXXXXXXXXX 178f4379cefSBen GardinerTLB addr = XXXXXXXXXX 179f4379cefSBen Gardinerrelocaddr = 0x8ff08000 180f4379cefSBen Gardiner ^^^^^^^^^^ 181f4379cefSBen Gardinerreloc off = XXXXXXXXXX 182f4379cefSBen Gardinerirq_sp = XXXXXXXXXX 183f4379cefSBen Gardinersp start = XXXXXXXXXX 184f4379cefSBen GardinerFB base = XXXXXXXXXX 185f1d2b313SHeiko Schocher 1867124015aSBen Gardineror interrupt execution by any means and re-load the symbols at the location 1877124015aSBen Gardinerspecified by gd->relocaddr -- this is only valid after board_init_f. 1887124015aSBen Gardiner 1897124015aSBen Gardiner(gdb) set $s = gd->relocaddr 1907124015aSBen Gardiner(gdb) symbol-file 1917124015aSBen Gardiner(gdb) add-symbol-file u-boot $s 1927124015aSBen Gardiner 193f1d2b313SHeiko SchocherNow you can use gdb as usual :-) 194