bootloader.ld 9.6 KB

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