rp2040-template.ld 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2022-2025 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 = $program_size
  24. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* 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 BlueSCSI 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. .pio/build/$project_name/src/BlueSCSI_initiator.cpp.o(.text .text*)
  73. .pio/build/$project_name/src/BlueSCSI_msc_initiator.cpp.o(.text .text*)
  74. .pio/build/$project_name/src/BlueSCSI_log.cpp.o(.text .text*)
  75. .pio/build/$project_name/src/BlueSCSI_log_trace.cpp.o(.text .text*)
  76. .pio/build/$project_name/src/BlueSCSI_settings.cpp.o(.text .text*)
  77. .pio/build/$project_name/src/QuirksCheck.cpp.o(.text .text*)
  78. *libm*:(.text .text*)
  79. *libc*:(.text .text*)
  80. *libgcc*:*df*(.text .text*)
  81. *USB*(.text .text*)
  82. *SPI*(.text .text*)
  83. *Spi*(.text .text*)
  84. *spi*(.text .text*)
  85. *stdc*:(.text .text*)
  86. *supc*:(.text .text*)
  87. *nosys*:(.text .text*)
  88. *libc*:*printf*(.text .text*)
  89. *libc*:*toa*(.text .text*)
  90. *libminIni.a:(.text .text*)
  91. *libCUEParser.a:(.text .text*)
  92. /* RP2040 breakpoints in RAM code don't always work very well
  93. * because the boot routine tends to overwrite them.
  94. * Uncommenting this line puts all code in flash.
  95. * You may have to delete "firmware.elf" for the next build
  96. * to use this linker file's changes
  97. *
  98. * Alternatively, use "hbreak" in gdb to force hardware
  99. * breakpoints instead of RAM breakpoints.
  100. */
  101. /* *(.text .text*) */
  102. } > FLASH
  103. .rodata : {
  104. . = ALIGN(4);
  105. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  106. *(.rodata)
  107. *(.rodata*)
  108. . = ALIGN(4);
  109. } > FLASH
  110. .ARM.extab :
  111. {
  112. *(.ARM.extab* .gnu.linkonce.armextab.*)
  113. } > FLASH
  114. __exidx_start = .;
  115. .ARM.exidx :
  116. {
  117. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  118. } > FLASH
  119. __exidx_end = .;
  120. . = ALIGN(4);
  121. __binary_info_start = .;
  122. .binary_info :
  123. {
  124. KEEP(*(.binary_info.keep.*))
  125. *(.binary_info.*)
  126. } > FLASH
  127. __binary_info_end = .;
  128. . = ALIGN(4);
  129. __etext = .;
  130. .ram_vector_table (COPY): {
  131. *(.ram_vector_table)
  132. } > RAM
  133. .data : {
  134. __data_start__ = .;
  135. *(vtable)
  136. /* Time critical code will go here to avoid external flash latency */
  137. *(.time_critical*)
  138. . = ALIGN(4);
  139. *(.text)
  140. *(.text*)
  141. . = ALIGN(4);
  142. *(.data*)
  143. . = ALIGN(4);
  144. *(.after_data.*)
  145. . = ALIGN(4);
  146. PROVIDE_HIDDEN (__mutex_array_start = .);
  147. KEEP(*(SORT(.mutex_array.*)))
  148. KEEP(*(.mutex_array))
  149. PROVIDE_HIDDEN (__mutex_array_end = .);
  150. . = ALIGN(4);
  151. PROVIDE_HIDDEN (__preinit_array_start = .);
  152. KEEP(*(SORT(.preinit_array.*)))
  153. KEEP(*(.preinit_array))
  154. PROVIDE_HIDDEN (__preinit_array_end = .);
  155. . = ALIGN(4);
  156. PROVIDE_HIDDEN (__init_array_start = .);
  157. KEEP(*(SORT(.init_array.*)))
  158. KEEP(*(.init_array))
  159. PROVIDE_HIDDEN (__init_array_end = .);
  160. . = ALIGN(4);
  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. __data_end__ = .;
  168. } > RAM AT> FLASH
  169. .uninitialized_data (COPY): {
  170. . = ALIGN(4);
  171. *(.uninitialized_data*)
  172. } > RAM
  173. .scratch_x : {
  174. __scratch_x_start__ = .;
  175. *(.scratch_x.*)
  176. . = ALIGN(4);
  177. __scratch_x_end__ = .;
  178. } > SCRATCH_X AT > FLASH
  179. __scratch_x_source__ = LOADADDR(.scratch_x);
  180. .scratch_y : {
  181. __scratch_y_start__ = .;
  182. *(.scratch_y.*)
  183. . = ALIGN(4);
  184. __scratch_y_end__ = .;
  185. } > SCRATCH_Y AT > FLASH
  186. __scratch_y_source__ = LOADADDR(.scratch_y);
  187. .bss : {
  188. . = ALIGN(4);
  189. __bss_start__ = .;
  190. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  191. *(COMMON)
  192. . = ALIGN(4);
  193. __bss_end__ = .;
  194. } > RAM
  195. .heap (COPY):
  196. {
  197. __end__ = .;
  198. PROVIDE(end = .);
  199. *(.heap*)
  200. . = ORIGIN(RAM) + LENGTH(RAM) - 0x400;
  201. __HeapLimit = .;
  202. } > RAM
  203. .stack1_dummy (COPY):
  204. {
  205. *(.stack1*)
  206. } > SCRATCH_X
  207. .stack_dummy (COPY):
  208. {
  209. *(.stack*)
  210. } > RAM
  211. .flash_end : {
  212. __flash_binary_end = .;
  213. } > FLASH
  214. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  215. __StackLimit = __StackTop - 0x400;
  216. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  217. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  218. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  219. PROVIDE(__stack = __StackTop);
  220. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  221. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  222. }