rp2040.ld 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. MEMORY
  2. {
  3. FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 352k
  4. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
  5. SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
  6. SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
  7. }
  8. ENTRY(_entry_point)
  9. SECTIONS
  10. {
  11. .flash_begin : {
  12. __flash_binary_start = .;
  13. } > FLASH
  14. .boot2 : {
  15. __boot2_start__ = .;
  16. KEEP (*(.boot2))
  17. __boot2_end__ = .;
  18. } > FLASH
  19. ASSERT(__boot2_end__ - __boot2_start__ == 256,
  20. "ERROR: Pico second stage bootloader must be 256 bytes in size")
  21. /* If BlueSCSI SD card bootloader is included, it goes in first 128 kB */
  22. .text.bootloader : ALIGN(16) SUBALIGN(16)
  23. {
  24. KEEP(*(.text.btldr*))
  25. . = ALIGN(131072);
  26. CHECK_BOOTLOADER_SIZE = 1 / (. <= 131072);
  27. } > FLASH
  28. .text : {
  29. __logical_binary_start = .;
  30. __real_vectors_start = .;
  31. KEEP (*(.vectors))
  32. KEEP (*(.binary_info_header))
  33. __binary_info_header_end = .;
  34. KEEP (*(.reset))
  35. KEEP (*(.init))
  36. *(.fini)
  37. *crtbegin.o(.ctors)
  38. *crtbegin?.o(.ctors)
  39. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  40. *(SORT(.ctors.*))
  41. *(.ctors)
  42. *crtbegin.o(.dtors)
  43. *crtbegin?.o(.dtors)
  44. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  45. *(SORT(.dtors.*))
  46. *(.dtors)
  47. *(.eh_frame*)
  48. . = ALIGN(4);
  49. /* Put only non-timecritical code in flash
  50. * This includes e.g. floating point math routines.
  51. */
  52. *libm*:(.text .text*)
  53. *libc*:(.text .text*)
  54. *libgcc*:*df*(.text .text*)
  55. *USB*(.text .text*)
  56. *SPI*(.text .text*)
  57. *Spi*(.text .text*)
  58. *spi*(.text .text*)
  59. *stdc*:(.text .text*)
  60. *supc*:(.text .text*)
  61. *nosys*:(.text .text*)
  62. *libc*:*printf*(.text .text*)
  63. *libc*:*toa*(.text .text*)
  64. *libminIni.a:(.text .text*)
  65. /* RP2040 breakpoints in RAM code don't always work very well
  66. * because the boot routine tends to overwrite them.
  67. * Uncommenting this line puts all code in flash.
  68. */
  69. /* *(.text .text*) */
  70. } > FLASH
  71. .rodata : {
  72. . = ALIGN(4);
  73. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  74. *(.rodata)
  75. *(.rodata*)
  76. . = ALIGN(4);
  77. } > FLASH
  78. .ARM.extab :
  79. {
  80. *(.ARM.extab* .gnu.linkonce.armextab.*)
  81. } > FLASH
  82. __exidx_start = .;
  83. .ARM.exidx :
  84. {
  85. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  86. } > FLASH
  87. __exidx_end = .;
  88. . = ALIGN(4);
  89. __binary_info_start = .;
  90. .binary_info :
  91. {
  92. KEEP(*(.binary_info.keep.*))
  93. *(.binary_info.*)
  94. } > FLASH
  95. __binary_info_end = .;
  96. . = ALIGN(4);
  97. __etext = .;
  98. .ram_vector_table (COPY): {
  99. *(.ram_vector_table)
  100. } > RAM
  101. .data : {
  102. __data_start__ = .;
  103. *(vtable)
  104. /* Time critical code will go here to avoid external flash latency */
  105. *(.time_critical*)
  106. . = ALIGN(4);
  107. *(.text)
  108. *(.text*)
  109. . = ALIGN(4);
  110. *(.data*)
  111. . = ALIGN(4);
  112. *(.after_data.*)
  113. . = ALIGN(4);
  114. PROVIDE_HIDDEN (__mutex_array_start = .);
  115. KEEP(*(SORT(.mutex_array.*)))
  116. KEEP(*(.mutex_array))
  117. PROVIDE_HIDDEN (__mutex_array_end = .);
  118. . = ALIGN(4);
  119. PROVIDE_HIDDEN (__preinit_array_start = .);
  120. KEEP(*(SORT(.preinit_array.*)))
  121. KEEP(*(.preinit_array))
  122. PROVIDE_HIDDEN (__preinit_array_end = .);
  123. . = ALIGN(4);
  124. PROVIDE_HIDDEN (__init_array_start = .);
  125. KEEP(*(SORT(.init_array.*)))
  126. KEEP(*(.init_array))
  127. PROVIDE_HIDDEN (__init_array_end = .);
  128. . = ALIGN(4);
  129. PROVIDE_HIDDEN (__fini_array_start = .);
  130. *(SORT(.fini_array.*))
  131. *(.fini_array)
  132. PROVIDE_HIDDEN (__fini_array_end = .);
  133. *(.jcr)
  134. . = ALIGN(4);
  135. __data_end__ = .;
  136. } > RAM AT> FLASH
  137. .uninitialized_data (COPY): {
  138. . = ALIGN(4);
  139. *(.uninitialized_data*)
  140. } > RAM
  141. .scratch_x : {
  142. __scratch_x_start__ = .;
  143. *(.scratch_x.*)
  144. . = ALIGN(4);
  145. __scratch_x_end__ = .;
  146. } > SCRATCH_X AT > FLASH
  147. __scratch_x_source__ = LOADADDR(.scratch_x);
  148. .scratch_y : {
  149. __scratch_y_start__ = .;
  150. *(.scratch_y.*)
  151. . = ALIGN(4);
  152. __scratch_y_end__ = .;
  153. } > SCRATCH_Y AT > FLASH
  154. __scratch_y_source__ = LOADADDR(.scratch_y);
  155. .bss : {
  156. . = ALIGN(4);
  157. __bss_start__ = .;
  158. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  159. *(COMMON)
  160. . = ALIGN(4);
  161. __bss_end__ = .;
  162. } > RAM
  163. .heap (COPY):
  164. {
  165. __end__ = .;
  166. PROVIDE(end = .);
  167. *(.heap*)
  168. . = ORIGIN(RAM) + LENGTH(RAM) - 0x400;
  169. __HeapLimit = .;
  170. } > RAM
  171. .stack1_dummy (COPY):
  172. {
  173. *(.stack1*)
  174. } > SCRATCH_X
  175. .stack_dummy (COPY):
  176. {
  177. *(.stack*)
  178. } > RAM
  179. .flash_end : {
  180. __flash_binary_end = .;
  181. } > FLASH
  182. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  183. __StackLimit = __StackTop - 0x400;
  184. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  185. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  186. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  187. PROVIDE(__stack = __StackTop);
  188. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  189. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  190. }