bootloader.ld 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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-C2 ROM static data usage is as follows:
  10. * - 0x3fccb264 - 0x3fcdcb70: Shared buffers, used in UART/USB/SPI download mode only
  11. * - 0x3fcdcb70 - 0x3fcdeb70: PRO CPU stack, can be reclaimed as heap after RTOS startup
  12. * - 0x3fcdeb70 - 0x3fce0000: 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 (0x3fcdcb70).
  16. */
  17. /* The offset between Dbus and Ibus. Used to convert between 0x403xxxxx and 0x3fcxxxxx addresses. */
  18. iram_dram_offset = 0x6e0000;
  19. /* We consider 0x3fcdcb70 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 = 0x3fcdcb70;
  24. bootloader_stack_overhead = 0x2000; /* For safety margin between bootloader data section and startup stacks */
  25. bootloader_dram_seg_len = 0x5000;
  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 + iram_dram_offset;
  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. /* Default entry point: */
  40. ENTRY(call_start_cpu0);
  41. SECTIONS
  42. {
  43. .iram_loader.text :
  44. {
  45. . = ALIGN (16);
  46. _loader_text_start = ABSOLUTE(.);
  47. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  48. *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
  49. *liblog.a:(.literal .text .literal.* .text.*)
  50. *libgcc.a:(.literal .text .literal.* .text.*)
  51. *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
  52. *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
  53. *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
  54. *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
  55. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
  56. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
  57. *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
  58. *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
  59. *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
  60. *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
  61. *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
  62. *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
  63. *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
  64. *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
  65. *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
  66. *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
  67. *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
  68. *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
  69. *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
  70. *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
  71. *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
  72. *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
  73. *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
  74. *libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
  75. *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
  76. *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
  77. *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
  78. *libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)
  79. *libefuse.a:*.*(.literal .text .literal.* .text.*)
  80. *(.fini.literal)
  81. *(.fini)
  82. *(.gnu.version)
  83. _loader_text_end = ABSOLUTE(.);
  84. } > iram_loader_seg
  85. .iram.text :
  86. {
  87. . = ALIGN (16);
  88. *(.entry.text)
  89. *(.init.literal)
  90. *(.init)
  91. } > iram_seg
  92. /* Shared RAM */
  93. .dram0.bss (NOLOAD) :
  94. {
  95. . = ALIGN (8);
  96. _dram_start = ABSOLUTE(.);
  97. _bss_start = ABSOLUTE(.);
  98. *(.dynsbss)
  99. *(.sbss)
  100. *(.sbss.*)
  101. *(.gnu.linkonce.sb.*)
  102. *(.scommon)
  103. *(.sbss2)
  104. *(.sbss2.*)
  105. *(.gnu.linkonce.sb2.*)
  106. *(.dynbss)
  107. *(.bss)
  108. *(.bss.*)
  109. *(.gnu.linkonce.b.*)
  110. *(COMMON)
  111. . = ALIGN (8);
  112. _bss_end = ABSOLUTE(.);
  113. } > dram_seg
  114. .dram0.data :
  115. {
  116. _data_start = ABSOLUTE(.);
  117. *(.data)
  118. *(.data.*)
  119. *(.gnu.linkonce.d.*)
  120. *(.data1)
  121. *(.sdata)
  122. *(.sdata.*)
  123. *(.gnu.linkonce.s.*)
  124. *(.gnu.linkonce.s2.*)
  125. *(.jcr)
  126. _data_end = ABSOLUTE(.);
  127. } > dram_seg
  128. .dram0.rodata :
  129. {
  130. _rodata_start = ABSOLUTE(.);
  131. *(.rodata)
  132. *(.rodata.*)
  133. *(.gnu.linkonce.r.*)
  134. *(.rodata1)
  135. *(.sdata2 .sdata2.* .srodata .srodata.*)
  136. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  137. *(.xt_except_table)
  138. *(.gcc_except_table)
  139. *(.gnu.linkonce.e.*)
  140. *(.gnu.version_r)
  141. *(.eh_frame)
  142. . = (. + 3) & ~ 3;
  143. /* C++ constructor and destructor tables, properly ordered: */
  144. __init_array_start = ABSOLUTE(.);
  145. KEEP (*crtbegin.*(.ctors))
  146. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  147. KEEP (*(SORT(.ctors.*)))
  148. KEEP (*(.ctors))
  149. __init_array_end = ABSOLUTE(.);
  150. KEEP (*crtbegin.*(.dtors))
  151. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  152. KEEP (*(SORT(.dtors.*)))
  153. KEEP (*(.dtors))
  154. /* C++ exception handlers table: */
  155. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  156. *(.xt_except_desc)
  157. *(.gnu.linkonce.h.*)
  158. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  159. *(.xt_except_desc_end)
  160. *(.dynamic)
  161. *(.gnu.version_d)
  162. _rodata_end = ABSOLUTE(.);
  163. /* Literals are also RO data. */
  164. _lit4_start = ABSOLUTE(.);
  165. *(*.lit4)
  166. *(.lit4.*)
  167. *(.gnu.linkonce.lit4.*)
  168. _lit4_end = ABSOLUTE(.);
  169. . = ALIGN(4);
  170. _dram_end = ABSOLUTE(.);
  171. } > dram_seg
  172. .iram.text :
  173. {
  174. _stext = .;
  175. _text_start = ABSOLUTE(.);
  176. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  177. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  178. *(.fini.literal)
  179. *(.fini)
  180. *(.gnu.version)
  181. /** CPU will try to prefetch up to 16 bytes of
  182. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  183. * safe access to up to 16 bytes after the last real instruction, add
  184. * dummy bytes to ensure this
  185. */
  186. . += 16;
  187. _text_end = ABSOLUTE(.);
  188. _etext = .;
  189. } > iram_seg
  190. }
  191. /**
  192. * Appendix: Memory Usage of ROM bootloader
  193. *
  194. * 0x3fccb264 ------------------> _dram0_0_start
  195. * | |
  196. * | |
  197. * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
  198. * | |
  199. * | |
  200. * 0x3fcdcb70 ------------------> __stack_sentry
  201. * | |
  202. * | | 2. Startup pro cpu stack (freed when IDF app is running)
  203. * | |
  204. * 0x3fcdeb70 ------------------> __stack (pro cpu)
  205. * | |
  206. * | |
  207. * | | 3. Shared memory only used in startup code or nonos/early boot*
  208. * | | (can be freed when IDF runs)
  209. * | |
  210. * | |
  211. * 0x3fcdf4bc ------------------> _dram0_rtos_reserved_start
  212. * | |
  213. * | |
  214. * | | 4. Shared memory used in startup code and when IDF runs
  215. * | |
  216. * | |
  217. * 0x3fcdfa70 ------------------> _dram0_rtos_reserved_end
  218. * | |
  219. * 0x3fcdfa74 ------------------> _data_start_interface
  220. * | |
  221. * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
  222. * | |
  223. * 0x3fce0000 ------------------> _data_end_interface
  224. */