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 | At config level: |
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 | Define CONFIG_RELOC_FIXUP_WORKS. |
| 40 | Undefine CONFIG_SYS_ARM_WITHOUT_RELOC |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 41 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 42 | * WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING * |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 43 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 44 | Boards which are not fixed to support relocation will be REMOVED! |
| 45 | |
| 46 | Eventually, CONFIG_SYS_ARM_WITHOUT_RELOC and CONFIG_RELOC_FIXUP_WORKS will |
| 47 | disappear and boards which have to migrated to relocation will disappear too. |
| 48 | |
| 49 | ----------------------------------------------------------------------------- |
| 50 | |
| 51 | For boards which boot from nand_spl, it is possible to save one copy |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 52 | if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 53 | is copied again in relocate_code(). |
| 54 | |
| 55 | example for the tx25 board: |
| 56 | |
| 57 | a) cpu starts |
| 58 | b) it copies the first page in nand to internal ram |
| 59 | (nand_spl_code) |
| 60 | c) end executes this code |
| 61 | d) this initialize CPU, RAM, ... and copy itself to RAM |
| 62 | (this bin must fit in one page, so board_init_f() |
| 63 | don;t fit in it ... ) |
| 64 | e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and |
| 65 | starts this image @ CONFIG_SYS_NAND_U_BOOT_START |
| 66 | f) u-boot code steps through board_init_f() and calculates |
| 67 | the relocation address and copy itself to it |
| 68 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 69 | If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 70 | in f) could be saved. |
| 71 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 72 | ----------------------------------------------------------------------------- |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 73 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 74 | TODO |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 75 | |
| 76 | - fill in bd_t infos (check) |
| 77 | - adapt all boards |
| 78 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 79 | - 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] | 80 | This *must* be done for boards, which boot from NOR flash |
| 81 | |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 82 | on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 83 | one copying from u-boot code. |
| 84 | |
| 85 | - new function dram_init_banksize() is actual board specific. Maybe |
| 86 | we make a weak default function in arch/arm/lib/board.c ? |
| 87 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 88 | ----------------------------------------------------------------------------- |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 89 | |
| 90 | Relocation with NAND_SPL (example for the tx25): |
| 91 | |
| 92 | - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE) |
| 93 | and start with code execution on this address. |
| 94 | |
| 95 | - The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 96 | 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] | 97 | the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution |
| 98 | @CONFIG_SYS_NAND_U_BOOT_START |
| 99 | |
Wolfgang Denk | c8d76ea | 2010-10-18 23:43:37 +0200 | [diff] [blame] | 100 | - This u-boot does no RAM init, nor CPU register setup. Just look |
| 101 | where it has to copy and relocate itself to this address. If |
| 102 | relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the |
| 103 | CONFIG_SYS_TEXT_BASE from the nand_spl code), then there is no need |
| 104 | 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] | 105 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 106 | ----------------------------------------------------------------------------- |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 107 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 108 | How ELF relocations 23 and 2 work. |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 109 | |
Albert Aribaud | 92d5ecb | 2010-10-11 13:13:28 +0200 | [diff] [blame] | 110 | TBC |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 111 | |
| 112 | ------------------------------------------------------------------------------------- |
| 113 | |
| 114 | Debugging u-boot in RAM: |
| 115 | (example on the qong board) |
| 116 | |
| 117 | a) add in config.mk: |
| 118 | |
| 119 | PLATFORM_CPPFLAGS += -DDEBUG |
| 120 | |
| 121 | ----------------- |
| 122 | |
| 123 | b) start debugger |
| 124 | |
| 125 | arm-linux-gdb u-boot |
| 126 | |
| 127 | [hs@pollux u-boot]$ arm-linux-gdb u-boot |
| 128 | GNU gdb Red Hat Linux (6.7-2rh) |
| 129 | Copyright (C) 2007 Free Software Foundation, Inc. |
| 130 | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
| 131 | This is free software: you are free to change and redistribute it. |
| 132 | There is NO WARRANTY, to the extent permitted by law. Type "show copying" |
| 133 | and "show warranty" for details. |
| 134 | This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux". |
| 135 | The target architecture is set automatically (currently arm) |
| 136 | .. |
| 137 | (gdb) |
| 138 | |
| 139 | ----------------- |
| 140 | |
| 141 | c) connect to target |
| 142 | |
| 143 | target remote bdi10:2001 |
| 144 | |
| 145 | (gdb) target remote bdi10:2001 |
| 146 | Remote debugging using bdi10:2001 |
| 147 | 0x8ff17f10 in ?? () |
| 148 | (gdb) |
| 149 | |
| 150 | ----------------- |
| 151 | |
| 152 | d) discard symbol-file |
| 153 | |
| 154 | (gdb) symbol-file |
| 155 | Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y |
| 156 | No symbol file now. |
| 157 | (gdb) |
| 158 | |
| 159 | ----------------- |
| 160 | |
| 161 | e) load new symbol table: |
| 162 | |
| 163 | (gdb) add-symbol-file u-boot 0x8ff08000 |
| 164 | add symbol table from file "u-boot" at |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 165 | .text_addr = 0x8ff08000 |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 166 | (y or n) y |
| 167 | Reading symbols from /home/hs/celf/u-boot/u-boot...done. |
| 168 | (gdb) c |
| 169 | Continuing. |
| 170 | ^C |
| 171 | Program received signal SIGSTOP, Stopped (signal). |
| 172 | 0x8ff17f18 in serial_getc () at serial_mxc.c:192 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 173 | 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY); |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 174 | (gdb) |
| 175 | |
| 176 | add-symbol-file u-boot 0x8ff08000 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 177 | ^^^^^^^^^^ |
| 178 | get this address from u-boot debug printfs |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 179 | |
| 180 | U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46) |
| 181 | |
| 182 | U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10 |
| 183 | CPU: Freescale i.MX31 at 398 MHz |
| 184 | Board: DAVE/DENX Qong |
| 185 | mon: FFFFFFFF gd->monLen: 00061F10 |
| 186 | Top of RAM usable for U-Boot at: 90000000 |
| 187 | LCD panel info: 640 x 480, 16 bit/pix |
| 188 | Reserving 600k for LCD Framebuffer at: 8ff6a000 |
| 189 | Reserving 391k for U-Boot at: 8ff08000 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 190 | ^^^^^^^^ |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 191 | Reserving 1280k for malloc() at: 8fdc8000 |
| 192 | Reserving 24 Bytes for Board Info at: 8fdc7fe8 |
| 193 | Reserving 52 Bytes for Global Data at: 8fdc7fb4 |
| 194 | New Stack Pointer is: 8fdc7fb0 |
| 195 | RAM Configuration: |
| 196 | Bank #0: 80000000 256 MiB |
| 197 | relocation Offset is: eff08000 |
| 198 | mon: 00058BAC gd->monLen: 00061F10 |
| 199 | Now running in RAM - U-Boot at: 8ff08000 |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame^] | 200 | ^^^^^^^^ |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 201 | |
| 202 | Now you can use gdb as usual :-) |