bootloader.ld 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * TODO: IDF-8002
  8. * Simplified memory map for the bootloader.
  9. * Make sure the bootloader can load into main memory without overwriting itself.
  10. *
  11. * ESP32-P4 ROM static data usage is as follows:
  12. * - 0x4086ad08 - 0x4087c610: Shared buffers, used in UART/USB/SPI download mode only
  13. * - 0x4087c610 - 0x4087e610: CPU1 stack, can be reclaimed as heap after RTOS startup
  14. * - 0x4087e610 - 0x40880000: ROM .bss and .data (not easily reclaimable)
  15. *
  16. * The 2nd stage bootloader can take space up to the end of ROM shared
  17. * buffers area (0x4087c610).
  18. */
  19. /* We consider 0x4087c610 to be the last usable address for 2nd stage bootloader stack overhead, dram_seg,
  20. * and work out iram_seg and iram_loader_seg addresses from there, backwards.
  21. */
  22. /* These lengths can be adjusted, if necessary: */
  23. bootloader_usable_dram_end = 0x4ff3abd0;
  24. bootloader_stack_overhead = 0x2000; /* For safety margin between bootloader data section and startup stacks */
  25. bootloader_dram_seg_len = 0x4000;
  26. bootloader_iram_loader_seg_len = 0x7000;
  27. bootloader_iram_seg_len = 0x2000;
  28. /* Start of the lower region is determined by region size and the end of the higher region */
  29. bootloader_dram_seg_end = bootloader_usable_dram_end - bootloader_stack_overhead;
  30. bootloader_dram_seg_start = bootloader_dram_seg_end - bootloader_dram_seg_len;
  31. bootloader_iram_loader_seg_start = bootloader_dram_seg_start - bootloader_iram_loader_seg_len;
  32. bootloader_iram_seg_start = bootloader_iram_loader_seg_start - bootloader_iram_seg_len;
  33. MEMORY
  34. {
  35. iram_seg (RWX) : org = bootloader_iram_seg_start, len = bootloader_iram_seg_len
  36. iram_loader_seg (RWX) : org = bootloader_iram_loader_seg_start, len = bootloader_iram_loader_seg_len
  37. dram_seg (RW) : org = bootloader_dram_seg_start, len = bootloader_dram_seg_len
  38. }
  39. /* The app may use RAM for static allocations up to the start of iram_loader_seg.
  40. * If you have changed something above and this assert fails:
  41. * 1. Check what the new value of bootloader_iram_loader_seg start is.
  42. * 2. Update the value in this assert.
  43. * 3. Update SRAM_DRAM_END in components/esp_system/ld/esp32p4/memory.ld.in to the same value.
  44. */
  45. ASSERT(bootloader_iram_loader_seg_start == 0x4FF2DBD0, "bootloader_iram_loader_seg_start inconsistent with SRAM_DRAM_END");
  46. /* Default entry point: */
  47. ENTRY(call_start_cpu0);
  48. SECTIONS
  49. {
  50. .iram_loader.text :
  51. {
  52. . = ALIGN (16);
  53. _loader_text_start = ABSOLUTE(.);
  54. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  55. *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
  56. *liblog.a:(.literal .text .literal.* .text.*)
  57. *libgcc.a:(.literal .text .literal.* .text.*)
  58. *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
  59. *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
  60. *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
  61. *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
  62. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
  63. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
  64. *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
  65. *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
  66. *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
  67. *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
  68. *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
  69. *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
  70. *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
  71. *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
  72. *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
  73. *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
  74. *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
  75. *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
  76. *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
  77. *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
  78. *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
  79. *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
  80. *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
  81. *libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
  82. *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
  83. *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
  84. *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
  85. *libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)
  86. *libefuse.a:*.*(.literal .text .literal.* .text.*)
  87. *(.fini.literal)
  88. *(.fini)
  89. *(.gnu.version)
  90. _loader_text_end = ABSOLUTE(.);
  91. } > iram_loader_seg
  92. .iram.text :
  93. {
  94. . = ALIGN (16);
  95. *(.entry.text)
  96. *(.init.literal)
  97. *(.init)
  98. } > iram_seg
  99. /* Shared RAM */
  100. .dram0.bss (NOLOAD) :
  101. {
  102. . = ALIGN (8);
  103. _dram_start = ABSOLUTE(.);
  104. _bss_start = ABSOLUTE(.);
  105. *(.dynsbss)
  106. *(.sbss)
  107. *(.sbss.*)
  108. *(.gnu.linkonce.sb.*)
  109. *(.scommon)
  110. *(.sbss2)
  111. *(.sbss2.*)
  112. *(.gnu.linkonce.sb2.*)
  113. *(.dynbss)
  114. *(.bss)
  115. *(.bss.*)
  116. *(.gnu.linkonce.b.*)
  117. *(COMMON)
  118. . = ALIGN (8);
  119. _bss_end = ABSOLUTE(.);
  120. } > dram_seg
  121. .dram0.data :
  122. {
  123. _data_start = ABSOLUTE(.);
  124. *(.data)
  125. *(.data.*)
  126. *(.gnu.linkonce.d.*)
  127. *(.data1)
  128. *(.sdata)
  129. *(.sdata.*)
  130. *(.gnu.linkonce.s.*)
  131. *(.gnu.linkonce.s2.*)
  132. *(.jcr)
  133. _data_end = ABSOLUTE(.);
  134. } > dram_seg
  135. .dram0.rodata :
  136. {
  137. _rodata_start = ABSOLUTE(.);
  138. *(.rodata)
  139. *(.rodata.*)
  140. *(.gnu.linkonce.r.*)
  141. *(.rodata1)
  142. *(.sdata2 .sdata2.* .srodata .srodata.*)
  143. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  144. *(.xt_except_table)
  145. *(.gcc_except_table)
  146. *(.gnu.linkonce.e.*)
  147. *(.gnu.version_r)
  148. *(.eh_frame)
  149. . = (. + 3) & ~ 3;
  150. /* C++ constructor and destructor tables, properly ordered: */
  151. __init_array_start = ABSOLUTE(.);
  152. KEEP (*crtbegin.*(.ctors))
  153. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  154. KEEP (*(SORT(.ctors.*)))
  155. KEEP (*(.ctors))
  156. __init_array_end = ABSOLUTE(.);
  157. KEEP (*crtbegin.*(.dtors))
  158. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  159. KEEP (*(SORT(.dtors.*)))
  160. KEEP (*(.dtors))
  161. /* C++ exception handlers table: */
  162. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  163. *(.xt_except_desc)
  164. *(.gnu.linkonce.h.*)
  165. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  166. *(.xt_except_desc_end)
  167. *(.dynamic)
  168. *(.gnu.version_d)
  169. _rodata_end = ABSOLUTE(.);
  170. /* Literals are also RO data. */
  171. _lit4_start = ABSOLUTE(.);
  172. *(*.lit4)
  173. *(.lit4.*)
  174. *(.gnu.linkonce.lit4.*)
  175. _lit4_end = ABSOLUTE(.);
  176. . = ALIGN(4);
  177. _dram_end = ABSOLUTE(.);
  178. } > dram_seg
  179. .iram.text :
  180. {
  181. _stext = .;
  182. _text_start = ABSOLUTE(.);
  183. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  184. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  185. *(.fini.literal)
  186. *(.fini)
  187. *(.gnu.version)
  188. /** CPU will try to prefetch up to 16 bytes of
  189. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  190. * safe access to up to 16 bytes after the last real instruction, add
  191. * dummy bytes to ensure this
  192. */
  193. . += 16;
  194. _text_end = ABSOLUTE(.);
  195. _etext = .;
  196. } > iram_seg
  197. }
  198. /**
  199. * Appendix: Memory Usage of ROM bootloader
  200. *
  201. * 0x4086ad08 ------------------> _dram0_0_start
  202. * | |
  203. * | |
  204. * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
  205. * | |
  206. * | |
  207. * 0x4087c610 ------------------> __stack_sentry
  208. * | |
  209. * | | 2. Startup pro cpu stack (freed when IDF app is running)
  210. * | |
  211. * 0x4087e610 ------------------> __stack (pro cpu)
  212. * | |
  213. * | |
  214. * | | 3. Shared memory only used in startup code or nonos/early boot*
  215. * | | (can be freed when IDF runs)
  216. * | |
  217. * | |
  218. * 0x4087f564 ------------------> _dram0_rtos_reserved_start
  219. * | |
  220. * | |
  221. * | | 4. Shared memory used in startup code and when IDF runs
  222. * | |
  223. * | |
  224. * 0x4087fab0 ------------------> _dram0_rtos_reserved_end
  225. * | |
  226. * 0x4087fce8 ------------------> _data_start_interface
  227. * | |
  228. * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
  229. * | |
  230. * 0x40880000 ------------------> _data_end_interface
  231. */