sections.ld.in 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /* Default entry point */
  7. ENTRY(call_start_cpu0);
  8. _diram_i_start = 0x40378000;
  9. SECTIONS
  10. {
  11. /**
  12. * RTC fast memory holds RTC wake stub code,
  13. * including from any source file named rtc_wake_stub*.c
  14. */
  15. .rtc.text :
  16. {
  17. . = ALIGN(4);
  18. _rtc_fast_start = ABSOLUTE(.);
  19. _rtc_text_start = ABSOLUTE(.);
  20. *(.rtc.entry.text)
  21. mapping[rtc_text]
  22. *rtc_wake_stub*.*(.literal .text .literal.* .text.*)
  23. *(.rtc_text_end_test)
  24. /* 16B padding for possible CPU prefetch and 4B alignment for PMS split lines */
  25. . += _esp_memprot_prefetch_pad_size;
  26. . = ALIGN(4);
  27. _rtc_text_end = ABSOLUTE(.);
  28. } > rtc_iram_seg
  29. /**
  30. * This section located in RTC FAST Memory area.
  31. * It holds data marked with RTC_FAST_ATTR attribute.
  32. * See the file "esp_attr.h" for more information.
  33. */
  34. .rtc.force_fast :
  35. {
  36. . = ALIGN(4);
  37. _rtc_force_fast_start = ABSOLUTE(.);
  38. mapping[rtc_force_fast]
  39. *(.rtc.force_fast .rtc.force_fast.*)
  40. . = ALIGN(4) ;
  41. _rtc_force_fast_end = ABSOLUTE(.);
  42. } > rtc_data_seg
  43. /**
  44. * RTC data section holds RTC wake stub
  45. * data/rodata, including from any source file
  46. * named rtc_wake_stub*.c and the data marked with
  47. * RTC_DATA_ATTR, RTC_RODATA_ATTR attributes.
  48. * The memory location of the data is dependent on
  49. * CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM option.
  50. */
  51. .rtc.data :
  52. {
  53. _rtc_data_start = ABSOLUTE(.);
  54. mapping[rtc_data]
  55. *rtc_wake_stub*.*(.data .rodata .data.* .rodata.*)
  56. _rtc_data_end = ABSOLUTE(.);
  57. } > rtc_data_location
  58. /* RTC bss, from any source file named rtc_wake_stub*.c */
  59. .rtc.bss (NOLOAD) :
  60. {
  61. _rtc_bss_start = ABSOLUTE(.);
  62. *rtc_wake_stub*.*(.bss .bss.*)
  63. *rtc_wake_stub*.*(COMMON)
  64. mapping[rtc_bss]
  65. _rtc_bss_end = ABSOLUTE(.);
  66. } > rtc_data_location
  67. /**
  68. * This section holds data that should not be initialized at power up
  69. * and will be retained during deep sleep.
  70. * User data marked with RTC_NOINIT_ATTR will be placed
  71. * into this section. See the file "esp_attr.h" for more information.
  72. * The memory location of the data is dependent on CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM option.
  73. */
  74. .rtc_noinit (NOLOAD):
  75. {
  76. . = ALIGN(4);
  77. _rtc_noinit_start = ABSOLUTE(.);
  78. *(.rtc_noinit .rtc_noinit.*)
  79. . = ALIGN(4) ;
  80. _rtc_noinit_end = ABSOLUTE(.);
  81. } > rtc_data_location
  82. /**
  83. * This section located in RTC SLOW Memory area.
  84. * It holds data marked with RTC_SLOW_ATTR attribute.
  85. * See the file "esp_attr.h" for more information.
  86. */
  87. .rtc.force_slow :
  88. {
  89. . = ALIGN(4);
  90. _rtc_force_slow_start = ABSOLUTE(.);
  91. *(.rtc.force_slow .rtc.force_slow.*)
  92. . = ALIGN(4) ;
  93. _rtc_force_slow_end = ABSOLUTE(.);
  94. } > rtc_slow_seg
  95. /**
  96. * This section holds RTC data that should have fixed addresses.
  97. * The data are not initialized at power-up and are retained during deep sleep.
  98. */
  99. .rtc_reserved (NOLOAD):
  100. {
  101. . = ALIGN(4);
  102. _rtc_reserved_start = ABSOLUTE(.);
  103. /* New data can only be added here to ensure existing data are not moved.
  104. Because data have adhered to the end of the segment and code is relied on it.
  105. >> put new data here << */
  106. *(.rtc_timer_data_in_rtc_mem .rtc_timer_data_in_rtc_mem.*)
  107. KEEP(*(.bootloader_data_rtc_mem .bootloader_data_rtc_mem.*))
  108. _rtc_reserved_end = ABSOLUTE(.);
  109. } > rtc_reserved_seg
  110. _rtc_reserved_length = _rtc_reserved_end - _rtc_reserved_start;
  111. ASSERT((_rtc_reserved_length <= LENGTH(rtc_reserved_seg)),
  112. "RTC reserved segment data does not fit.")
  113. /* Get size of rtc slow data based on rtc_data_location alias */
  114. _rtc_slow_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  115. ? (_rtc_force_slow_end - _rtc_data_start)
  116. : (_rtc_force_slow_end - _rtc_force_slow_start);
  117. _rtc_fast_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  118. ? (_rtc_force_fast_end - _rtc_fast_start)
  119. : (_rtc_noinit_end - _rtc_fast_start);
  120. ASSERT((_rtc_slow_length <= LENGTH(rtc_slow_seg)),
  121. "RTC_SLOW segment data does not fit.")
  122. ASSERT((_rtc_fast_length <= LENGTH(rtc_data_seg)),
  123. "RTC_FAST segment data does not fit.")
  124. /* Send .iram0 code to iram */
  125. .iram0.vectors :
  126. {
  127. _iram_start = ABSOLUTE(.);
  128. /* Vectors go to IRAM */
  129. _vector_table = ABSOLUTE(.);
  130. . = 0x0;
  131. KEEP(*(.WindowVectors.text));
  132. . = 0x180;
  133. KEEP(*(.Level2InterruptVector.text));
  134. . = 0x1c0;
  135. KEEP(*(.Level3InterruptVector.text));
  136. . = 0x200;
  137. KEEP(*(.Level4InterruptVector.text));
  138. . = 0x240;
  139. KEEP(*(.Level5InterruptVector.text));
  140. . = 0x280;
  141. KEEP(*(.DebugExceptionVector.text));
  142. . = 0x2c0;
  143. KEEP(*(.NMIExceptionVector.text));
  144. . = 0x300;
  145. KEEP(*(.KernelExceptionVector.text));
  146. . = 0x340;
  147. KEEP(*(.UserExceptionVector.text));
  148. . = 0x3C0;
  149. KEEP(*(.DoubleExceptionVector.text));
  150. . = 0x400;
  151. _invalid_pc_placeholder = ABSOLUTE(.);
  152. *(.*Vector.literal)
  153. *(.UserEnter.literal);
  154. *(.UserEnter.text);
  155. . = ALIGN (16);
  156. *(.entry.text)
  157. *(.init.literal)
  158. *(.init)
  159. _init_end = ABSOLUTE(.);
  160. } > iram0_0_seg
  161. .iram0.text :
  162. {
  163. /* Code marked as running out of IRAM */
  164. _iram_text_start = ABSOLUTE(.);
  165. mapping[iram0_text]
  166. } > iram0_0_seg
  167. /**
  168. * This section is required to skip .iram0.text area because iram0_0_seg and
  169. * dram0_0_seg reflect the same address space on different buses.
  170. */
  171. .dram0.dummy (NOLOAD):
  172. {
  173. . = ORIGIN(dram0_0_seg) + MAX(_iram_end - _diram_i_start, 0);
  174. } > dram0_0_seg
  175. .dram0.data :
  176. {
  177. _data_start = ABSOLUTE(.);
  178. *(.gnu.linkonce.d.*)
  179. *(.data1)
  180. *(.sdata)
  181. *(.sdata.*)
  182. *(.gnu.linkonce.s.*)
  183. *(.gnu.linkonce.s2.*)
  184. *(.jcr)
  185. mapping[dram0_data]
  186. _data_end = ABSOLUTE(.);
  187. . = ALIGN(4);
  188. } > dram0_0_seg
  189. /**
  190. * This section holds data that should not be initialized at power up.
  191. * The section located in Internal SRAM memory region. The macro _NOINIT
  192. * can be used as attribute to place data into this section.
  193. * See the "esp_attr.h" file for more information.
  194. */
  195. .noinit (NOLOAD):
  196. {
  197. . = ALIGN(4);
  198. _noinit_start = ABSOLUTE(.);
  199. *(.noinit .noinit.*)
  200. . = ALIGN(4) ;
  201. _noinit_end = ABSOLUTE(.);
  202. } > dram0_0_seg
  203. /* Shared RAM */
  204. .dram0.bss (NOLOAD) :
  205. {
  206. . = ALIGN (8);
  207. _bss_start = ABSOLUTE(.);
  208. mapping[dram0_bss]
  209. *(.dynsbss)
  210. *(.sbss)
  211. *(.sbss.*)
  212. *(.gnu.linkonce.sb.*)
  213. *(.scommon)
  214. *(.sbss2)
  215. *(.sbss2.*)
  216. *(.gnu.linkonce.sb2.*)
  217. *(.dynbss)
  218. *(.share.mem)
  219. *(.gnu.linkonce.b.*)
  220. . = ALIGN (8);
  221. _bss_end = ABSOLUTE(.);
  222. } > dram0_0_seg
  223. ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.")
  224. .flash.text :
  225. {
  226. _stext = .;
  227. _instruction_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.text start, this can be used for mmu driver to maintain virtual address */
  228. _text_start = ABSOLUTE(.);
  229. mapping[flash_text]
  230. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  231. *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
  232. *(.fini.literal)
  233. *(.fini)
  234. *(.gnu.version)
  235. /** CPU will try to prefetch up to 16 bytes of
  236. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  237. * safe access to up to 16 bytes after the last real instruction, add
  238. * dummy bytes to ensure this
  239. */
  240. . += _esp_flash_mmap_prefetch_pad_size;
  241. _text_end = ABSOLUTE(.);
  242. _instruction_reserved_end = ABSOLUTE(.); /* This is a symbol marking the flash.text end, this can be used for mmu driver to maintain virtual address */
  243. _etext = .;
  244. /**
  245. * Similar to _iram_start, this symbol goes here so it is
  246. * resolved by addr2line in preference to the first symbol in
  247. * the flash.text segment.
  248. */
  249. _flash_cache_start = ABSOLUTE(0);
  250. } > default_code_seg
  251. /**
  252. * This dummy section represents the .flash.text section but in default_rodata_seg.
  253. * Thus, it must have its alignment and (at least) its size.
  254. */
  255. .flash_rodata_dummy (NOLOAD):
  256. {
  257. _flash_rodata_dummy_start = ABSOLUTE(.);
  258. /* Start at the same alignment constraint than .flash.text */
  259. . = ALIGN(ALIGNOF(.flash.text));
  260. /* Create an empty gap as big as .flash.text section */
  261. . = . + SIZEOF(.flash.text);
  262. /* Prepare the alignment of the section above. Few bytes (0x20) must be
  263. * added for the mapping header. */
  264. . = ALIGN(_esp_mmu_block_size) + 0x20;
  265. } > default_rodata_seg
  266. .flash.appdesc : ALIGN(0x10)
  267. {
  268. _rodata_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.rodata start, this can be used for mmu driver to maintain virtual address */
  269. _rodata_start = ABSOLUTE(.);
  270. *(.rodata_desc .rodata_desc.*) /* Should be the first. App version info. DO NOT PUT ANYTHING BEFORE IT! */
  271. *(.rodata_custom_desc .rodata_custom_desc.*) /* Should be the second. Custom app version info. DO NOT PUT ANYTHING BEFORE IT! */
  272. /* Create an empty gap within this section. Thanks to this, the end of this
  273. * section will match .flah.rodata's begin address. Thus, both sections
  274. * will be merged when creating the final bin image. */
  275. . = ALIGN(ALIGNOF(.flash.rodata));
  276. } >default_rodata_seg
  277. .flash.rodata : ALIGN(0x10)
  278. {
  279. _flash_rodata_start = ABSOLUTE(.);
  280. mapping[flash_rodata]
  281. *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
  282. *(.gnu.linkonce.r.*)
  283. *(.rodata1)
  284. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  285. *(.xt_except_table)
  286. *(.gcc_except_table .gcc_except_table.*)
  287. *(.gnu.linkonce.e.*)
  288. *(.gnu.version_r)
  289. . = (. + 3) & ~ 3;
  290. __eh_frame = ABSOLUTE(.);
  291. KEEP(*(.eh_frame))
  292. . = (. + 7) & ~ 3;
  293. /* C++ constructor and destructor tables */
  294. /* Don't include anything from crtbegin.o or crtend.o, as IDF doesn't use toolchain crt */
  295. __init_array_start = ABSOLUTE(.);
  296. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors SORT(.ctors.*)))
  297. __init_array_end = ABSOLUTE(.);
  298. KEEP (*crtbegin.*(.dtors))
  299. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  300. KEEP (*(SORT(.dtors.*)))
  301. KEEP (*(.dtors))
  302. /* C++ exception handlers table: */
  303. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  304. *(.xt_except_desc)
  305. *(.gnu.linkonce.h.*)
  306. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  307. *(.xt_except_desc_end)
  308. *(.dynamic)
  309. *(.gnu.version_d)
  310. /* Addresses of memory regions reserved via SOC_RESERVE_MEMORY_REGION() */
  311. soc_reserved_memory_region_start = ABSOLUTE(.);
  312. KEEP (*(.reserved_memory_address))
  313. soc_reserved_memory_region_end = ABSOLUTE(.);
  314. /* System init functions registered via ESP_SYSTEM_INIT_FN */
  315. _esp_system_init_fn_array_start = ABSOLUTE(.);
  316. KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
  317. _esp_system_init_fn_array_end = ABSOLUTE(.);
  318. _rodata_end = ABSOLUTE(.);
  319. /* Literals are also RO data. */
  320. _lit4_start = ABSOLUTE(.);
  321. *(*.lit4)
  322. *(.lit4.*)
  323. *(.gnu.linkonce.lit4.*)
  324. _lit4_end = ABSOLUTE(.);
  325. . = ALIGN(4);
  326. _thread_local_start = ABSOLUTE(.);
  327. *(.tdata)
  328. *(.tdata.*)
  329. *(.tbss)
  330. *(.tbss.*)
  331. _thread_local_end = ABSOLUTE(.);
  332. . = ALIGN(4);
  333. } > default_rodata_seg
  334. _flash_rodata_align = ALIGNOF(.flash.rodata);
  335. /*
  336. This section is a place where we dump all the rodata which aren't used at runtime,
  337. so as to avoid binary size increase
  338. */
  339. .flash.rodata_noload (NOLOAD) :
  340. {
  341. /*
  342. This is a symbol marking the flash.rodata end, this can be used for mmu driver to maintain virtual address
  343. We don't need to include the noload rodata in this section
  344. */
  345. _rodata_reserved_end = ABSOLUTE(.);
  346. . = ALIGN (4);
  347. mapping[rodata_noload]
  348. } > default_rodata_seg
  349. /**
  350. * This section is required to skip flash rodata sections, because `extern_ram_seg`
  351. * and `drom0_0_seg` are on the same bus
  352. */
  353. .ext_ram.dummy (NOLOAD):
  354. {
  355. . = ORIGIN(extern_ram_seg) + (_rodata_reserved_end - _flash_rodata_dummy_start);
  356. . = ALIGN (0x10000);
  357. } > extern_ram_seg
  358. /* This section holds .ext_ram.bss data, and will be put in PSRAM */
  359. .ext_ram.bss (NOLOAD) :
  360. {
  361. _ext_ram_bss_start = ABSOLUTE(.);
  362. mapping[extern_ram]
  363. . = ALIGN(4);
  364. _ext_ram_bss_end = ABSOLUTE(.);
  365. } > extern_ram_seg
  366. /* Marks the end of IRAM code segment */
  367. .iram0.text_end (NOLOAD) :
  368. {
  369. /* iram_end_test section exists for use by memprot unit tests only */
  370. *(.iram_end_test)
  371. /* ESP32-S3 memprot requires 16B padding for possible CPU prefetch and 256B alignment for PMS split lines */
  372. . += _esp_memprot_prefetch_pad_size;
  373. . = ALIGN(_esp_memprot_align_size);
  374. _iram_text_end = ABSOLUTE(.);
  375. } > iram0_0_seg
  376. .iram0.data :
  377. {
  378. . = ALIGN(4);
  379. _iram_data_start = ABSOLUTE(.);
  380. mapping[iram0_data]
  381. _iram_data_end = ABSOLUTE(.);
  382. } > iram0_0_seg
  383. .iram0.bss (NOLOAD) :
  384. {
  385. . = ALIGN(4);
  386. _iram_bss_start = ABSOLUTE(.);
  387. mapping[iram0_bss]
  388. _iram_bss_end = ABSOLUTE(.);
  389. . = ALIGN(4);
  390. _iram_end = ABSOLUTE(.);
  391. } > iram0_0_seg
  392. /* Marks the end of data, bss and possibly rodata */
  393. .dram0.heap_start (NOLOAD) :
  394. {
  395. . = ALIGN (8);
  396. /* Lowest possible start address for the heap */
  397. _heap_low_start = ABSOLUTE(.);
  398. } > dram0_0_seg
  399. /** This section will be used by the debugger and disassembler to get more information
  400. * about raw data present in the code.
  401. * Indeed, it may be required to add some padding at some points in the code
  402. * in order to align a branch/jump destination on a particular bound.
  403. * Padding these instructions will generate null bytes that shall be
  404. * interpreted as data, and not code by the debugger or disassembler.
  405. * This section will only be present in the ELF file, not in the final binary
  406. * For more details, check GCC-212
  407. */
  408. .xt.prop 0 :
  409. {
  410. KEEP (*(.xt.prop .gnu.linkonce.prop.*))
  411. }
  412. .xt.lit 0 :
  413. {
  414. KEEP (*(.xt.lit .gnu.linkonce.p.*))
  415. }
  416. }
  417. ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
  418. "IRAM0 segment data does not fit.")
  419. ASSERT(((_heap_low_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
  420. "DRAM segment data does not fit.")