link.ld 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 = (2 * 1024 * 1024)
  26. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 520k
  27. SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k
  28. SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k
  29. }
  30. ENTRY(_entry_point)
  31. SECTIONS
  32. {
  33. .flash_begin : {
  34. __flash_binary_start = .;
  35. } > FLASH
  36. .text : {
  37. _stext = .;
  38. __logical_binary_start = .;
  39. KEEP (*(.vectors))
  40. KEEP (*(.binary_info_header))
  41. __binary_info_header_end = .;
  42. KEEP (*(.embedded_block))
  43. __embedded_block_end = .;
  44. KEEP (*(.reset))
  45. /* TODO revisit this now memset/memcpy/float in ROM */
  46. /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
  47. * FLASH ... we will include any thing excluded here in .data below by default */
  48. *(.init)
  49. *libgcc.a:cmse_nonsecure_call.o
  50. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
  51. *(.fini)
  52. . = ALIGN(4);
  53. /* Pull all c'tors into .text */
  54. *crtbegin.o(.ctors)
  55. *crtbegin?.o(.ctors)
  56. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  57. *(SORT(.ctors.*))
  58. *(.ctors)
  59. /* Followed by destructors */
  60. *crtbegin.o(.dtors)
  61. *crtbegin?.o(.dtors)
  62. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  63. *(SORT(.dtors.*))
  64. *(.dtors)
  65. . = ALIGN(4);
  66. /* preinit data */
  67. PROVIDE_HIDDEN (__preinit_array_start = .);
  68. KEEP(*(SORT(.preinit_array.*)))
  69. KEEP(*(.preinit_array))
  70. PROVIDE_HIDDEN (__preinit_array_end = .);
  71. . = ALIGN(4);
  72. /* init data */
  73. PROVIDE_HIDDEN (__init_array_start = .);
  74. KEEP(*(SORT(.init_array.*)))
  75. KEEP(*(.init_array))
  76. PROVIDE_HIDDEN (__init_array_end = .);
  77. . = ALIGN(4);
  78. /* finit data */
  79. PROVIDE_HIDDEN (__fini_array_start = .);
  80. *(SORT(.fini_array.*))
  81. *(.fini_array)
  82. PROVIDE_HIDDEN (__fini_array_end = .);
  83. /* section information for utest */
  84. . = ALIGN(4);
  85. __rt_utest_tc_tab_start = .;
  86. KEEP(*(UtestTcTab))
  87. __rt_utest_tc_tab_end = .;
  88. /* section information for finsh shell */
  89. . = ALIGN(4);
  90. __fsymtab_start = .;
  91. KEEP(*(FSymTab))
  92. __fsymtab_end = .;
  93. . = ALIGN(4);
  94. __vsymtab_start = .;
  95. KEEP(*(VSymTab))
  96. __vsymtab_end = .;
  97. /* section information for initial. */
  98. . = ALIGN(4);
  99. __rt_init_start = .;
  100. KEEP(*(SORT(.rti_fn*)))
  101. __rt_init_end = .;
  102. *(.eh_frame*)
  103. . = ALIGN(4);
  104. _etext = .;
  105. } > FLASH
  106. .boot2 : {
  107. __boot2_start__ = .;
  108. *(.boot2)
  109. __boot2_end__ = .;
  110. } > FLASH
  111. ASSERT(__boot2_end__ - __boot2_start__ <= 256,
  112. "ERROR: Pico second stage bootloader must be no more than 256 bytes in size")
  113. .rodata : {
  114. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
  115. *(.srodata*)
  116. . = ALIGN(4);
  117. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  118. . = ALIGN(4);
  119. } > FLASH
  120. .ARM.extab :
  121. {
  122. *(.ARM.extab* .gnu.linkonce.armextab.*)
  123. } > FLASH
  124. __exidx_start = .;
  125. .ARM.exidx :
  126. {
  127. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  128. } > FLASH
  129. __exidx_end = .;
  130. /* Machine inspectable binary information */
  131. . = ALIGN(4);
  132. __binary_info_start = .;
  133. .binary_info :
  134. {
  135. KEEP(*(.binary_info.keep.*))
  136. *(.binary_info.*)
  137. } > FLASH
  138. __binary_info_end = .;
  139. . = ALIGN(4);
  140. .ram_vector_table (NOLOAD): {
  141. *(.ram_vector_table)
  142. } > RAM
  143. .uninitialized_data (NOLOAD): {
  144. . = ALIGN(4);
  145. *(.uninitialized_data*)
  146. } > RAM
  147. .data : {
  148. __data_start__ = .;
  149. *(vtable)
  150. *(.time_critical*)
  151. /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
  152. *(.text*)
  153. . = ALIGN(4);
  154. *(.rodata*)
  155. . = ALIGN(4);
  156. *(.data*)
  157. *(.sdata*)
  158. . = ALIGN(4);
  159. *(.after_data.*)
  160. . = ALIGN(4);
  161. /* preinit data */
  162. PROVIDE_HIDDEN (__mutex_array_start = .);
  163. KEEP(*(SORT(.mutex_array.*)))
  164. KEEP(*(.mutex_array))
  165. PROVIDE_HIDDEN (__mutex_array_end = .);
  166. *(.jcr)
  167. . = ALIGN(4);
  168. } > RAM AT> FLASH
  169. /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
  170. .tdata : {
  171. . = ALIGN(4);
  172. *(.tdata .tdata.* .gnu.linkonce.td.*)
  173. /* All data end */
  174. __tdata_end = .;
  175. } > RAM AT> FLASH
  176. PROVIDE(__data_end__ = .);
  177. /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
  178. __etext = LOADADDR(.data);
  179. .tbss (NOLOAD) : {
  180. . = ALIGN(4);
  181. __bss_start__ = .;
  182. __tls_base = .;
  183. *(.tbss .tbss.* .gnu.linkonce.tb.*)
  184. *(.tcommon)
  185. __tls_end = .;
  186. } > RAM
  187. .bss (NOLOAD) : {
  188. __tbss_end = .;
  189. . = ALIGN(4);
  190. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  191. *(COMMON)
  192. PROVIDE(__global_pointer$ = . + 2K);
  193. *(.sbss*)
  194. . = ALIGN(4);
  195. __bss_end__ = .;
  196. } > RAM
  197. .heap (NOLOAD):
  198. {
  199. _sstack = .;
  200. __end__ = .;
  201. end = __end__;
  202. KEEP(*(.heap*))
  203. __HeapLimit = .;
  204. _estack = .;
  205. } > RAM
  206. /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however
  207. to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */
  208. /* Start and end symbols must be word-aligned */
  209. .scratch_x : {
  210. __scratch_x_start__ = .;
  211. *(.scratch_x.*)
  212. . = ALIGN(4);
  213. __scratch_x_end__ = .;
  214. } > SCRATCH_X AT > FLASH
  215. __scratch_x_source__ = LOADADDR(.scratch_x);
  216. .scratch_y : {
  217. __scratch_y_start__ = .;
  218. *(.scratch_y.*)
  219. . = ALIGN(4);
  220. __scratch_y_end__ = .;
  221. } > SCRATCH_Y AT > FLASH
  222. __scratch_y_source__ = LOADADDR(.scratch_y);
  223. /* .stack*_dummy section doesn't contains any symbols. It is only
  224. * used for linker to calculate size of stack sections, and assign
  225. * values to stack symbols later
  226. *
  227. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  228. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  229. * stack is not used then all of SCRATCH_X is free.
  230. */
  231. .stack1_dummy (NOLOAD):
  232. {
  233. *(.stack1*)
  234. } > SCRATCH_X
  235. .stack_dummy (NOLOAD):
  236. {
  237. KEEP(*(.stack*))
  238. } > SCRATCH_Y
  239. .flash_end : {
  240. KEEP(*(.embedded_end_block*))
  241. PROVIDE(__flash_binary_end = .);
  242. } > FLASH =0xaa
  243. /* stack limit is poorly named, but historically is maximum heap ptr */
  244. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  245. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  246. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  247. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  248. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  249. PROVIDE(__stack = __StackTop);
  250. /* Check if data + heap + stack exceeds RAM limit */
  251. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  252. ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary")
  253. ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary")
  254. /* todo assert on extra code */
  255. }