rp2040_btldr.ld 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. /*
  22. *
  23. * Customized linker script for building bootloader
  24. *
  25. */
  26. MEMORY
  27. {
  28. /* The bootloader is linked to begin at 0x12000100.
  29. * First 256 bytes are reserved for RP2040 second stage bootloader,
  30. * which comes as part of the main firmware.elf and is never overwritten.
  31. */
  32. FLASH(rx) : ORIGIN = 0x10000100, LENGTH = 128k-256
  33. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* Leave space for pico-debug */
  34. SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
  35. SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
  36. }
  37. ENTRY(_entry_point)
  38. SECTIONS
  39. {
  40. .flash_begin : {
  41. __flash_binary_start = .;
  42. } > FLASH
  43. /* Discard code that is not used in bootloader mode to
  44. * reduce the flash usage.
  45. */
  46. /DISCARD/ : {
  47. *scanf*(*)
  48. *strtod*(*)
  49. *libipv4.a:*(*)
  50. *liblwip*.a:*(*)
  51. *libBlueSCSI_audio_RP2MCU.a:*(*)
  52. *libAdafruit*.a:*(*)
  53. *libWire.a:*(*)
  54. *libSPI.a:*(*)
  55. *libBlueSCSI_platform_RP2MCU.a:BlueSCSI_platform_network.cpp.o*(*)
  56. *libFrameworkArduino.a:cyw43_wrappers.cpp.o*(*)
  57. /* gt */
  58. *BlueSCSI_tape.cpp.o*(*)
  59. *BlueSCSI_mode.cpp.o*(*)
  60. *BlueSCSI_blink.cpp.o*(*)
  61. *BlueSCSI_buffer_control.cpp.o*(*)
  62. *uiDiskUtils.cpp.o*(*)
  63. *SDNavigator.cpp.o*(*)
  64. }
  65. .text : {
  66. cyw43_digitalWrite = 0;
  67. cyw43_digitalRead = 0;
  68. cyw43_pinMode = 0;
  69. init_cyw43_wifi = bootloader_main;
  70. platform_poll = 0;
  71. __logical_binary_start = .;
  72. KEEP (*(.btldr_vectors))
  73. KEEP (*(.binary_info_header))
  74. __binary_info_header_end = .;
  75. . = ALIGN(256);
  76. __real_vectors_start = .;
  77. KEEP (*(.vectors))
  78. KEEP (*(.reset))
  79. KEEP (*(.init))
  80. *(.fini)
  81. *crtbegin.o(.ctors)
  82. *crtbegin?.o(.ctors)
  83. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  84. *(SORT(.ctors.*))
  85. *(.ctors)
  86. *crtbegin.o(.dtors)
  87. *crtbegin?.o(.dtors)
  88. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  89. *(SORT(.dtors.*))
  90. *(.dtors)
  91. *(.eh_frame*)
  92. *(.text .text*)
  93. . = ALIGN(4);
  94. } > FLASH
  95. .rodata : {
  96. . = ALIGN(4);
  97. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  98. *(.rodata)
  99. *(.rodata*)
  100. . = ALIGN(4);
  101. } > FLASH
  102. .ARM.extab :
  103. {
  104. *(.ARM.extab* .gnu.linkonce.armextab.*)
  105. } > FLASH
  106. __exidx_start = .;
  107. .ARM.exidx :
  108. {
  109. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  110. } > FLASH
  111. __exidx_end = .;
  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. __etext = .;
  122. .ram_vector_table (COPY): {
  123. *(.ram_vector_table)
  124. } > RAM
  125. .data : {
  126. __data_start__ = .;
  127. *(vtable)
  128. /* Time critical code will go here to avoid external flash latency */
  129. *(.time_critical*)
  130. . = ALIGN(4);
  131. *(.data*)
  132. . = ALIGN(4);
  133. *(.after_data.*)
  134. . = ALIGN(4);
  135. PROVIDE_HIDDEN (__mutex_array_start = .);
  136. KEEP(*(SORT(.mutex_array.*)))
  137. KEEP(*(.mutex_array))
  138. PROVIDE_HIDDEN (__mutex_array_end = .);
  139. . = ALIGN(4);
  140. PROVIDE_HIDDEN (__preinit_array_start = .);
  141. KEEP(*(SORT(.preinit_array.*)))
  142. KEEP(*(.preinit_array))
  143. PROVIDE_HIDDEN (__preinit_array_end = .);
  144. . = ALIGN(4);
  145. PROVIDE_HIDDEN (__init_array_start = .);
  146. KEEP(*(SORT(.init_array.*)))
  147. KEEP(*(.init_array))
  148. PROVIDE_HIDDEN (__init_array_end = .);
  149. . = ALIGN(4);
  150. PROVIDE_HIDDEN (__fini_array_start = .);
  151. *(SORT(.fini_array.*))
  152. *(.fini_array)
  153. PROVIDE_HIDDEN (__fini_array_end = .);
  154. *(.jcr)
  155. . = ALIGN(4);
  156. __data_end__ = .;
  157. } > RAM AT> FLASH
  158. .uninitialized_data (COPY): {
  159. . = ALIGN(4);
  160. *(.uninitialized_data*)
  161. } > RAM
  162. .scratch_x : {
  163. __scratch_x_start__ = .;
  164. *(.scratch_x.*)
  165. . = ALIGN(4);
  166. __scratch_x_end__ = .;
  167. } > SCRATCH_X AT > FLASH
  168. __scratch_x_source__ = LOADADDR(.scratch_x);
  169. .scratch_y : {
  170. __scratch_y_start__ = .;
  171. *(.scratch_y.*)
  172. . = ALIGN(4);
  173. __scratch_y_end__ = .;
  174. } > SCRATCH_Y AT > FLASH
  175. __scratch_y_source__ = LOADADDR(.scratch_y);
  176. .bss : {
  177. . = ALIGN(4);
  178. __bss_start__ = .;
  179. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  180. *(COMMON)
  181. . = ALIGN(4);
  182. __bss_end__ = .;
  183. } > RAM
  184. .heap (COPY):
  185. {
  186. __end__ = .;
  187. PROVIDE(end = .);
  188. *(.heap*)
  189. . = ORIGIN(RAM) + LENGTH(RAM) - 0x400;
  190. __HeapLimit = .;
  191. } > RAM
  192. .stack1_dummy (COPY):
  193. {
  194. *(.stack1*)
  195. } > SCRATCH_X
  196. .stack_dummy (COPY):
  197. {
  198. *(.stack*)
  199. } > RAM
  200. .flash_end : {
  201. __flash_binary_end = .;
  202. } > FLASH
  203. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  204. __StackLimit = __StackTop - 0x400;
  205. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  206. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  207. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  208. PROVIDE(__stack = __StackTop);
  209. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  210. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  211. }