rp23xx-template.ld 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* Based on GCC ARM embedded samples.
  2. Defines the following symbols for use by code:
  3. __exidx_start
  4. __exidx_end
  5. __etext
  6. __data_start__
  7. __preinit_array_start
  8. __preinit_array_end
  9. __init_array_start
  10. __init_array_end
  11. __fini_array_start
  12. __fini_array_end
  13. __data_end__
  14. __bss_start__
  15. __bss_end__
  16. __end__
  17. end
  18. __HeapLimit
  19. __StackLimit
  20. __StackTop
  21. __stack (== StackTop)
  22. */
  23. MEMORY
  24. {
  25. FLASH(rx) : ORIGIN = 0x10000000, LENGTH = $program_size
  26. PSRAM(rwx) : ORIGIN = 0x11000000, LENGTH = 0
  27. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k /* Leave space for pico-debug */
  28. SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k
  29. SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k
  30. }
  31. PROVIDE ( _EEPROM_start = __EEPROM_START__ );
  32. PROVIDE ( _FS_start = __FS_START__ );
  33. PROVIDE ( _FS_end = __FS_END__ );
  34. ENTRY(_entry_point)
  35. SECTIONS
  36. {
  37. .flash_begin : {
  38. __flash_binary_start = .;
  39. } > FLASH
  40. /* The bootrom will enter the image at the point indicated in your
  41. IMAGE_DEF, which is usually the reset handler of your vector table.
  42. The debugger will use the ELF entry point, which is the _entry_point
  43. symbol, and in our case is *different from the bootrom's entry point.*
  44. This is used to go back through the bootrom on debugger launches only,
  45. to perform the same initial flash setup that would be performed on a
  46. cold boot.
  47. */
  48. /* If BlueSCSI SD card bootloader is included, it goes in first 128 kB */
  49. .text.bootloader : ALIGN(16) SUBALIGN(16)
  50. {
  51. KEEP(*(.text.btldr*))
  52. . = ALIGN(131072);
  53. CHECK_BOOTLOADER_SIZE = 1 / (. <= 131072);
  54. } > FLASH
  55. .text : {
  56. __logical_binary_start = .;
  57. KEEP (*(.vectors))
  58. KEEP (*(.binary_info_header))
  59. __binary_info_header_end = .;
  60. KEEP (*(.embedded_block))
  61. __embedded_block_end = .;
  62. KEEP (*(.reset))
  63. /* TODO revisit this now memset/memcpy/float in ROM */
  64. /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
  65. * FLASH ... we will include any thing excluded here in .data below by default */
  66. *(.init)
  67. *libgcc.a:cmse_nonsecure_call.o
  68. /* =============================================================== */
  69. /* Exclude as much code from flash as possible as the RP2350 series has twice as much SRAM */
  70. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a: *libBlueIDE_platform_RPMCU.a: *libSdFat.a: *libSCSI2SD.a: *CUEParser.a: *minIni.a: *.cpp.o) .text*)
  71. /* ---------------------------------------------------------
  72. Uncomment the EXCLUDE_FILE line below and comment the EXCLUDE_FILE line above for debug to work properly,
  73. the initial break point to main seems to get clobbered when everything is in SRAM.
  74. You may have to delete the "firmware.elf" file so the next build links with newly modified linker script
  75. Alternatively, use "hbreak" in gdb to force hardware
  76. breakpoints instead of RAM breakpoints.
  77. ------------------------------------------------------------*/
  78. /* *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) */
  79. /* =============================================================== */
  80. *(.fini)
  81. /* Pull all c'tors into .text */
  82. *crtbegin.o(.ctors)
  83. *crtbegin?.o(.ctors)
  84. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  85. *(SORT(.ctors.*))
  86. *(.ctors)
  87. /* Followed by destructors */
  88. *crtbegin.o(.dtors)
  89. *crtbegin?.o(.dtors)
  90. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  91. *(SORT(.dtors.*))
  92. *(.dtors)
  93. . = ALIGN(4);
  94. /* preinit data */
  95. PROVIDE_HIDDEN (__preinit_array_start = .);
  96. KEEP(*(SORT(.preinit_array.*)))
  97. KEEP(*(.preinit_array))
  98. PROVIDE_HIDDEN (__preinit_array_end = .);
  99. . = ALIGN(4);
  100. /* init data */
  101. PROVIDE_HIDDEN (__init_array_start = .);
  102. KEEP(*(SORT(.init_array.*)))
  103. KEEP(*(.init_array))
  104. PROVIDE_HIDDEN (__init_array_end = .);
  105. . = ALIGN(4);
  106. /* finit data */
  107. PROVIDE_HIDDEN (__fini_array_start = .);
  108. *(SORT(.fini_array.*))
  109. *(.fini_array)
  110. PROVIDE_HIDDEN (__fini_array_end = .);
  111. *(.eh_frame*)
  112. . = ALIGN(4);
  113. } > FLASH
  114. /* Note the boot2 section is optional, and should be discarded if there is
  115. no reference to it *inside* the binary, as it is not called by the
  116. bootrom. (The bootrom performs a simple best-effort XIP setup and
  117. leaves it to the binary to do anything more sophisticated.) However
  118. there is still a size limit of 256 bytes, to ensure the boot2 can be
  119. stored in boot RAM.
  120. Really this is a "XIP setup function" -- the name boot2 is historic and
  121. refers to its dual-purpose on RP2040, where it also handled vectoring
  122. from the bootrom into the user image.
  123. */
  124. .boot2 : {
  125. __boot2_start__ = .;
  126. *(.boot2)
  127. __boot2_end__ = .;
  128. } > FLASH
  129. ASSERT(__boot2_end__ - __boot2_start__ <= 256,
  130. "ERROR: Pico second stage bootloader must be no more than 256 bytes in size")
  131. .rodata : {
  132. /* Exclude as many constants as possible from flash as corresponding to the code that has been removed from flash
  133. to keep the MCU from having to hit flash while it is executing in SRAM */
  134. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a: *libBlueIDE_platform_RPMCU.a: *libSdFat.a: *libSCSI2SD.a: *CUEParser.a: *minIni.a: *.cpp.o) .rodata*)
  135. /* Uncomment below and comment above lines for debugging */
  136. /* *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) */
  137. *(.srodata*)
  138. . = ALIGN(4);
  139. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  140. . = ALIGN(4);
  141. } > FLASH
  142. .ARM.extab :
  143. {
  144. *(.ARM.extab* .gnu.linkonce.armextab.*)
  145. } > FLASH
  146. __exidx_start = .;
  147. .ARM.exidx :
  148. {
  149. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  150. } > FLASH
  151. __exidx_end = .;
  152. /* Machine inspectable binary information */
  153. . = ALIGN(4);
  154. __binary_info_start = .;
  155. .binary_info :
  156. {
  157. KEEP(*(.binary_info.keep.*))
  158. *(.binary_info.*)
  159. } > FLASH
  160. __binary_info_end = .;
  161. . = ALIGN(4);
  162. .ram_vector_table (COPY): {
  163. *(.ram_vector_table)
  164. } > RAM
  165. .uninitialized_data (COPY): {
  166. . = ALIGN(4);
  167. *(.uninitialized_data*)
  168. } > RAM
  169. .data : {
  170. __data_start__ = .;
  171. *(vtable)
  172. *(.time_critical*)
  173. . = ALIGN(4);
  174. /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
  175. *(.text)
  176. *(.text*)
  177. . = ALIGN(4);
  178. *(.rodata*)
  179. . = ALIGN(4);
  180. *(.data*)
  181. . = ALIGN(4);
  182. *(.sdata*)
  183. . = ALIGN(4);
  184. *(.after_data.*)
  185. . = ALIGN(4);
  186. /* preinit data */
  187. PROVIDE_HIDDEN (__mutex_array_start = .);
  188. KEEP(*(SORT(.mutex_array.*)))
  189. KEEP(*(.mutex_array))
  190. PROVIDE_HIDDEN (__mutex_array_end = .);
  191. *(.jcr)
  192. . = ALIGN(4);
  193. } > RAM AT> FLASH
  194. .tdata : {
  195. . = ALIGN(4);
  196. *(.tdata .tdata.* .gnu.linkonce.td.*)
  197. /* All data end */
  198. __tdata_end = .;
  199. } > RAM AT> FLASH
  200. PROVIDE(__data_end__ = .);
  201. /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
  202. __etext = LOADADDR(.data);
  203. .tbss (NOLOAD) : {
  204. . = ALIGN(4);
  205. __bss_start__ = .;
  206. __tls_base = .;
  207. *(.tbss .tbss.* .gnu.linkonce.tb.*)
  208. *(.tcommon)
  209. __tls_end = .;
  210. } > RAM
  211. .bss (NOLOAD) : {
  212. . = ALIGN(4);
  213. __tbss_end = .;
  214. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  215. *(COMMON)
  216. /* Python template escaping dollar sign with two dollar signs */
  217. PROVIDE(__global_pointer$$ = . + 2K);
  218. *(.sbss*)
  219. . = ALIGN(4);
  220. __bss_end__ = .;
  221. } > RAM
  222. .heap (NOLOAD):
  223. {
  224. __end__ = .;
  225. end = __end__;
  226. KEEP(*(.heap*))
  227. /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however
  228. to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */
  229. . = ORIGIN(RAM) + LENGTH(RAM);
  230. __HeapLimit = .;
  231. } > RAM
  232. /* Start and end symbols must be word-aligned */
  233. .scratch_x : {
  234. __scratch_x_start__ = .;
  235. *(.scratch_x.*)
  236. . = ALIGN(4);
  237. __scratch_x_end__ = .;
  238. } > SCRATCH_X AT > FLASH
  239. __scratch_x_source__ = LOADADDR(.scratch_x);
  240. .scratch_y : {
  241. __scratch_y_start__ = .;
  242. *(.scratch_y.*)
  243. . = ALIGN(4);
  244. __scratch_y_end__ = .;
  245. } > SCRATCH_Y AT > FLASH
  246. __scratch_y_source__ = LOADADDR(.scratch_y);
  247. /* .stack*_dummy section doesn't contains any symbols. It is only
  248. * used for linker to calculate size of stack sections, and assign
  249. * values to stack symbols later
  250. *
  251. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  252. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  253. * stack is not used then all of SCRATCH_X is free.
  254. */
  255. .stack1_dummy (NOLOAD):
  256. {
  257. *(.stack1*)
  258. } > SCRATCH_X
  259. .stack_dummy (NOLOAD):
  260. {
  261. KEEP(*(.stack*))
  262. } > SCRATCH_Y
  263. .flash_end : {
  264. KEEP(*(.embedded_end_block*))
  265. PROVIDE(__flash_binary_end = .);
  266. } > FLASH =0xaa
  267. .psram (NOLOAD) : {
  268. __psram_start__ = .;
  269. *(.psram*)
  270. . = ALIGN(4096);
  271. __psram_heap_start__ = .;
  272. } > PSRAM
  273. /* stack limit is poorly named, but historically is maximum heap ptr */
  274. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  275. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  276. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  277. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  278. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  279. PROVIDE(__stack = __StackTop);
  280. /* picolibc and LLVM */
  281. PROVIDE (__heap_start = __end__);
  282. PROVIDE (__heap_end = __HeapLimit);
  283. PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );
  284. PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1));
  285. PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );
  286. /* TLSF */
  287. PROVIDE (__psram_start = __psram_start__);
  288. PROVIDE (__psram_heap_start = __psram_heap_start__);
  289. /* llvm-libc */
  290. PROVIDE (_end = __end__);
  291. PROVIDE (__llvm_libc_heap_limit = __HeapLimit);
  292. /* Check if data + heap + stack exceeds RAM limit */
  293. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  294. ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary")
  295. ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary")
  296. /* todo assert on extra code */
  297. }