blob: 2f91d0ac43f73b30829eef46e4f45cb407087a2a [file] [log] [blame]
Heiko Schocheraeb29912010-09-17 13:10:39 +02001To make relocation on arm working, the following changes are done:
2
Albert Aribaud6d1fcb12010-10-11 13:13:28 +02003At arch level: add linker flag -pie
Heiko Schocheraeb29912010-09-17 13:10:39 +02004
Albert Aribaud6d1fcb12010-10-11 13:13:28 +02005 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 Schocheraeb29912010-09-17 13:10:39 +02008
Albert Aribaud6d1fcb12010-10-11 13:13:28 +02009 These fixups are described in the ARM ELF documentation as type 23
10 (program-base-relative) and 2 (symbol-relative)
Heiko Schocheraeb29912010-09-17 13:10:39 +020011
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020012At cpu level: modify linker file and add a relocation and fixup loop
Heiko Schocheraeb29912010-09-17 13:10:39 +020013
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020014 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 Schocheraeb29912010-09-17 13:10:39 +020017
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020018 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 Schocheraeb29912010-09-17 13:10:39 +020021
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020022At board level:
Heiko Schocheraeb29912010-09-17 13:10:39 +020023
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020024 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 Schocheraeb29912010-09-17 13:10:39 +020027
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020028TODO: move also dram initialization there on boards where it is possible.
Heiko Schocheraeb29912010-09-17 13:10:39 +020029
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020030 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 Schocheraeb29912010-09-17 13:10:39 +020032
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020033At lib level:
Heiko Schocheraeb29912010-09-17 13:10:39 +020034
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020035 Board.c code is adapted from ppc code
Heiko Schocheraeb29912010-09-17 13:10:39 +020036
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020037At config level:
Heiko Schocheraeb29912010-09-17 13:10:39 +020038
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020039 Undefine CONFIG_SYS_ARM_WITHOUT_RELOC
Heiko Schocheraeb29912010-09-17 13:10:39 +020040
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020041* WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
Heiko Schocheraeb29912010-09-17 13:10:39 +020042
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020043Boards which are not fixed to support relocation will be REMOVED!
44
Wolfgang Denkd0813e52010-10-28 20:00:11 +020045Eventually, CONFIG_SYS_ARM_WITHOUT_RELOC will disappear and boards
46which have to migrated to relocation will disappear too.
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020047
48-----------------------------------------------------------------------------
49
50For boards which boot from nand_spl, it is possible to save one copy
Wolfgang Denk0708bc62010-10-07 21:51:12 +020051if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
Heiko Schocher0e2412a2010-09-17 13:10:42 +020052is copied again in relocate_code().
53
54example for the tx25 board:
55
56a) cpu starts
57b) it copies the first page in nand to internal ram
58 (nand_spl_code)
59c) end executes this code
60d) this initialize CPU, RAM, ... and copy itself to RAM
61 (this bin must fit in one page, so board_init_f()
62 don;t fit in it ... )
63e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
64 starts this image @ CONFIG_SYS_NAND_U_BOOT_START
65f) u-boot code steps through board_init_f() and calculates
66 the relocation address and copy itself to it
67
Wolfgang Denk0708bc62010-10-07 21:51:12 +020068If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
Heiko Schocher0e2412a2010-09-17 13:10:42 +020069in f) could be saved.
70
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020071-----------------------------------------------------------------------------
Heiko Schocher0e2412a2010-09-17 13:10:42 +020072
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020073TODO
Heiko Schocheraeb29912010-09-17 13:10:39 +020074
75- fill in bd_t infos (check)
76- adapt all boards
77
Wolfgang Denk0708bc62010-10-07 21:51:12 +020078- maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
Heiko Schocheraeb29912010-09-17 13:10:39 +020079 This *must* be done for boards, which boot from NOR flash
80
Wolfgang Denk0708bc62010-10-07 21:51:12 +020081 on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
Heiko Schocheraeb29912010-09-17 13:10:39 +020082 one copying from u-boot code.
83
84- new function dram_init_banksize() is actual board specific. Maybe
85 we make a weak default function in arch/arm/lib/board.c ?
86
Albert Aribaud6d1fcb12010-10-11 13:13:28 +020087-----------------------------------------------------------------------------
Heiko Schocheraeb29912010-09-17 13:10:39 +020088
89Relocation with NAND_SPL (example for the tx25):
90
91- cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
92 and start with code execution on this address.
93
94- The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
Wolfgang Denk1136f69e2010-10-27 22:48:30 +020095 which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
Heiko Schocheraeb29912010-09-17 13:10:39 +020096 the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
97 @CONFIG_SYS_NAND_U_BOOT_START
98
Wolfgang Denkfb2759c2010-10-18 23:43:37 +020099- 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.
Heiko Schocheraeb29912010-09-17 13:10:39 +0200104
Albert Aribaud6d1fcb12010-10-11 13:13:28 +0200105-----------------------------------------------------------------------------
Heiko Schocheraeb29912010-09-17 13:10:39 +0200106
Albert Aribaud6d1fcb12010-10-11 13:13:28 +0200107How ELF relocations 23 and 2 work.
Heiko Schocheraeb29912010-09-17 13:10:39 +0200108
Albert Aribaud6d1fcb12010-10-11 13:13:28 +0200109TBC
Heiko Schocheraeb29912010-09-17 13:10:39 +0200110
111-------------------------------------------------------------------------------------
112
113Debugging u-boot in RAM:
114(example on the qong board)
115
116a) add in config.mk:
117
118PLATFORM_CPPFLAGS += -DDEBUG
119
120-----------------
121
122b) start debugger
123
124arm-linux-gdb u-boot
125
126[hs@pollux u-boot]$ arm-linux-gdb u-boot
127GNU gdb Red Hat Linux (6.7-2rh)
128Copyright (C) 2007 Free Software Foundation, Inc.
129License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
130This is free software: you are free to change and redistribute it.
131There is NO WARRANTY, to the extent permitted by law. Type "show copying"
132and "show warranty" for details.
133This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
134The target architecture is set automatically (currently arm)
135..
136(gdb)
137
138-----------------
139
140c) connect to target
141
142target remote bdi10:2001
143
144(gdb) target remote bdi10:2001
145Remote debugging using bdi10:2001
1460x8ff17f10 in ?? ()
147(gdb)
148
149-----------------
150
151d) discard symbol-file
152
153(gdb) symbol-file
154Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
155No symbol file now.
156(gdb)
157
158-----------------
159
160e) load new symbol table:
161
162(gdb) add-symbol-file u-boot 0x8ff08000
163add symbol table from file "u-boot" at
Wolfgang Denk1136f69e2010-10-27 22:48:30 +0200164 .text_addr = 0x8ff08000
Heiko Schocheraeb29912010-09-17 13:10:39 +0200165(y or n) y
166Reading symbols from /home/hs/celf/u-boot/u-boot...done.
167(gdb) c
168Continuing.
169^C
170Program received signal SIGSTOP, Stopped (signal).
1710x8ff17f18 in serial_getc () at serial_mxc.c:192
Wolfgang Denk1136f69e2010-10-27 22:48:30 +0200172192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
Heiko Schocheraeb29912010-09-17 13:10:39 +0200173(gdb)
174
175add-symbol-file u-boot 0x8ff08000
Wolfgang Denk1136f69e2010-10-27 22:48:30 +0200176 ^^^^^^^^^^
177 get this address from u-boot debug printfs
Heiko Schocheraeb29912010-09-17 13:10:39 +0200178
179U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
180
181U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10
182CPU: Freescale i.MX31 at 398 MHz
183Board: DAVE/DENX Qong
184mon: FFFFFFFF gd->monLen: 00061F10
185Top of RAM usable for U-Boot at: 90000000
186LCD panel info: 640 x 480, 16 bit/pix
187Reserving 600k for LCD Framebuffer at: 8ff6a000
188Reserving 391k for U-Boot at: 8ff08000
Wolfgang Denk1136f69e2010-10-27 22:48:30 +0200189 ^^^^^^^^
Heiko Schocheraeb29912010-09-17 13:10:39 +0200190Reserving 1280k for malloc() at: 8fdc8000
191Reserving 24 Bytes for Board Info at: 8fdc7fe8
192Reserving 52 Bytes for Global Data at: 8fdc7fb4
193New Stack Pointer is: 8fdc7fb0
194RAM Configuration:
195Bank #0: 80000000 256 MiB
196relocation Offset is: eff08000
197mon: 00058BAC gd->monLen: 00061F10
198Now running in RAM - U-Boot at: 8ff08000
Wolfgang Denk1136f69e2010-10-27 22:48:30 +0200199 ^^^^^^^^
Heiko Schocheraeb29912010-09-17 13:10:39 +0200200
201Now you can use gdb as usual :-)