README.arm-relocation 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. * WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING *
  25. Boards which are not fixed to support relocation will be REMOVED!
  26. -----------------------------------------------------------------------------
  27. For boards which boot from spl, it is possible to save one copy
  28. if CONFIG_SYS_TEXT_BASE == relocation address! This prevents that uboot code
  29. is copied again in relocate_code().
  30. example for the tx25 board booting from NAND Flash:
  31. a) cpu starts
  32. b) it copies the first page in nand to internal ram
  33. (spl code)
  34. c) end executes this code
  35. d) this initialize CPU, RAM, ... and copy itself to RAM
  36. (this bin must fit in one page, so board_init_f()
  37. don;t fit in it ... )
  38. e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
  39. starts this image @ CONFIG_SYS_NAND_U_BOOT_START
  40. f) u-boot code steps through board_init_f() and calculates
  41. the relocation address and copy itself to it
  42. If CONFIG_SYS_TEXT_BASE == relocation address, the copying of u-boot
  43. in f) could be saved.
  44. -----------------------------------------------------------------------------
  45. TODO
  46. - fill in bd_t infos (check)
  47. - adapt all boards
  48. - maybe adapt CONFIG_SYS_TEXT_BASE (this must be checked from board maintainers)
  49. This *must* be done for boards, which boot from NOR flash
  50. on other boards if CONFIG_SYS_TEXT_BASE = relocation baseaddr, this saves
  51. one copying from u-boot code.
  52. - new function dram_init_banksize() is actual board specific. Maybe
  53. we make a weak default function in arch/arm/lib/board.c ?
  54. -----------------------------------------------------------------------------
  55. Relocation with SPL (example for the tx25 booting from NAND Flash):
  56. - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE)
  57. and start with code execution on this address.
  58. - The First page contains u-boot code from drivers/mtd/nand/raw/mxc_nand_spl.c
  59. which inits the dram, cpu registers, reloacte itself to CONFIG_SPL_TEXT_BASE and loads
  60. the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution
  61. @CONFIG_SYS_NAND_U_BOOT_START
  62. - This u-boot does no RAM init, nor CPU register setup. Just look
  63. where it has to copy and relocate itself to this address. If
  64. relocate address = CONFIG_SYS_TEXT_BASE (not the same, as the
  65. CONFIG_SPL_TEXT_BASE from the spl code), then there is no need
  66. to copy, just go on with bss clear and jump to board_init_r.
  67. -----------------------------------------------------------------------------
  68. How ELF relocations 23 and 2 work.
  69. TBC
  70. -------------------------------------------------------------------------------------
  71. Debugging u-boot in RAM:
  72. (example on the qong board)
  73. -----------------
  74. a) start debugger
  75. arm-linux-gdb u-boot
  76. [hs@pollux u-boot]$ arm-linux-gdb u-boot
  77. GNU gdb Red Hat Linux (6.7-2rh)
  78. Copyright (C) 2007 Free Software Foundation, Inc.
  79. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  80. This is free software: you are free to change and redistribute it.
  81. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  82. and "show warranty" for details.
  83. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
  84. The target architecture is set automatically (currently arm)
  85. ..
  86. (gdb)
  87. -----------------
  88. b) connect to target
  89. target remote bdi10:2001
  90. (gdb) target remote bdi10:2001
  91. Remote debugging using bdi10:2001
  92. 0x8ff17f10 in ?? ()
  93. (gdb)
  94. -----------------
  95. c) discard symbol-file
  96. (gdb) symbol-file
  97. Discard symbol table from `/home/hs/celf/u-boot/u-boot'? (y or n) y
  98. No symbol file now.
  99. (gdb)
  100. -----------------
  101. d) load new symbol table:
  102. (gdb) add-symbol-file u-boot 0x8ff08000
  103. add symbol table from file "u-boot" at
  104. .text_addr = 0x8ff08000
  105. (y or n) y
  106. Reading symbols from /home/hs/celf/u-boot/u-boot...done.
  107. (gdb) c
  108. Continuing.
  109. ^C
  110. Program received signal SIGSTOP, Stopped (signal).
  111. 0x8ff17f18 in serial_getc () at serial_mxc.c:192
  112. 192 while (__REG(UART_PHYS + UTS) & UTS_RXEMPTY);
  113. (gdb)
  114. add-symbol-file u-boot 0x8ff08000
  115. ^^^^^^^^^^
  116. get this address from u-boot bdinfo command
  117. or get it from gd->relocaddr in gdb
  118. => bdinfo
  119. rch_number = XXXXXXXXXX
  120. boot_params = XXXXXXXXXX
  121. DRAM bank = XXXXXXXXXX
  122. -> start = XXXXXXXXXX
  123. -> size = XXXXXXXXXX
  124. ethaddr = XXXXXXXXXX
  125. ip_addr = XXXXXXXXXX
  126. baudrate = XXXXXXXXXX
  127. TLB addr = XXXXXXXXXX
  128. relocaddr = 0x8ff08000
  129. ^^^^^^^^^^
  130. reloc off = XXXXXXXXXX
  131. irq_sp = XXXXXXXXXX
  132. sp start = XXXXXXXXXX
  133. FB base = XXXXXXXXXX
  134. or interrupt execution by any means and re-load the symbols at the location
  135. specified by gd->relocaddr -- this is only valid after board_init_f.
  136. (gdb) set $s = gd->relocaddr
  137. (gdb) symbol-file
  138. (gdb) add-symbol-file u-boot $s
  139. Now you can use gdb as usual :-)