cpp.linker_script.ld 4.4 KB

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