rp2040_btldr.ld 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. *
  3. * Customized linker script for building bootloader
  4. *
  5. */
  6. MEMORY
  7. {
  8. /* The bootloader is linked to begin at 0x12000100.
  9. * First 256 bytes are reserved for RP2040 second stage bootloader,
  10. * which comes as part of the main firmware.elf and is never overwritten.
  11. * The bootloader also runs without XIP cache because that seemed to cause
  12. * problems when writing flash.
  13. */
  14. FLASH(rx) : ORIGIN = 0x12000100, LENGTH = 128k-256
  15. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
  16. SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
  17. SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
  18. }
  19. ENTRY(_entry_point)
  20. SECTIONS
  21. {
  22. .flash_begin : {
  23. __flash_binary_start = .;
  24. } > FLASH
  25. .text : {
  26. __logical_binary_start = .;
  27. KEEP (*(.btldr_vectors))
  28. KEEP (*(.binary_info_header))
  29. __binary_info_header_end = .;
  30. . = ALIGN(256);
  31. __real_vectors_start = .;
  32. KEEP (*(.vectors))
  33. KEEP (*(.reset))
  34. KEEP (*(.init))
  35. *(.fini)
  36. *crtbegin.o(.ctors)
  37. *crtbegin?.o(.ctors)
  38. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  39. *(SORT(.ctors.*))
  40. *(.ctors)
  41. *crtbegin.o(.dtors)
  42. *crtbegin?.o(.dtors)
  43. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  44. *(SORT(.dtors.*))
  45. *(.dtors)
  46. *(.eh_frame*)
  47. *(.text .text*)
  48. . = ALIGN(4);
  49. } > FLASH
  50. .rodata : {
  51. . = ALIGN(4);
  52. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  53. *(.rodata)
  54. *(.rodata*)
  55. . = ALIGN(4);
  56. } > FLASH
  57. .ARM.extab :
  58. {
  59. *(.ARM.extab* .gnu.linkonce.armextab.*)
  60. } > FLASH
  61. __exidx_start = .;
  62. .ARM.exidx :
  63. {
  64. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  65. } > FLASH
  66. __exidx_end = .;
  67. . = ALIGN(4);
  68. __binary_info_start = .;
  69. .binary_info :
  70. {
  71. KEEP(*(.binary_info.keep.*))
  72. *(.binary_info.*)
  73. } > FLASH
  74. __binary_info_end = .;
  75. . = ALIGN(4);
  76. __etext = .;
  77. .ram_vector_table (COPY): {
  78. *(.ram_vector_table)
  79. } > RAM
  80. .data : {
  81. __data_start__ = .;
  82. *(vtable)
  83. /* Time critical code will go here to avoid external flash latency */
  84. *(.time_critical*)
  85. . = ALIGN(4);
  86. *(.data*)
  87. . = ALIGN(4);
  88. *(.after_data.*)
  89. . = ALIGN(4);
  90. PROVIDE_HIDDEN (__mutex_array_start = .);
  91. KEEP(*(SORT(.mutex_array.*)))
  92. KEEP(*(.mutex_array))
  93. PROVIDE_HIDDEN (__mutex_array_end = .);
  94. . = ALIGN(4);
  95. PROVIDE_HIDDEN (__preinit_array_start = .);
  96. KEEP(*(SORT(.preinit_array.*)))
  97. KEEP(*(.preinit_array))
  98. PROVIDE_HIDDEN (__preinit_array_end = .);
  99. . = ALIGN(4);
  100. PROVIDE_HIDDEN (__init_array_start = .);
  101. KEEP(*(SORT(.init_array.*)))
  102. KEEP(*(.init_array))
  103. PROVIDE_HIDDEN (__init_array_end = .);
  104. . = ALIGN(4);
  105. PROVIDE_HIDDEN (__fini_array_start = .);
  106. *(SORT(.fini_array.*))
  107. *(.fini_array)
  108. PROVIDE_HIDDEN (__fini_array_end = .);
  109. *(.jcr)
  110. . = ALIGN(4);
  111. __data_end__ = .;
  112. } > RAM AT> FLASH
  113. .uninitialized_data (COPY): {
  114. . = ALIGN(4);
  115. *(.uninitialized_data*)
  116. } > RAM
  117. .scratch_x : {
  118. __scratch_x_start__ = .;
  119. *(.scratch_x.*)
  120. . = ALIGN(4);
  121. __scratch_x_end__ = .;
  122. } > SCRATCH_X AT > FLASH
  123. __scratch_x_source__ = LOADADDR(.scratch_x);
  124. .scratch_y : {
  125. __scratch_y_start__ = .;
  126. *(.scratch_y.*)
  127. . = ALIGN(4);
  128. __scratch_y_end__ = .;
  129. } > SCRATCH_Y AT > FLASH
  130. __scratch_y_source__ = LOADADDR(.scratch_y);
  131. .bss : {
  132. . = ALIGN(4);
  133. __bss_start__ = .;
  134. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  135. *(COMMON)
  136. . = ALIGN(4);
  137. __bss_end__ = .;
  138. } > RAM
  139. .heap (COPY):
  140. {
  141. __end__ = .;
  142. PROVIDE(end = .);
  143. *(.heap*)
  144. . = ORIGIN(RAM) + LENGTH(RAM) - 0x400;
  145. __HeapLimit = .;
  146. } > RAM
  147. .stack1_dummy (COPY):
  148. {
  149. *(.stack1*)
  150. } > SCRATCH_X
  151. .stack_dummy (COPY):
  152. {
  153. *(.stack*)
  154. } > RAM
  155. .flash_end : {
  156. __flash_binary_end = .;
  157. } > FLASH
  158. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  159. __StackLimit = __StackTop - 0x400;
  160. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  161. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  162. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  163. PROVIDE(__stack = __StackTop);
  164. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  165. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  166. }