bootloader.ld 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /** Simplified memory map for the bootloader.
  7. * Make sure the bootloader can load into main memory without overwriting itself.
  8. *
  9. * ESP32-H2 ROM static data usage is as follows:
  10. * - 0x4083ba78 - 0x4084d380: Shared buffers, used in UART/USB/SPI download mode only
  11. * - 0x4084d380 - 0x4084f380: PRO CPU stack, can be reclaimed as heap after RTOS startup
  12. * - 0x4084f380 - 0x4084fee0: ROM .bss and .data used in startup code or nonos/early boot (can be freed when IDF runs)
  13. * - 0x4084fee0 - 0x40850000: ROM .bss and .data used in startup code and when IDF runs (cannot be freed)
  14. *
  15. * The 2nd stage bootloader can take space up to the end of ROM shared
  16. * buffers area (0x4084d380).
  17. */
  18. /* We consider 0x3fcdc710 to be the last usable address for 2nd stage bootloader stack overhead, dram_seg,
  19. * and work out iram_seg and iram_loader_seg addresses from there, backwards.
  20. */
  21. /* These lengths can be adjusted, if necessary: */
  22. bootloader_usable_dram_end = 0x4084cfd0;
  23. bootloader_stack_overhead = 0x2000; /* For safety margin between bootloader data section and startup stacks */
  24. bootloader_dram_seg_len = 0x5000;
  25. bootloader_iram_loader_seg_len = 0x7000;
  26. bootloader_iram_seg_len = 0x2000;
  27. /* Start of the lower region is determined by region size and the end of the higher region */
  28. bootloader_dram_seg_end = bootloader_usable_dram_end - bootloader_stack_overhead;
  29. bootloader_dram_seg_start = bootloader_dram_seg_end - bootloader_dram_seg_len;
  30. bootloader_iram_loader_seg_start = bootloader_dram_seg_start - bootloader_iram_loader_seg_len;
  31. bootloader_iram_seg_start = bootloader_iram_loader_seg_start - bootloader_iram_seg_len;
  32. MEMORY
  33. {
  34. iram_seg (RWX) : org = bootloader_iram_seg_start, len = bootloader_iram_seg_len
  35. iram_loader_seg (RWX) : org = bootloader_iram_loader_seg_start, len = bootloader_iram_loader_seg_len
  36. dram_seg (RW) : org = bootloader_dram_seg_start, len = bootloader_dram_seg_len
  37. }
  38. /* The app may use RAM for static allocations up to the start of iram_loader_seg.
  39. * If you have changed something above and this assert fails:
  40. * 1. Check what the new value of bootloader_iram_loader_seg start is.
  41. * 2. Update the value in this assert.
  42. * 3. Update SRAM_DRAM_END in components/esp_system/ld/esp32h2/memory.ld.in to the same value.
  43. */
  44. ASSERT(bootloader_iram_loader_seg_start == 0x4083EFD0, "bootloader_iram_loader_seg_start inconsistent with SRAM_DRAM_END");
  45. /* Default entry point: */
  46. ENTRY(call_start_cpu0);
  47. SECTIONS
  48. {
  49. .iram_loader.text :
  50. {
  51. . = ALIGN (16);
  52. _loader_text_start = ABSOLUTE(.);
  53. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  54. *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
  55. *liblog.a:(.literal .text .literal.* .text.*)
  56. /* we use either libgcc or compiler-rt, so put similar entries for them here */
  57. *libgcc.a:(.literal .text .literal.* .text.*)
  58. *libclang_rt.builtins.a:(.literal .text .literal.* .text.*)
  59. *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
  60. *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
  61. *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
  62. *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
  63. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
  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.bootdesc : ALIGN(0x10)
  122. {
  123. _data_start = ABSOLUTE(.);
  124. *(.data_bootloader_desc .data_bootloader_desc.*) /* Should be the first. Bootloader version info. DO NOT PUT ANYTHING BEFORE IT! */
  125. } > dram_seg
  126. .dram0.data :
  127. {
  128. _data_start = ABSOLUTE(.);
  129. *(.data)
  130. *(.data.*)
  131. *(.gnu.linkonce.d.*)
  132. *(.data1)
  133. *(.sdata)
  134. *(.sdata.*)
  135. *(.gnu.linkonce.s.*)
  136. *(.gnu.linkonce.s2.*)
  137. *(.jcr)
  138. _data_end = ABSOLUTE(.);
  139. } > dram_seg
  140. .dram0.rodata :
  141. {
  142. _rodata_start = ABSOLUTE(.);
  143. *(.rodata)
  144. *(.rodata.*)
  145. *(.gnu.linkonce.r.*)
  146. *(.rodata1)
  147. *(.sdata2 .sdata2.* .srodata .srodata.*)
  148. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  149. *(.xt_except_table)
  150. *(.gcc_except_table)
  151. *(.gnu.linkonce.e.*)
  152. *(.gnu.version_r)
  153. *(.eh_frame)
  154. . = (. + 3) & ~ 3;
  155. /* C++ constructor and destructor tables, properly ordered: */
  156. __init_array_start = ABSOLUTE(.);
  157. KEEP (*crtbegin.*(.ctors))
  158. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  159. KEEP (*(SORT(.ctors.*)))
  160. KEEP (*(.ctors))
  161. __init_array_end = ABSOLUTE(.);
  162. KEEP (*crtbegin.*(.dtors))
  163. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  164. KEEP (*(SORT(.dtors.*)))
  165. KEEP (*(.dtors))
  166. /* C++ exception handlers table: */
  167. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  168. *(.xt_except_desc)
  169. *(.gnu.linkonce.h.*)
  170. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  171. *(.xt_except_desc_end)
  172. *(.dynamic)
  173. *(.gnu.version_d)
  174. _rodata_end = ABSOLUTE(.);
  175. /* Literals are also RO data. */
  176. _lit4_start = ABSOLUTE(.);
  177. *(*.lit4)
  178. *(.lit4.*)
  179. *(.gnu.linkonce.lit4.*)
  180. _lit4_end = ABSOLUTE(.);
  181. . = ALIGN(4);
  182. _dram_end = ABSOLUTE(.);
  183. } > dram_seg
  184. .iram.text :
  185. {
  186. _stext = .;
  187. _text_start = ABSOLUTE(.);
  188. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  189. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  190. *(.fini.literal)
  191. *(.fini)
  192. *(.gnu.version)
  193. /** CPU will try to prefetch up to 16 bytes of
  194. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  195. * safe access to up to 16 bytes after the last real instruction, add
  196. * dummy bytes to ensure this
  197. */
  198. . += 16;
  199. _text_end = ABSOLUTE(.);
  200. _etext = .;
  201. } > iram_seg
  202. }
  203. /**
  204. * Appendix: Memory Usage of ROM bootloader
  205. *
  206. * 0x4083ba78 ------------------> _dram0_0_start
  207. * | |
  208. * | |
  209. * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
  210. * | |
  211. * | |
  212. * 0x4084d380 ------------------> __stack_sentry
  213. * | |
  214. * | | 2. Startup pro cpu stack (freed when IDF app is running)
  215. * | |
  216. * 0x4084f380 ------------------> __stack (pro cpu)
  217. * | |
  218. * | |
  219. * | | 3. Shared memory only used in startup code or nonos/early boot*
  220. * | | (can be freed when IDF runs)
  221. * | |
  222. * | |
  223. * 0x4084fee0 ------------------> _dram0_rtos_reserved_start
  224. * | |
  225. * | |
  226. * | | 4. Shared memory used in startup code and when IDF runs
  227. * | |
  228. * | |
  229. * 0x4084ffc0 ------------------> _dram0_rtos_reserved_end
  230. * | |
  231. * 0x4084ffc8 ------------------> _data_start_interface
  232. * | |
  233. * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
  234. * | |
  235. * 0x40850000 ------------------> _data_end_interface
  236. */