link.ld 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 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. __reset_start = .;
  55. KEEP (*(.reset))
  56. . = ALIGN(256);
  57. __reset_end = .;
  58. ASSERT(__reset_end - __reset_start == 256, "ERROR: reset section should only be 256 bytes");
  59. KEEP (*(.vectors))
  60. /* TODO revisit this now memset/memcpy/float in ROM */
  61. /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
  62. * FLASH ... we will include any thing excluded here in .data below by default */
  63. *(.init)
  64. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
  65. *(.fini)
  66. /* section information for finsh shell */
  67. . = ALIGN(4);
  68. __fsymtab_start = .;
  69. KEEP(*(FSymTab))
  70. __fsymtab_end = .;
  71. . = ALIGN(4);
  72. __vsymtab_start = .;
  73. KEEP(*(VSymTab))
  74. __vsymtab_end = .;
  75. /* section information for initial. */
  76. . = ALIGN(4);
  77. __rt_init_start = .;
  78. KEEP(*(SORT(.rti_fn*)))
  79. __rt_init_end = .;
  80. /* Pull all c'tors into .text */
  81. *crtbegin.o(.ctors)
  82. *crtbegin?.o(.ctors)
  83. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  84. *(SORT(.ctors.*))
  85. *(.ctors)
  86. /* Followed by destructors */
  87. *crtbegin.o(.dtors)
  88. *crtbegin?.o(.dtors)
  89. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  90. *(SORT(.dtors.*))
  91. *(.dtors)
  92. *(.eh_frame*)
  93. . = ALIGN(4);
  94. } > FLASH
  95. .rodata : {
  96. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
  97. . = ALIGN(4);
  98. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  99. . = ALIGN(4);
  100. } > FLASH
  101. .ARM.extab :
  102. {
  103. *(.ARM.extab* .gnu.linkonce.armextab.*)
  104. } > FLASH
  105. __exidx_start = .;
  106. .ARM.exidx :
  107. {
  108. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  109. } > FLASH
  110. __exidx_end = .;
  111. /* Machine inspectable binary information */
  112. . = ALIGN(4);
  113. __binary_info_start = .;
  114. .binary_info :
  115. {
  116. KEEP(*(.binary_info.keep.*))
  117. *(.binary_info.*)
  118. } > FLASH
  119. __binary_info_end = .;
  120. . = ALIGN(4);
  121. /* End of .text-like segments */
  122. __etext = .;
  123. .ram_vector_table (COPY): {
  124. *(.ram_vector_table)
  125. } > RAM
  126. .data : {
  127. __data_start__ = .;
  128. *(vtable)
  129. *(.time_critical*)
  130. /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
  131. *(.text*)
  132. . = ALIGN(4);
  133. *(.rodata*)
  134. . = ALIGN(4);
  135. *(.data*)
  136. . = ALIGN(4);
  137. *(.after_data.*)
  138. . = ALIGN(4);
  139. /* preinit data */
  140. PROVIDE_HIDDEN (__mutex_array_start = .);
  141. KEEP(*(SORT(.mutex_array.*)))
  142. KEEP(*(.mutex_array))
  143. PROVIDE_HIDDEN (__mutex_array_end = .);
  144. . = ALIGN(4);
  145. /* preinit data */
  146. PROVIDE_HIDDEN (__preinit_array_start = .);
  147. KEEP(*(SORT(.preinit_array.*)))
  148. KEEP(*(.preinit_array))
  149. PROVIDE_HIDDEN (__preinit_array_end = .);
  150. . = ALIGN(4);
  151. /* init data */
  152. PROVIDE_HIDDEN (__init_array_start = .);
  153. KEEP(*(SORT(.init_array.*)))
  154. KEEP(*(.init_array))
  155. PROVIDE_HIDDEN (__init_array_end = .);
  156. . = ALIGN(4);
  157. /* finit data */
  158. PROVIDE_HIDDEN (__fini_array_start = .);
  159. *(SORT(.fini_array.*))
  160. *(.fini_array)
  161. PROVIDE_HIDDEN (__fini_array_end = .);
  162. *(.jcr)
  163. . = ALIGN(4);
  164. /* All data end */
  165. __data_end__ = .;
  166. } > RAM AT> FLASH
  167. .uninitialized_data (COPY): {
  168. . = ALIGN(4);
  169. *(.uninitialized_data*)
  170. } > RAM
  171. /* Start and end symbols must be word-aligned */
  172. .scratch_x : {
  173. __scratch_x_start__ = .;
  174. *(.scratch_x.*)
  175. . = ALIGN(4);
  176. __scratch_x_end__ = .;
  177. } > SCRATCH_X AT > FLASH
  178. __scratch_x_source__ = LOADADDR(.scratch_x);
  179. .scratch_y : {
  180. __scratch_y_start__ = .;
  181. *(.scratch_y.*)
  182. . = ALIGN(4);
  183. __scratch_y_end__ = .;
  184. } > SCRATCH_Y AT > FLASH
  185. __scratch_y_source__ = LOADADDR(.scratch_y);
  186. .bss : {
  187. . = ALIGN(4);
  188. __bss_start__ = .;
  189. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  190. *(COMMON)
  191. . = ALIGN(4);
  192. __bss_end__ = .;
  193. } > RAM
  194. /* .stack*_dummy section doesn't contains any symbols. It is only
  195. * used for linker to calculate size of stack sections, and assign
  196. * values to stack symbols later
  197. *
  198. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  199. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  200. * stack is not used then all of SCRATCH_X is free.
  201. */
  202. .stack1_dummy (COPY):
  203. {
  204. *(.stack1*)
  205. } > SCRATCH_X
  206. .stack_dummy (COPY):
  207. {
  208. *(.stack*)
  209. } > SCRATCH_Y
  210. .flash_end : {
  211. __flash_binary_end = .;
  212. } > FLASH
  213. /* stack limit is poorly named, but historically is maximum heap ptr */
  214. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  215. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  216. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  217. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  218. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  219. PROVIDE(__stack = __StackTop);
  220. /* Check if data + heap + stack exceeds RAM limit */
  221. ASSERT(__StackLimit >= __bss_end__, "region RAM overflowed")
  222. /* todo assert on extra code */
  223. }