README.arm-relocation 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. To make relocation on arm working, the following changes are done:
  2. Add new compilerflag:
  3. -fPIC
  4. -> compiler generates position independent code
  5. changes in board code:
  6. - dram_init:
  7. - bd pointer is now at this point not accessible, so only
  8. detect the real dramsize, and store it in gd->ram_size.
  9. best detected with get_ram_size();
  10. ToDo: move there also the dram initialization on boards where
  11. it is possible.
  12. - setup the bd_t dram bank info in the new function
  13. dram_init_banksize().
  14. - board.c code is adapted from ppc code
  15. - undef CONFIG_RELOC_FIXUP_WORKS
  16. -> cmdtabl, and subcommand table must be handled from "hand"
  17. collected in section "__datarellocal_start".
  18. - How To fixup the sections:
  19. __datarel_start, __datarelrolocal_start, __datarellocal_start and
  20. __datarelro_start
  21. automatically? Then it should be possible to define again
  22. CONFIG_RELOC_FIXUP_WORKS
  23. - irq stack setup is now not longer on a fix position, instead it is
  24. calculated in board_init_f, and stored in gd->irq_sp
  25. -------------------------------------------------------------------------------------
  26. To compile a board without relocation, define CONFIG_SYS_ARM_WITHOUT_RELOC
  27. This possibility will removed!! So please fix your board to compile without
  28. CONFIG_SYS_ARM_WITHOUT_RELOC defined!!!
  29. -------------------------------------------------------------------------------------
  30. For boards which boot from nand_spl, it is possible to save a copy
  31. if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
  32. is copied again in relocate_code().
  33. example for the tx25 board:
  34. a) cpu starts
  35. b) it copies the first page in nand to internal ram
  36. (nand_spl_code)
  37. c) end executes this code
  38. d) this initialize CPU, RAM, ... and copy itself to RAM
  39. (this bin must fit in one page, so board_init_f()
  40. don;t fit in it ... )
  41. e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
  42. starts this image @ CONFIG_SYS_NAND_U_BOOT_START
  43. f) u-boot code steps through board_init_f() and calculates
  44. the relocation address and copy itself to it
  45. If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
  46. in f) could be saved.
  47. -------------------------------------------------------------------------------------
  48. ToDo:
  49. - fill in bd_t infos (check)
  50. - adapt all boards
  51. - maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
  52. This *must* be done for boards, which boot from NOR flash
  53. on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
  54. one copying from u-boot code.
  55. - new function dram_init_banksize() is actual board specific. Maybe
  56. we make a weak default function in arch/arm/lib/board.c ?
  57. -------------------------------------------------------------------------------------
  58. Relocation with NAND_SPL (example for the tx25):
  59. - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
  60. and start with code execution on this address.
  61. - The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
  62. which inits the dram, cpu registers, reloacte itself to CONFIG_SYS_TEXT_BASE and loads
  63. the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
  64. @CONFIG_SYS_NAND_U_BOOT_START
  65. - This u-boot does no RAM init, nor CPU register setup. Just look
  66. where it has to copy and relocate itself to this address. If
  67. relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the
  68. CONFIG_SYS_TEXT_BASE from the nand_spl code), then there is no need
  69. to copy, just go on with bss clear and jump to board_init_r.
  70. -------------------------------------------------------------------------------------
  71. Relocation:
  72. How to translate flash addresses in GOT to ram addresses.
  73. This is automagically done from code, but this example
  74. shows, how this magic code works ;-)
  75. (example on the qong board)
  76. Find a variable:
  77. a) search it in System.map
  78. (for example flash_info)
  79. a005b4c0 B BootpID
  80. a005b4c4 B BootpTry
  81. a005b4c8 b slave
  82. a005b4cc B flash_info
  83. ^^^^^^^^
  84. a005c908 b saved_sector.4002
  85. a005c910 b cfi_mtd_info
  86. a005c9c0 b cfi_mtd_names
  87. a005c9d0 B mtd_table
  88. ---------------------------------------
  89. b) create hexdump from u-boot code:
  90. hexdump -C u-boot > gnlmpfhex
  91. ---------------------------------------
  92. c) search the variables address in the hexdump
  93. *
  94. 0005fc80 00 00 00 00 00 00 00 00 2c 06 01 a0 18 cd 05 a0 |........,.......|
  95. 0005fc90 9c d4 05 a0 bc b4 05 a0 1c 7f 05 a0 f0 05 01 a0 |................|
  96. 0005fca0 08 5a 04 a0 1c ab 05 a0 ec a4 05 a0 98 c3 01 a0 |.Z..............|
  97. 0005fcb0 a0 d6 05 a0 04 71 05 a0 c0 f9 00 a0 3c cd 05 a0 |.....q......<...|
  98. 0005fcc0 cc b4 05 a0 f0 fa 00 a0 f0 d6 05 a0 10 86 05 a0 |................|
  99. ^^^^^^^^^^^
  100. 0005fcd0 a4 16 06 a0 dc 64 05 a0 18 86 05 a0 52 48 05 a0 |.....d......RH..|
  101. 0005fce0 c0 86 05 a0 24 6e 02 a0 b4 6c 05 a0 b0 94 01 a0 |....$n...l......|
  102. 0005fcf0 1c 86 05 a0 50 85 05 a0 d4 0c 06 a0 bc 0b 06 a0 |....P...........|
  103. -> 0005fcc0
  104. ----------------------------------------
  105. d) know we calculate this address in RAM
  106. 8ff08000 (new address of code in RAM *1)
  107. + 0005fcc0
  108. - 00008000 (offset of text *2)
  109. ----------
  110. 8ff5fcc0 -> Addr GOT in RAM
  111. *1:
  112. activate debug and look for the line:
  113. Now running in RAM - U-Boot at: 8ff08000
  114. ^^^^^^^^
  115. new address of u-boot code in RAM
  116. *2:
  117. Section Headers:
  118. [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
  119. [ 0] NULL 00000000 000000 000000 00 0 0 0
  120. [ 1] .text PROGBITS a0000000 008000 04599c 00 AX 0 0 32
  121. ^^^^^^
  122. Offset of text
  123. ----------------------------------------
  124. e) now we look in 8ff5fcc0 (RAM)
  125. QongEVB>md 0x8ff5fcc0
  126. 8ff5fcc0 : a005b4cc a000faf0 a005d6f0 a0058610 ................
  127. ^^^^^^^^
  128. Bingo, here we have the old flash address (when relocation
  129. is working, here is the fixed ram address. see @ f, how
  130. it gets calculated)
  131. ----------------------------------------
  132. f) now translate it in the new RAM address
  133. a005b4cc
  134. - a0000000 TextBase
  135. + 8ff08000 new address of u-boot in ram
  136. ----------
  137. 8ff634cc
  138. QongEVB>mm 0x8ff5fcc0 0x8ff634cc 1
  139. QongEVB>md 0x8ff5fcc0
  140. 8ff5fcc0 : 8ff634cc a000faf0 a005d6f0 a0058610 .4..............
  141. 8ff5fcd0 : a00616a4 a00564dc a0058618 a0054852 .....d......RH..
  142. As this must be done for all address in the GOT, the u-boot
  143. code did this automagically ... :-)
  144. ----------------------------------------------
  145. g) check if the new address is really in the bss section:
  146. bss start:
  147. 8ff6054c (8ff08000 + 0005854C monitorlen)
  148. bss end:
  149. 8ff698ac (8ff08000 + 618AC)
  150. 8ff634cc is in bss :-)
  151. ----------------------------------------------
  152. h) u-boot prints:
  153. important addresses:
  154. U-Boot code: A0000000 -> A005854C BSS: -> A00618AC TextBase 0xa0000000
  155. Now running in RAM - U-Boot at: 8ff08000 relocBase 0x8ff08000
  156. ---------
  157. U-Boot 2010.06-rc2-00002-gf8fbb25-dirty (Jun 18 2010 - 17:07:19)
  158. U-Boot code: A0000000 -> A005854C BSS: -> A00618AC
  159. CPU: Freescale i.MX31 at 398 MHz
  160. Board: DAVE/DENX Qong
  161. mon: FFFFFFFF gd->monLen: 000618AC
  162. Top of RAM usable for U-Boot at: 90000000
  163. LCD panel info: 640 x 480, 16 bit/pix
  164. Reserving 600k for LCD Framebuffer at: 8ff6a000
  165. Reserving 390k for U-Boot at: 8ff08000
  166. Reserving 1280k for malloc() at: 8fdc8000
  167. Reserving 28 Bytes for Board Info at: 8fdc7fe4
  168. Reserving 48 Bytes for Global Data at: 8fdc7fb4
  169. New Stack Pointer is: 8fdc7fb0
  170. RAM Configuration:
  171. Bank #0: 80000000 256 MiB
  172. mon: 0005854C gd->monLen: 000618AC
  173. Now running in RAM - U-Boot at: 8ff08000
  174. -------------------------------------------------------------------------------------
  175. Debugging u-boot in RAM:
  176. (example on the qong board)
  177. a) add in config.mk:
  178. PLATFORM_CPPFLAGS += -DDEBUG
  179. -----------------
  180. b) start debugger
  181. arm-linux-gdb u-boot
  182. [hs@pollux u-boot]$ arm-linux-gdb u-boot
  183. GNU gdb Red Hat Linux (6.7-2rh)
  184. Copyright (C) 2007 Free Software Foundation, Inc.
  185. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  186. This is free software: you are free to change and redistribute it.
  187. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  188. and "show warranty" for details.
  189. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
  190. The target architecture is set automatically (currently arm)
  191. ..
  192. (gdb)
  193. -----------------
  194. c) connect to target
  195. target remote bdi10:2001
  196. (gdb) target remote bdi10:2001
  197. Remote debugging using bdi10:2001
  198. 0x8ff17f10 in ?? ()
  199. (gdb)
  200. -----------------
  201. d) discard symbol-file
  202. (gdb) symbol-file
  203. Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
  204. No symbol file now.
  205. (gdb)
  206. -----------------
  207. e) load new symbol table:
  208. (gdb) add-symbol-file u-boot 0x8ff08000
  209. add symbol table from file "u-boot" at
  210. .text_addr = 0x8ff08000
  211. (y or n) y
  212. Reading symbols from /home/hs/celf/u-boot/u-boot...done.
  213. (gdb) c
  214. Continuing.
  215. ^C
  216. Program received signal SIGSTOP, Stopped (signal).
  217. 0x8ff17f18 in serial_getc () at serial_mxc.c:192
  218. 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
  219. (gdb)
  220. add-symbol-file u-boot 0x8ff08000
  221. ^^^^^^^^^^
  222. get this address from u-boot debug printfs
  223. U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
  224. U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10
  225. CPU: Freescale i.MX31 at 398 MHz
  226. Board: DAVE/DENX Qong
  227. mon: FFFFFFFF gd->monLen: 00061F10
  228. Top of RAM usable for U-Boot at: 90000000
  229. LCD panel info: 640 x 480, 16 bit/pix
  230. Reserving 600k for LCD Framebuffer at: 8ff6a000
  231. Reserving 391k for U-Boot at: 8ff08000
  232. ^^^^^^^^
  233. Reserving 1280k for malloc() at: 8fdc8000
  234. Reserving 24 Bytes for Board Info at: 8fdc7fe8
  235. Reserving 52 Bytes for Global Data at: 8fdc7fb4
  236. New Stack Pointer is: 8fdc7fb0
  237. RAM Configuration:
  238. Bank #0: 80000000 256 MiB
  239. relocation Offset is: eff08000
  240. mon: 00058BAC gd->monLen: 00061F10
  241. Now running in RAM - U-Boot at: 8ff08000
  242. ^^^^^^^^
  243. Now you can use gdb as usual :-)