rp2040_btldr.ld 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. .text : {
  44. __logical_binary_start = .;
  45. KEEP (*(.btldr_vectors))
  46. KEEP (*(.binary_info_header))
  47. __binary_info_header_end = .;
  48. . = ALIGN(256);
  49. __real_vectors_start = .;
  50. KEEP (*(.vectors))
  51. KEEP (*(.reset))
  52. KEEP (*(.init))
  53. *(.fini)
  54. *crtbegin.o(.ctors)
  55. *crtbegin?.o(.ctors)
  56. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  57. *(SORT(.ctors.*))
  58. *(.ctors)
  59. *crtbegin.o(.dtors)
  60. *crtbegin?.o(.dtors)
  61. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  62. *(SORT(.dtors.*))
  63. *(.dtors)
  64. *(.eh_frame*)
  65. *(.text .text*)
  66. . = ALIGN(4);
  67. } > FLASH
  68. .rodata : {
  69. . = ALIGN(4);
  70. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  71. *(.rodata)
  72. *(.rodata*)
  73. . = ALIGN(4);
  74. } > FLASH
  75. .ARM.extab :
  76. {
  77. *(.ARM.extab* .gnu.linkonce.armextab.*)
  78. } > FLASH
  79. __exidx_start = .;
  80. .ARM.exidx :
  81. {
  82. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  83. } > FLASH
  84. __exidx_end = .;
  85. . = ALIGN(4);
  86. __binary_info_start = .;
  87. .binary_info :
  88. {
  89. KEEP(*(.binary_info.keep.*))
  90. *(.binary_info.*)
  91. } > FLASH
  92. __binary_info_end = .;
  93. . = ALIGN(4);
  94. __etext = .;
  95. .ram_vector_table (COPY): {
  96. *(.ram_vector_table)
  97. } > RAM
  98. .data : {
  99. __data_start__ = .;
  100. *(vtable)
  101. /* Time critical code will go here to avoid external flash latency */
  102. *(.time_critical*)
  103. . = ALIGN(4);
  104. *(.data*)
  105. . = ALIGN(4);
  106. *(.after_data.*)
  107. . = ALIGN(4);
  108. PROVIDE_HIDDEN (__mutex_array_start = .);
  109. KEEP(*(SORT(.mutex_array.*)))
  110. KEEP(*(.mutex_array))
  111. PROVIDE_HIDDEN (__mutex_array_end = .);
  112. . = ALIGN(4);
  113. PROVIDE_HIDDEN (__preinit_array_start = .);
  114. KEEP(*(SORT(.preinit_array.*)))
  115. KEEP(*(.preinit_array))
  116. PROVIDE_HIDDEN (__preinit_array_end = .);
  117. . = ALIGN(4);
  118. PROVIDE_HIDDEN (__init_array_start = .);
  119. KEEP(*(SORT(.init_array.*)))
  120. KEEP(*(.init_array))
  121. PROVIDE_HIDDEN (__init_array_end = .);
  122. . = ALIGN(4);
  123. PROVIDE_HIDDEN (__fini_array_start = .);
  124. *(SORT(.fini_array.*))
  125. *(.fini_array)
  126. PROVIDE_HIDDEN (__fini_array_end = .);
  127. *(.jcr)
  128. . = ALIGN(4);
  129. __data_end__ = .;
  130. } > RAM AT> FLASH
  131. .uninitialized_data (COPY): {
  132. . = ALIGN(4);
  133. *(.uninitialized_data*)
  134. } > RAM
  135. .scratch_x : {
  136. __scratch_x_start__ = .;
  137. *(.scratch_x.*)
  138. . = ALIGN(4);
  139. __scratch_x_end__ = .;
  140. } > SCRATCH_X AT > FLASH
  141. __scratch_x_source__ = LOADADDR(.scratch_x);
  142. .scratch_y : {
  143. __scratch_y_start__ = .;
  144. *(.scratch_y.*)
  145. . = ALIGN(4);
  146. __scratch_y_end__ = .;
  147. } > SCRATCH_Y AT > FLASH
  148. __scratch_y_source__ = LOADADDR(.scratch_y);
  149. .bss : {
  150. . = ALIGN(4);
  151. __bss_start__ = .;
  152. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  153. *(COMMON)
  154. . = ALIGN(4);
  155. __bss_end__ = .;
  156. } > RAM
  157. .heap (COPY):
  158. {
  159. __end__ = .;
  160. PROVIDE(end = .);
  161. *(.heap*)
  162. . = ORIGIN(RAM) + LENGTH(RAM) - 0x400;
  163. __HeapLimit = .;
  164. } > RAM
  165. .stack1_dummy (COPY):
  166. {
  167. *(.stack1*)
  168. } > SCRATCH_X
  169. .stack_dummy (COPY):
  170. {
  171. *(.stack*)
  172. } > RAM
  173. .flash_end : {
  174. __flash_binary_end = .;
  175. } > FLASH
  176. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  177. __StackLimit = __StackTop - 0x400;
  178. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  179. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  180. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  181. PROVIDE(__stack = __StackTop);
  182. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  183. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  184. }