1 To make relocation on arm working, the following changes are done:
3 At arch level: add linker flag -pie
5 This causes the linker to generate fixup tables .rel.dyn and .dynsym,
6 which must be applied to the relocated image before transferring
9 These fixups are described in the ARM ELF documentation as type 23
10 (program-base-relative) and 2 (symbol-relative)
12 At cpu level: modify linker file and add a relocation and fixup loop
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
18 The relocation and fixup loop must be executed after executing
19 board_init_f at initial location and before executing board_init_r
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
28 TODO: move also dram initialization there on boards where it is possible.
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.
35 Board.c code is adapted from ppc code
39 Undefine CONFIG_SYS_ARM_WITHOUT_RELOC
41 * WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
43 Boards which are not fixed to support relocation will be REMOVED!
45 Eventually, CONFIG_SYS_ARM_WITHOUT_RELOC will disappear and boards
46 which have to migrated to relocation will disappear too.
48 -----------------------------------------------------------------------------
50 For boards which boot from nand_spl, it is possible to save one copy
51 if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
52 is copied again in relocate_code().
54 example for the tx25 board:
57 b) it copies the first page in nand to internal ram
59 c) end executes this code
60 d) this initialize CPU, RAM, ... and copy itself to RAM
61 (this bin must fit in one page, so board_init_f()
63 e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
64 starts this image @ CONFIG_SYS_NAND_U_BOOT_START
65 f) u-boot code steps through board_init_f() and calculates
66 the relocation address and copy itself to it
68 If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
71 -----------------------------------------------------------------------------
75 - fill in bd_t infos (check)
78 - maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
79 This *must* be done for boards, which boot from NOR flash
81 on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
82 one copying from u-boot code.
84 - new function dram_init_banksize() is actual board specific. Maybe
85 we make a weak default function in arch/arm/lib/board.c ?
87 -----------------------------------------------------------------------------
89 Relocation with NAND_SPL (example for the tx25):
91 - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
92 and start with code execution on this address.
94 - The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
95 which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
96 the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
97 @CONFIG_SYS_NAND_U_BOOT_START
99 - This u-boot does no RAM init, nor CPU register setup. Just look
100 where it has to copy and relocate itself to this address. If
101 relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the
102 CONFIG_SYS_TEXT_BASE from the nand_spl code), then there is no need
103 to copy, just go on with bss clear and jump to board_init_r.
105 -----------------------------------------------------------------------------
107 How ELF relocations 23 and 2 work.
111 -------------------------------------------------------------------------------------
113 Debugging u-boot in RAM:
114 (example on the qong board)
118 PLATFORM_CPPFLAGS += -DDEBUG
126 [hs@pollux u-boot]$ arm-linux-gdb u-boot
127 GNU gdb Red Hat Linux (6.7-2rh)
128 Copyright (C) 2007 Free Software Foundation, Inc.
129 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
130 This is free software: you are free to change and redistribute it.
131 There is NO WARRANTY, to the extent permitted by law. Type "show copying"
132 and "show warranty" for details.
133 This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
134 The target architecture is set automatically (currently arm)
142 target remote bdi10:2001
144 (gdb) target remote bdi10:2001
145 Remote debugging using bdi10:2001
151 d) discard symbol-file
154 Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
160 e) load new symbol table:
162 (gdb) add-symbol-file u-boot 0x8ff08000
163 add symbol table from file "u-boot" at
164 .text_addr = 0x8ff08000
166 Reading symbols from /home/hs/celf/u-boot/u-boot...done.
170 Program received signal SIGSTOP, Stopped (signal).
171 0x8ff17f18 in serial_getc () at serial_mxc.c:192
172 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
175 add-symbol-file u-boot 0x8ff08000
177 get this address from u-boot debug printfs
179 U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
181 U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10
182 CPU: Freescale i.MX31 at 398 MHz
183 Board: DAVE/DENX Qong
184 mon: FFFFFFFF gd->monLen: 00061F10
185 Top of RAM usable for U-Boot at: 90000000
186 LCD panel info: 640 x 480, 16 bit/pix
187 Reserving 600k for LCD Framebuffer at: 8ff6a000
188 Reserving 391k for U-Boot at: 8ff08000
190 Reserving 1280k for malloc() at: 8fdc8000
191 Reserving 24 Bytes for Board Info at: 8fdc7fe8
192 Reserving 52 Bytes for Global Data at: 8fdc7fb4
193 New Stack Pointer is: 8fdc7fb0
195 Bank #0: 80000000 256 MiB
196 relocation Offset is: eff08000
197 mon: 00058BAC gd->monLen: 00061F10
198 Now running in RAM - U-Boot at: 8ff08000
201 Now you can use gdb as usual :-)