1
0

link.ld 7.4 KB

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