rp2040.ld 6.3 KB

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