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 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 3 | At arch level: add linker flag -pie |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 4 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 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. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 8 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 9 | These fixups are described in the ARM ELF documentation as type 23 |
| 10 | (program-base-relative) and 2 (symbol-relative) |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 11 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 12 | At cpu level: modify linker file and add a relocation and fixup loop |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 13 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 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 |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 17 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 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. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 21 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 22 | At board level: |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 23 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 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(). |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 27 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 28 | TODO: move also dram initialization there on boards where it is possible. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 29 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 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. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 32 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 33 | At lib level: |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 34 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 35 | Board.c code is adapted from ppc code |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 36 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 37 | * WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING * |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 38 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 39 | Boards which are not fixed to support relocation will be REMOVED! |
| 40 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 41 | ----------------------------------------------------------------------------- |
| 42 | |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 43 | For boards which boot from spl, it is possible to save one copy |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 44 | if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 45 | is copied again in relocate_code(). |
| 46 | |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 47 | example for the tx25 board booting from NAND Flash: |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 48 | |
| 49 | a) cpu starts |
| 50 | b) it copies the first page in nand to internal ram |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 51 | (spl code) |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 52 | c) end executes this code |
| 53 | d) 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 ... ) |
| 56 | e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and |
| 57 | starts this image @ CONFIG_SYS_NAND_U_BOOT_START |
| 58 | f) u-boot code steps through board_init_f() and calculates |
| 59 | the relocation address and copy itself to it |
| 60 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 61 | If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 62 | in f) could be saved. |
| 63 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 64 | ----------------------------------------------------------------------------- |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 65 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 66 | TODO |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 67 | |
| 68 | - fill in bd_t infos (check) |
| 69 | - adapt all boards |
| 70 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 71 | - 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] | 72 | This *must* be done for boards, which boot from NOR flash |
| 73 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 74 | on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 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 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 80 | ----------------------------------------------------------------------------- |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 81 | |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 82 | Relocation with SPL (example for the tx25 booting from NAND Flash): |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 83 | |
| 84 | - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE) |
| 85 | and start with code execution on this address. |
| 86 | |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 87 | - The First page contains u-boot code from drivers/mtd/nand/mxc_nand_spl.c |
| 88 | which inits the dram, cpu registers, reloacte itself to CONFIG_SPL_TEXT_BASE and loads |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 89 | the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution |
| 90 | @CONFIG_SYS_NAND_U_BOOT_START |
| 91 | |
Wolfgang Denk | c8d76ea | 2010-10-18 23:43:37 +0200 | [diff] [blame] | 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 |
Benoît Thébaudeau | da962b7 | 2013-04-11 09:35:51 +0000 | [diff] [blame^] | 95 | CONFIG_SPL_TEXT_BASE from the spl code), then there is no need |
Wolfgang Denk | c8d76ea | 2010-10-18 23:43:37 +0200 | [diff] [blame] | 96 | 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] | 97 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 98 | ----------------------------------------------------------------------------- |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 99 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 100 | How ELF relocations 23 and 2 work. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 101 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 102 | TBC |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 103 | |
| 104 | ------------------------------------------------------------------------------------- |
| 105 | |
| 106 | Debugging u-boot in RAM: |
| 107 | (example on the qong board) |
| 108 | |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 109 | ----------------- |
| 110 | |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 111 | a) start debugger |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 112 | |
| 113 | arm-linux-gdb u-boot |
| 114 | |
| 115 | [hs@pollux u-boot]$ arm-linux-gdb u-boot |
| 116 | GNU gdb Red Hat Linux (6.7-2rh) |
| 117 | Copyright (C) 2007 Free Software Foundation, Inc. |
| 118 | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
| 119 | This is free software: you are free to change and redistribute it. |
| 120 | There is NO WARRANTY, to the extent permitted by law. Type "show copying" |
| 121 | and "show warranty" for details. |
| 122 | This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux". |
| 123 | The target architecture is set automatically (currently arm) |
| 124 | .. |
| 125 | (gdb) |
| 126 | |
| 127 | ----------------- |
| 128 | |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 129 | b) connect to target |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 130 | |
| 131 | target remote bdi10:2001 |
| 132 | |
| 133 | (gdb) target remote bdi10:2001 |
| 134 | Remote debugging using bdi10:2001 |
| 135 | 0x8ff17f10 in ?? () |
| 136 | (gdb) |
| 137 | |
| 138 | ----------------- |
| 139 | |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 140 | c) discard symbol-file |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 141 | |
| 142 | (gdb) symbol-file |
| 143 | Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y |
| 144 | No symbol file now. |
| 145 | (gdb) |
| 146 | |
| 147 | ----------------- |
| 148 | |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 149 | d) load new symbol table: |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 150 | |
| 151 | (gdb) add-symbol-file u-boot 0x8ff08000 |
| 152 | add symbol table from file "u-boot" at |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 153 | .text_addr = 0x8ff08000 |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 154 | (y or n) y |
| 155 | Reading symbols from /home/hs/celf/u-boot/u-boot...done. |
| 156 | (gdb) c |
| 157 | Continuing. |
| 158 | ^C |
| 159 | Program received signal SIGSTOP, Stopped (signal). |
| 160 | 0x8ff17f18 in serial_getc () at serial_mxc.c:192 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 161 | 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY); |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 162 | (gdb) |
| 163 | |
| 164 | add-symbol-file u-boot 0x8ff08000 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 165 | ^^^^^^^^^^ |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 166 | get this address from u-boot bdinfo command |
Ben Gardiner | 7124015 | 2011-04-28 11:03:21 +0000 | [diff] [blame] | 167 | or get it from gd->relocaddr in gdb |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 168 | |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 169 | => bdinfo |
| 170 | rch_number = XXXXXXXXXX |
| 171 | boot_params = XXXXXXXXXX |
| 172 | DRAM bank = XXXXXXXXXX |
| 173 | -> start = XXXXXXXXXX |
| 174 | -> size = XXXXXXXXXX |
| 175 | ethaddr = XXXXXXXXXX |
| 176 | ip_addr = XXXXXXXXXX |
| 177 | baudrate = XXXXXXXXXX |
| 178 | TLB addr = XXXXXXXXXX |
| 179 | relocaddr = 0x8ff08000 |
Wolfgang Denk | cd6881b | 2011-05-19 22:21:41 +0200 | [diff] [blame] | 180 | ^^^^^^^^^^ |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 181 | reloc off = XXXXXXXXXX |
Wolfgang Denk | cd6881b | 2011-05-19 22:21:41 +0200 | [diff] [blame] | 182 | irq_sp = XXXXXXXXXX |
Ben Gardiner | f4379ce | 2011-04-28 06:49:47 +0000 | [diff] [blame] | 183 | sp start = XXXXXXXXXX |
| 184 | FB base = XXXXXXXXXX |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 185 | |
Ben Gardiner | 7124015 | 2011-04-28 11:03:21 +0000 | [diff] [blame] | 186 | or interrupt execution by any means and re-load the symbols at the location |
| 187 | specified by gd->relocaddr -- this is only valid after board_init_f. |
| 188 | |
| 189 | (gdb) set $s = gd->relocaddr |
| 190 | (gdb) symbol-file |
| 191 | (gdb) add-symbol-file u-boot $s |
| 192 | |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 193 | Now you can use gdb as usual :-) |