link.ld 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 finsh shell */
  66. . = ALIGN(4);
  67. __fsymtab_start = .;
  68. KEEP(*(FSymTab))
  69. __fsymtab_end = .;
  70. . = ALIGN(4);
  71. __vsymtab_start = .;
  72. KEEP(*(VSymTab))
  73. __vsymtab_end = .;
  74. /* section information for initial. */
  75. . = ALIGN(4);
  76. __rt_init_start = .;
  77. KEEP(*(SORT(.rti_fn*)))
  78. __rt_init_end = .;
  79. . = ALIGN(4);
  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. PROVIDE(__ctors_start__ = .);
  94. KEEP (*(SORT(.init_array.*)))
  95. KEEP (*(.init_array))
  96. PROVIDE(__ctors_end__ = .);
  97. . = ALIGN(4);
  98. _etext = .;
  99. } > FLASH
  100. .rodata : {
  101. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
  102. . = ALIGN(4);
  103. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  104. . = ALIGN(4);
  105. } > FLASH
  106. .ARM.extab :
  107. {
  108. *(.ARM.extab* .gnu.linkonce.armextab.*)
  109. } > FLASH
  110. __exidx_start = .;
  111. .ARM.exidx :
  112. {
  113. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  114. } > FLASH
  115. __exidx_end = .;
  116. /* Machine inspectable binary information */
  117. . = ALIGN(4);
  118. __binary_info_start = .;
  119. .binary_info :
  120. {
  121. KEEP(*(.binary_info.keep.*))
  122. *(.binary_info.*)
  123. } > FLASH
  124. __binary_info_end = .;
  125. . = ALIGN(4);
  126. .ram_vector_table (NOLOAD): {
  127. *(.ram_vector_table)
  128. } > RAM
  129. .data : {
  130. __data_start__ = .;
  131. *(vtable)
  132. *(.time_critical*)
  133. /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
  134. *(.text*)
  135. . = ALIGN(4);
  136. *(.rodata*)
  137. . = ALIGN(4);
  138. *(.data*)
  139. . = ALIGN(4);
  140. *(.after_data.*)
  141. . = ALIGN(4);
  142. /* preinit data */
  143. PROVIDE_HIDDEN (__mutex_array_start = .);
  144. KEEP(*(SORT(.mutex_array.*)))
  145. KEEP(*(.mutex_array))
  146. PROVIDE_HIDDEN (__mutex_array_end = .);
  147. . = ALIGN(4);
  148. /* preinit data */
  149. PROVIDE_HIDDEN (__preinit_array_start = .);
  150. KEEP(*(SORT(.preinit_array.*)))
  151. KEEP(*(.preinit_array))
  152. PROVIDE_HIDDEN (__preinit_array_end = .);
  153. . = ALIGN(4);
  154. /* init data */
  155. PROVIDE_HIDDEN (__init_array_start = .);
  156. KEEP(*(SORT(.init_array.*)))
  157. KEEP(*(.init_array))
  158. PROVIDE_HIDDEN (__init_array_end = .);
  159. . = ALIGN(4);
  160. /* finit data */
  161. PROVIDE_HIDDEN (__fini_array_start = .);
  162. *(SORT(.fini_array.*))
  163. *(.fini_array)
  164. PROVIDE_HIDDEN (__fini_array_end = .);
  165. *(.jcr)
  166. . = ALIGN(4);
  167. /* All data end */
  168. __data_end__ = .;
  169. } > RAM AT> FLASH
  170. /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
  171. __etext = LOADADDR(.data);
  172. .uninitialized_data (NOLOAD): {
  173. . = ALIGN(4);
  174. *(.uninitialized_data*)
  175. } > RAM
  176. /* Start and end symbols must be word-aligned */
  177. .scratch_x : {
  178. __scratch_x_start__ = .;
  179. *(.scratch_x.*)
  180. . = ALIGN(4);
  181. __scratch_x_end__ = .;
  182. } > SCRATCH_X AT > FLASH
  183. __scratch_x_source__ = LOADADDR(.scratch_x);
  184. .scratch_y : {
  185. __scratch_y_start__ = .;
  186. *(.scratch_y.*)
  187. . = ALIGN(4);
  188. __scratch_y_end__ = .;
  189. } > SCRATCH_Y AT > FLASH
  190. __scratch_y_source__ = LOADADDR(.scratch_y);
  191. .bss : {
  192. . = ALIGN(4);
  193. __bss_start__ = .;
  194. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  195. *(COMMON)
  196. . = ALIGN(4);
  197. __bss_end__ = .;
  198. } > RAM
  199. /* .stack*_dummy section doesn't contains any symbols. It is only
  200. * used for linker to calculate size of stack sections, and assign
  201. * values to stack symbols later
  202. *
  203. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  204. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  205. * stack is not used then all of SCRATCH_X is free.
  206. */
  207. .stack1_dummy (NOLOAD):
  208. {
  209. *(.stack1*)
  210. } > SCRATCH_X
  211. .stack_dummy (NOLOAD):
  212. {
  213. KEEP(*(.stack*))
  214. } > SCRATCH_Y
  215. .flash_end : {
  216. PROVIDE(__flash_binary_end = .);
  217. } > FLASH
  218. /* stack limit is poorly named, but historically is maximum heap ptr */
  219. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  220. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  221. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  222. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  223. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  224. PROVIDE(__stack = __StackTop);
  225. /* Check if data + heap + stack exceeds RAM limit */
  226. ASSERT(__StackLimit >= __bss_end__, "region RAM overflowed")
  227. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  228. /* todo assert on extra code */
  229. }