rp2040_btldr.ld 4.5 KB

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