bootloader.ld 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. /* we use either libgcc or compiler-rt, so put similar entries for them here */
  59. *libgcc.a:(.literal .text .literal.* .text.*)
  60. *libclang_rt.builtins.a:(.literal .text .literal.* .text.*)
  61. *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
  62. *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
  63. *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
  64. *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
  65. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
  66. *libesp_common.a:fpga_overrides.*(.literal.bootloader_fill_random .text.bootloader_fill_random)
  67. *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
  68. *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
  69. *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
  70. *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
  71. *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
  72. *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
  73. *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
  74. *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
  75. *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
  76. *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
  77. *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
  78. *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
  79. *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
  80. *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
  81. *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
  82. *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
  83. *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
  84. *libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
  85. *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
  86. *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
  87. *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
  88. *libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)
  89. *libefuse.a:*.*(.literal .text .literal.* .text.*)
  90. *(.fini.literal)
  91. *(.fini)
  92. *(.gnu.version)
  93. _loader_text_end = ABSOLUTE(.);
  94. } > iram_loader_seg
  95. .iram.text :
  96. {
  97. . = ALIGN (16);
  98. *(.entry.text)
  99. *(.init.literal)
  100. *(.init)
  101. } > iram_seg
  102. /* Shared RAM */
  103. .dram0.bss (NOLOAD) :
  104. {
  105. . = ALIGN (8);
  106. _dram_start = ABSOLUTE(.);
  107. _bss_start = ABSOLUTE(.);
  108. *(.dynsbss)
  109. *(.sbss)
  110. *(.sbss.*)
  111. *(.gnu.linkonce.sb.*)
  112. *(.scommon)
  113. *(.sbss2)
  114. *(.sbss2.*)
  115. *(.gnu.linkonce.sb2.*)
  116. *(.dynbss)
  117. *(.bss)
  118. *(.bss.*)
  119. *(.gnu.linkonce.b.*)
  120. *(COMMON)
  121. . = ALIGN (8);
  122. _bss_end = ABSOLUTE(.);
  123. } > dram_seg
  124. .dram0.bootdesc : ALIGN(0x10)
  125. {
  126. _data_start = ABSOLUTE(.);
  127. *(.data_bootloader_desc .data_bootloader_desc.*) /* Should be the first. Bootloader version info. DO NOT PUT ANYTHING BEFORE IT! */
  128. } > dram_seg
  129. .dram0.data :
  130. {
  131. *(.data)
  132. *(.data.*)
  133. *(.gnu.linkonce.d.*)
  134. *(.data1)
  135. *(.sdata)
  136. *(.sdata.*)
  137. *(.gnu.linkonce.s.*)
  138. *(.gnu.linkonce.s2.*)
  139. *(.jcr)
  140. _data_end = ABSOLUTE(.);
  141. } > dram_seg
  142. .dram0.rodata :
  143. {
  144. _rodata_start = ABSOLUTE(.);
  145. *(.rodata)
  146. *(.rodata.*)
  147. *(.gnu.linkonce.r.*)
  148. *(.rodata1)
  149. *(.sdata2 .sdata2.*)
  150. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  151. *(.xt_except_table)
  152. *(.gcc_except_table)
  153. *(.gnu.linkonce.e.*)
  154. *(.gnu.version_r)
  155. *(.eh_frame)
  156. . = (. + 3) & ~ 3;
  157. /* C++ constructor and destructor tables, properly ordered: */
  158. __init_array_start = ABSOLUTE(.);
  159. KEEP (*crtbegin.*(.ctors))
  160. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  161. KEEP (*(SORT(.ctors.*)))
  162. KEEP (*(.ctors))
  163. __init_array_end = ABSOLUTE(.);
  164. KEEP (*crtbegin.*(.dtors))
  165. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  166. KEEP (*(SORT(.dtors.*)))
  167. KEEP (*(.dtors))
  168. /* C++ exception handlers table: */
  169. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  170. *(.xt_except_desc)
  171. *(.gnu.linkonce.h.*)
  172. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  173. *(.xt_except_desc_end)
  174. *(.dynamic)
  175. *(.gnu.version_d)
  176. _rodata_end = ABSOLUTE(.);
  177. /* Literals are also RO data. */
  178. _lit4_start = ABSOLUTE(.);
  179. *(*.lit4)
  180. *(.lit4.*)
  181. *(.gnu.linkonce.lit4.*)
  182. _lit4_end = ABSOLUTE(.);
  183. . = ALIGN(4);
  184. _dram_end = ABSOLUTE(.);
  185. } > dram_seg
  186. .iram.text :
  187. {
  188. _stext = .;
  189. _text_start = ABSOLUTE(.);
  190. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  191. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  192. *(.fini.literal)
  193. *(.fini)
  194. *(.gnu.version)
  195. /** CPU will try to prefetch up to 16 bytes of
  196. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  197. * safe access to up to 16 bytes after the last real instruction, add
  198. * dummy bytes to ensure this
  199. */
  200. . += 16;
  201. _text_end = ABSOLUTE(.);
  202. _etext = .;
  203. } > iram_seg
  204. /** This section will be used by the debugger and disassembler to get more information
  205. * about raw data present in the code.
  206. * Indeed, it may be required to add some padding at some points in the code
  207. * in order to align a branch/jump destination on a particular bound.
  208. * Padding these instructions will generate null bytes that shall be
  209. * interpreted as data, and not code by the debugger or disassembler.
  210. * This section will only be present in the ELF file, not in the final binary
  211. * For more details, check GCC-212
  212. */
  213. .xt.prop 0 :
  214. {
  215. KEEP (*(.xt.prop .gnu.linkonce.prop.*))
  216. }
  217. .xt.lit 0 :
  218. {
  219. KEEP (*(.xt.lit .gnu.linkonce.p.*))
  220. }
  221. }
  222. /**
  223. * Appendix: Memory Usage of ROM bootloader
  224. *
  225. * 0x3fcd7e00 ------------------> _dram0_0_start
  226. * | |
  227. * | |
  228. * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
  229. * | |
  230. * | |
  231. * 0x3fce9710 ------------------> __stack_sentry
  232. * | |
  233. * | | 2. Startup pro cpu stack (freed when IDF app is running)
  234. * | |
  235. * 0x3fceb710 ------------------> __stack (pro cpu)
  236. * | |
  237. * | | Startup app cpu stack
  238. * | |
  239. * 0x3fced710 ------------------> __stack_app (app cpu)
  240. * | |
  241. * | |
  242. * | | 3. Shared memory only used in startup code or nonos/early boot*
  243. * | | (can be freed when IDF runs)
  244. * | |
  245. * | |
  246. * 0x3fceee34 ------------------> _dram0_rtos_reserved_start
  247. * | |
  248. * | |
  249. * | | 4. Shared memory used in startup code and when IDF runs
  250. * | |
  251. * | |
  252. * 0x3fcef770 ------------------> _dram0_rtos_reserved_end
  253. * | |
  254. * 0x3fcef81c ------------------> _data_start_interface
  255. * | |
  256. * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
  257. * | |
  258. * 0x3fcf0000 ------------------> _data_end_interface
  259. */