README.arm-relocation 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. To make relocation on arm working, the following changes are done:
  2. At arch level: add linker flag -pie
  3. This causes the linker to generate fixup tables .rel.dyn and .dynsym,
  4. which must be applied to the relocated image before transferring
  5. control to it.
  6. These fixups are described in the ARM ELF documentation as type 23
  7. (program-base-relative) and 2 (symbol-relative)
  8. At cpu level: modify linker file and add a relocation and fixup loop
  9. the linker file must be modified to include the .rel.dyn and .dynsym
  10. tables in the binary image, and to provide symbols for the relocation
  11. code to access these tables
  12. The relocation and fixup loop must be executed after executing
  13. board_init_f at initial location and before executing board_init_r
  14. at final location.
  15. At board level:
  16. dram_init(): bd pointer is now at this point not accessible, so only
  17. detect the real dramsize, and store it in gd->ram_size. Bst detected
  18. with get_ram_size().
  19. TODO: move also dram initialization there on boards where it is possible.
  20. Setup of the the bd_t dram bank info is done in the new function
  21. dram_init_banksize() called after bd is accessible.
  22. At lib level:
  23. Board.c code is adapted from ppc code
  24. At config level:
  25. Define CONFIG_RELOC_FIXUP_WORKS.
  26. Undefine CONFIG_SYS_ARM_WITHOUT_RELOC
  27. * WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
  28. Boards which are not fixed to support relocation will be REMOVED!
  29. Eventually, CONFIG_SYS_ARM_WITHOUT_RELOC and CONFIG_RELOC_FIXUP_WORKS will
  30. disappear and boards which have to migrated to relocation will disappear too.
  31. -----------------------------------------------------------------------------
  32. For boards which boot from nand_spl, it is possible to save one copy
  33. if TEXT_BASE == relocation address! This prevents that uboot code
  34. is copied again in relocate_code().
  35. example for the tx25 board:
  36. a) cpu starts
  37. b) it copies the first page in nand to internal ram
  38. (nand_spl_code)
  39. c) end executes this code
  40. d) this initialize CPU, RAM, ... and copy itself to RAM
  41. (this bin must fit in one page, so board_init_f()
  42. don;t fit in it ... )
  43. e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
  44. starts this image @ CONFIG_SYS_NAND_U_BOOT_START
  45. f) u-boot code steps through board_init_f() and calculates
  46. the relocation address and copy itself to it
  47. If TEXT_BASE == relocation address, the copying of u-boot
  48. in f) could be saved.
  49. -----------------------------------------------------------------------------
  50. TODO
  51. - fill in bd_t infos (check)
  52. - adapt all boards
  53. - maybe adapt TEXT_BASE (this must be checked from board maintainers)
  54. This *must* be done for boards, which boot from NOR flash
  55. on other boards if TEXT_BASE = relocation baseaddr, this saves
  56. one copying from u-boot code.
  57. - new function dram_init_banksize() is actual board specific. Maybe
  58. we make a weak default function in arch/arm/lib/board.c ?
  59. -----------------------------------------------------------------------------
  60. Relocation with NAND_SPL (example for the tx25):
  61. - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
  62. and start with code execution on this address.
  63. - The First page contains u-boot code from u-boot:nand_spl/nand_boot_fsl_nfc.c
  64. which inits the dram, cpu registers, reloacte itself to TEXT_BASE and loads
  65. the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
  66. @CONFIG_SYS_NAND_U_BOOT_START
  67. - This u-boot does no ram int, nor cpu register setup. Just looks
  68. where it have to relocate and relocate itself to this address.
  69. If relocate address = TEXT_BASE(not the same, as the TEXT_BASE
  70. from the nand_spl code), no need to copy, just go on with bss clear
  71. and jump to board_init_r.
  72. -----------------------------------------------------------------------------
  73. How ELF relocations 23 and 2 work.
  74. TBC
  75. -------------------------------------------------------------------------------------
  76. Debugging u-boot in RAM:
  77. (example on the qong board)
  78. a) add in config.mk:
  79. PLATFORM_CPPFLAGS += -DDEBUG
  80. -----------------
  81. b) start debugger
  82. arm-linux-gdb u-boot
  83. [hs@pollux u-boot]$ arm-linux-gdb u-boot
  84. GNU gdb Red Hat Linux (6.7-2rh)
  85. Copyright (C) 2007 Free Software Foundation, Inc.
  86. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  87. This is free software: you are free to change and redistribute it.
  88. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  89. and "show warranty" for details.
  90. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
  91. The target architecture is set automatically (currently arm)
  92. ..
  93. (gdb)
  94. -----------------
  95. c) connect to target
  96. target remote bdi10:2001
  97. (gdb) target remote bdi10:2001
  98. Remote debugging using bdi10:2001
  99. 0x8ff17f10 in ?? ()
  100. (gdb)
  101. -----------------
  102. d) discard symbol-file
  103. (gdb) symbol-file
  104. Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
  105. No symbol file now.
  106. (gdb)
  107. -----------------
  108. e) load new symbol table:
  109. (gdb) add-symbol-file u-boot 0x8ff08000
  110. add symbol table from file "u-boot" at
  111. .text_addr = 0x8ff08000
  112. (y or n) y
  113. Reading symbols from /home/hs/celf/u-boot/u-boot...done.
  114. (gdb) c
  115. Continuing.
  116. ^C
  117. Program received signal SIGSTOP, Stopped (signal).
  118. 0x8ff17f18 in serial_getc () at serial_mxc.c:192
  119. 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
  120. (gdb)
  121. add-symbol-file u-boot 0x8ff08000
  122. ^^^^^^^^^^
  123. get this address from u-boot debug printfs
  124. U-Boot 2010.06-rc2-00009-gf77b8b8-dirty (Jun 22 2010 - 09:43:46)
  125. U-Boot code: A0000000 -> A0058BAC BSS: -> A0061F10
  126. CPU: Freescale i.MX31 at 398 MHz
  127. Board: DAVE/DENX Qong
  128. mon: FFFFFFFF gd->monLen: 00061F10
  129. Top of RAM usable for U-Boot at: 90000000
  130. LCD panel info: 640 x 480, 16 bit/pix
  131. Reserving 600k for LCD Framebuffer at: 8ff6a000
  132. Reserving 391k for U-Boot at: 8ff08000
  133. ^^^^^^^^
  134. Reserving 1280k for malloc() at: 8fdc8000
  135. Reserving 24 Bytes for Board Info at: 8fdc7fe8
  136. Reserving 52 Bytes for Global Data at: 8fdc7fb4
  137. New Stack Pointer is: 8fdc7fb0
  138. RAM Configuration:
  139. Bank #0: 80000000 256 MiB
  140. relocation Offset is: eff08000
  141. mon: 00058BAC gd->monLen: 00061F10
  142. Now running in RAM - U-Boot at: 8ff08000
  143. ^^^^^^^^
  144. Now you can use gdb as usual :-)