bootloader.ld 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 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-S3 ROM static data usage is as follows:
  10. * - 0x3fcd7e00 - 0x3fce9704: Shared buffers, used in UART/USB/SPI download mode only
  11. * - 0x3fce9710 - 0x3fceb710: PRO CPU stack, can be reclaimed as heap after RTOS startup
  12. * - 0x3fceb710 - 0x3fced710: APP CPU stack, can be reclaimed as heap after RTOS startup
  13. * - 0x3fced710 - 0x3fcf0000: ROM .bss and .data (not easily reclaimable)
  14. *
  15. * The 2nd stage bootloader can take space up to the end of ROM shared
  16. * buffers area (0x3fce9704). For alignment purpose we shall use value (0x3fce9700).
  17. */
  18. /* The offset between Dbus and Ibus. Used to convert between 0x403xxxxx and 0x3fcxxxxx addresses. */
  19. iram_dram_offset = 0x6f0000;
  20. /* We consider 0x3fce9700 to be the last usable address for 2nd stage bootloader stack overhead, dram_seg,
  21. * and work out iram_seg and iram_loader_seg addresses from there, backwards.
  22. */
  23. /* These lengths can be adjusted, if necessary: */
  24. bootloader_usable_dram_end = 0x3fce9700;
  25. bootloader_stack_overhead = 0x2000; /* For safety margin between bootloader data section and startup stacks */
  26. bootloader_dram_seg_len = 0x4000;
  27. bootloader_iram_loader_seg_len = 0x7000;
  28. bootloader_iram_seg_len = 0x3000;
  29. /* Start of the lower region is determined by region size and the end of the higher region */
  30. bootloader_dram_seg_end = bootloader_usable_dram_end - bootloader_stack_overhead;
  31. bootloader_dram_seg_start = bootloader_dram_seg_end - bootloader_dram_seg_len;
  32. bootloader_iram_loader_seg_start = bootloader_dram_seg_start - bootloader_iram_loader_seg_len + iram_dram_offset;
  33. bootloader_iram_seg_start = bootloader_iram_loader_seg_start - bootloader_iram_seg_len;
  34. MEMORY
  35. {
  36. iram_seg (RWX) : org = bootloader_iram_seg_start, len = bootloader_iram_seg_len
  37. iram_loader_seg (RWX) : org = bootloader_iram_loader_seg_start, len = bootloader_iram_loader_seg_len
  38. dram_seg (RW) : org = bootloader_dram_seg_start, len = bootloader_dram_seg_len
  39. }
  40. /* The app may use RAM for static allocations up to the start of iram_loader_seg.
  41. * If you have changed something above and this assert fails:
  42. * 1. Check what the new value of bootloader_iram_loader_seg start is.
  43. * 2. Update the value in this assert.
  44. * 3. Update SRAM_IRAM_END in components/esp_system/ld/esp32s3/memory.ld.in to the same value.
  45. */
  46. ASSERT(bootloader_iram_loader_seg_start == 0x403cc700, "bootloader_iram_loader_seg_start inconsistent with SRAM_IRAM_END");
  47. /* Default entry point: */
  48. ENTRY(call_start_cpu0);
  49. SECTIONS
  50. {
  51. .iram_loader.text :
  52. {
  53. . = ALIGN (16);
  54. _loader_text_start = ABSOLUTE(.);
  55. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  56. *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
  57. *liblog.a:(.literal .text .literal.* .text.*)
  58. *libgcc.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. *libesp_common.a:fpga_overrides.*(.literal.bootloader_fill_random .text.bootloader_fill_random)
  65. *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
  66. *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
  67. *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
  68. *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
  69. *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
  70. *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
  71. *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
  72. *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
  73. *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
  74. *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
  75. *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
  76. *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
  77. *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
  78. *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
  79. *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
  80. *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
  81. *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
  82. *libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
  83. *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
  84. *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
  85. *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
  86. *libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)
  87. *libefuse.a:*.*(.literal .text .literal.* .text.*)
  88. *(.fini.literal)
  89. *(.fini)
  90. *(.gnu.version)
  91. _loader_text_end = ABSOLUTE(.);
  92. } > iram_loader_seg
  93. .iram.text :
  94. {
  95. . = ALIGN (16);
  96. *(.entry.text)
  97. *(.init.literal)
  98. *(.init)
  99. } > iram_seg
  100. /* Shared RAM */
  101. .dram0.bss (NOLOAD) :
  102. {
  103. . = ALIGN (8);
  104. _dram_start = ABSOLUTE(.);
  105. _bss_start = ABSOLUTE(.);
  106. *(.dynsbss)
  107. *(.sbss)
  108. *(.sbss.*)
  109. *(.gnu.linkonce.sb.*)
  110. *(.scommon)
  111. *(.sbss2)
  112. *(.sbss2.*)
  113. *(.gnu.linkonce.sb2.*)
  114. *(.dynbss)
  115. *(.bss)
  116. *(.bss.*)
  117. *(.gnu.linkonce.b.*)
  118. *(COMMON)
  119. . = ALIGN (8);
  120. _bss_end = ABSOLUTE(.);
  121. } > dram_seg
  122. .dram0.data :
  123. {
  124. _data_start = ABSOLUTE(.);
  125. *(.data)
  126. *(.data.*)
  127. *(.gnu.linkonce.d.*)
  128. *(.data1)
  129. *(.sdata)
  130. *(.sdata.*)
  131. *(.gnu.linkonce.s.*)
  132. *(.gnu.linkonce.s2.*)
  133. *(.jcr)
  134. _data_end = ABSOLUTE(.);
  135. } > dram_seg
  136. .dram0.rodata :
  137. {
  138. _rodata_start = ABSOLUTE(.);
  139. *(.rodata)
  140. *(.rodata.*)
  141. *(.gnu.linkonce.r.*)
  142. *(.rodata1)
  143. *(.sdata2 .sdata2.*)
  144. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  145. *(.xt_except_table)
  146. *(.gcc_except_table)
  147. *(.gnu.linkonce.e.*)
  148. *(.gnu.version_r)
  149. *(.eh_frame)
  150. . = (. + 3) & ~ 3;
  151. /* C++ constructor and destructor tables, properly ordered: */
  152. __init_array_start = ABSOLUTE(.);
  153. KEEP (*crtbegin.*(.ctors))
  154. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  155. KEEP (*(SORT(.ctors.*)))
  156. KEEP (*(.ctors))
  157. __init_array_end = ABSOLUTE(.);
  158. KEEP (*crtbegin.*(.dtors))
  159. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  160. KEEP (*(SORT(.dtors.*)))
  161. KEEP (*(.dtors))
  162. /* C++ exception handlers table: */
  163. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  164. *(.xt_except_desc)
  165. *(.gnu.linkonce.h.*)
  166. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  167. *(.xt_except_desc_end)
  168. *(.dynamic)
  169. *(.gnu.version_d)
  170. _rodata_end = ABSOLUTE(.);
  171. /* Literals are also RO data. */
  172. _lit4_start = ABSOLUTE(.);
  173. *(*.lit4)
  174. *(.lit4.*)
  175. *(.gnu.linkonce.lit4.*)
  176. _lit4_end = ABSOLUTE(.);
  177. . = ALIGN(4);
  178. _dram_end = ABSOLUTE(.);
  179. } > dram_seg
  180. .iram.text :
  181. {
  182. _stext = .;
  183. _text_start = ABSOLUTE(.);
  184. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  185. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  186. *(.fini.literal)
  187. *(.fini)
  188. *(.gnu.version)
  189. /** CPU will try to prefetch up to 16 bytes of
  190. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  191. * safe access to up to 16 bytes after the last real instruction, add
  192. * dummy bytes to ensure this
  193. */
  194. . += 16;
  195. _text_end = ABSOLUTE(.);
  196. _etext = .;
  197. } > iram_seg
  198. /** This section will be used by the debugger and disassembler to get more information
  199. * about raw data present in the code.
  200. * Indeed, it may be required to add some padding at some points in the code
  201. * in order to align a branch/jump destination on a particular bound.
  202. * Padding these instructions will generate null bytes that shall be
  203. * interpreted as data, and not code by the debugger or disassembler.
  204. * This section will only be present in the ELF file, not in the final binary
  205. * For more details, check GCC-212
  206. */
  207. .xt.prop 0 :
  208. {
  209. KEEP (*(.xt.prop .gnu.linkonce.prop.*))
  210. }
  211. .xt.lit 0 :
  212. {
  213. KEEP (*(.xt.lit .gnu.linkonce.p.*))
  214. }
  215. }
  216. /**
  217. * Appendix: Memory Usage of ROM bootloader
  218. *
  219. * 0x3fcd7e00 ------------------> _dram0_0_start
  220. * | |
  221. * | |
  222. * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
  223. * | |
  224. * | |
  225. * 0x3fce9710 ------------------> __stack_sentry
  226. * | |
  227. * | | 2. Startup pro cpu stack (freed when IDF app is running)
  228. * | |
  229. * 0x3fceb710 ------------------> __stack (pro cpu)
  230. * | |
  231. * | | Startup app cpu stack
  232. * | |
  233. * 0x3fced710 ------------------> __stack_app (app cpu)
  234. * | |
  235. * | |
  236. * | | 3. Shared memory only used in startup code or nonos/early boot*
  237. * | | (can be freed when IDF runs)
  238. * | |
  239. * | |
  240. * 0x3fceee34 ------------------> _dram0_rtos_reserved_start
  241. * | |
  242. * | |
  243. * | | 4. Shared memory used in startup code and when IDF runs
  244. * | |
  245. * | |
  246. * 0x3fcef770 ------------------> _dram0_rtos_reserved_end
  247. * | |
  248. * 0x3fcef81c ------------------> _data_start_interface
  249. * | |
  250. * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
  251. * | |
  252. * 0x3fcf0000 ------------------> _data_end_interface
  253. */