bootloader.ld 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. Linker file used to link the bootloader.
  8. */
  9. /* Simplified memory map for the bootloader
  10. The main purpose is to make sure the bootloader can load into main memory
  11. without overwriting itself.
  12. */
  13. MEMORY
  14. {
  15. /* IRAM POOL1, used for APP CPU cache. Bootloader runs from here during the final stage of loading the app because APP CPU is still held in reset, the main app enables APP CPU cache */
  16. iram_loader_seg (RWX) : org = 0x40078000, len = 0x8000 /* 32KB, APP CPU cache */
  17. /* 63kB, IRAM. We skip the first 1k to prevent the entry point being
  18. placed into the same range as exception vectors in the app.
  19. This leads to idf_monitor decoding ROM bootloader "entry 0x40080xxx"
  20. message as one of the exception vectors, which looks scary to users.
  21. */
  22. iram_seg (RWX) : org = 0x40080400, len = 0xfc00
  23. /* 64k at the end of DRAM, after ROM bootloader stack */
  24. dram_seg (RW) : org = 0x3FFF0000, len = 0x6000
  25. }
  26. /* Default entry point: */
  27. ENTRY(call_start_cpu0);
  28. SECTIONS
  29. {
  30. .iram_loader.text :
  31. {
  32. . = ALIGN (16);
  33. _loader_text_start = ABSOLUTE(.);
  34. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  35. *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
  36. *liblog.a:(.literal .text .literal.* .text.*)
  37. /* we use either libgcc or compiler-rt, so put similar entries for them here */
  38. *libgcc.a:(.literal .text .literal.* .text.*)
  39. *libclang_rt.builtins.a:(.literal .text .literal.* .text.*)
  40. *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
  41. *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
  42. *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
  43. *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
  44. *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
  45. *libesp_common.a:fpga_overrides.*(.literal.bootloader_fill_random .text.bootloader_fill_random)
  46. *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
  47. *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
  48. *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
  49. *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
  50. *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
  51. *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
  52. *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
  53. *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
  54. *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
  55. *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
  56. *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
  57. *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
  58. *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
  59. *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
  60. *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
  61. *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
  62. *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
  63. *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
  64. *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
  65. *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
  66. *libefuse.a:*.*(.literal .text .literal.* .text.*)
  67. *libesp_rom.a:*.*(.literal .text .literal.* .text.*)
  68. *(.fini.literal)
  69. *(.fini)
  70. *(.gnu.version)
  71. _loader_text_end = ABSOLUTE(.);
  72. } > iram_loader_seg
  73. .iram.text :
  74. {
  75. . = ALIGN (16);
  76. *(.entry.text)
  77. *(.init.literal)
  78. *(.init)
  79. } > iram_seg
  80. /* Shared RAM */
  81. .dram0.bss (NOLOAD) :
  82. {
  83. . = ALIGN (8);
  84. _dram_start = ABSOLUTE(.);
  85. _bss_start = ABSOLUTE(.);
  86. *(.dynsbss)
  87. *(.sbss)
  88. *(.sbss.*)
  89. *(.gnu.linkonce.sb.*)
  90. *(.scommon)
  91. *(.sbss2)
  92. *(.sbss2.*)
  93. *(.gnu.linkonce.sb2.*)
  94. *(.dynbss)
  95. *(.bss)
  96. *(.bss.*)
  97. *(.gnu.linkonce.b.*)
  98. *(COMMON)
  99. . = ALIGN (8);
  100. _bss_end = ABSOLUTE(.);
  101. } >dram_seg
  102. .dram0.bootdesc : ALIGN(0x10)
  103. {
  104. _data_start = ABSOLUTE(.);
  105. *(.data_bootloader_desc .data_bootloader_desc.*) /* Should be the first. Bootloader version info. DO NOT PUT ANYTHING BEFORE IT! */
  106. } > dram_seg
  107. .dram0.data : ALIGN(0x10)
  108. {
  109. *(.data)
  110. *(.data.*)
  111. *(.gnu.linkonce.d.*)
  112. *(.data1)
  113. *(.sdata)
  114. *(.sdata.*)
  115. *(.gnu.linkonce.s.*)
  116. *(.gnu.linkonce.s2.*)
  117. *(.jcr)
  118. _data_end = ABSOLUTE(.);
  119. } >dram_seg
  120. .dram0.rodata :
  121. {
  122. _rodata_start = ABSOLUTE(.);
  123. *(.rodata)
  124. *(.rodata.*)
  125. *(.gnu.linkonce.r.*)
  126. *(.rodata1)
  127. *(.sdata2 .sdata2.*)
  128. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  129. *(.xt_except_table)
  130. *(.gcc_except_table)
  131. *(.gnu.linkonce.e.*)
  132. *(.gnu.version_r)
  133. *(.eh_frame)
  134. . = (. + 3) & ~ 3;
  135. /* C++ constructor and destructor tables, properly ordered: */
  136. __init_array_start = ABSOLUTE(.);
  137. KEEP (*crtbegin.*(.ctors))
  138. KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
  139. KEEP (*(SORT(.ctors.*)))
  140. KEEP (*(.ctors))
  141. __init_array_end = ABSOLUTE(.);
  142. KEEP (*crtbegin.*(.dtors))
  143. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  144. KEEP (*(SORT(.dtors.*)))
  145. KEEP (*(.dtors))
  146. /* C++ exception handlers table: */
  147. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  148. *(.xt_except_desc)
  149. *(.gnu.linkonce.h.*)
  150. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  151. *(.xt_except_desc_end)
  152. *(.dynamic)
  153. *(.gnu.version_d)
  154. _rodata_end = ABSOLUTE(.);
  155. /* Literals are also RO data. */
  156. _lit4_start = ABSOLUTE(.);
  157. *(*.lit4)
  158. *(.lit4.*)
  159. *(.gnu.linkonce.lit4.*)
  160. _lit4_end = ABSOLUTE(.);
  161. . = ALIGN(4);
  162. _dram_end = ABSOLUTE(.);
  163. } >dram_seg
  164. .iram.text :
  165. {
  166. _stext = .;
  167. _text_start = ABSOLUTE(.);
  168. *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  169. *(.iram .iram.*) /* catch stray IRAM_ATTR */
  170. *(.fini.literal)
  171. *(.fini)
  172. *(.gnu.version)
  173. /** CPU will try to prefetch up to 16 bytes of
  174. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  175. * safe access to up to 16 bytes after the last real instruction, add
  176. * dummy bytes to ensure this
  177. */
  178. . += 16;
  179. _text_end = ABSOLUTE(.);
  180. _etext = .;
  181. } > iram_seg
  182. /** This section will be used by the debugger and disassembler to get more information
  183. * about raw data present in the code.
  184. * Indeed, it may be required to add some padding at some points in the code
  185. * in order to align a branch/jump destination on a particular bound.
  186. * Padding these instructions will generate null bytes that shall be
  187. * interpreted as data, and not code by the debugger or disassembler.
  188. * This section will only be present in the ELF file, not in the final binary
  189. * For more details, check GCC-212
  190. */
  191. .xt.prop 0 :
  192. {
  193. KEEP (*(.xt.prop .gnu.linkonce.prop.*))
  194. }
  195. .xt.lit 0 :
  196. {
  197. KEEP (*(.xt.lit .gnu.linkonce.p.*))
  198. }
  199. }