選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

bootloader.ld 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* Based on GCC ARM embedded samples.
  2. Defines the following symbols for use by code:
  3. __exidx_start
  4. __exidx_end
  5. __etext
  6. __data_start__
  7. __preinit_array_start
  8. __preinit_array_end
  9. __init_array_start
  10. __init_array_end
  11. __fini_array_start
  12. __fini_array_end
  13. __data_end__
  14. __bss_start__
  15. __bss_end__
  16. __end__
  17. end
  18. __HeapLimit
  19. __StackLimit
  20. __StackTop
  21. __stack (== StackTop)
  22. */
  23. /*
  24. * TODO: Hard-code 360k, which is the size I see on my machine with
  25. * 'sta' mode and debug printf.
  26. * There must be a better way to determine the size dynamically somehow.
  27. */
  28. MEMORY
  29. {
  30. FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 360k
  31. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
  32. SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
  33. SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
  34. }
  35. ENTRY(_entry_point)
  36. SECTIONS
  37. {
  38. /* Second stage bootloader is prepended to the image. It must be 256 bytes big
  39. and checksummed. It is usually built by the boot_stage2 target
  40. in the Raspberry Pi Pico SDK
  41. */
  42. .flash_begin : {
  43. __flash_binary_start = .;
  44. } > FLASH
  45. .boot2 : {
  46. __boot2_start__ = .;
  47. KEEP (*(.boot2))
  48. __boot2_end__ = .;
  49. } > FLASH
  50. ASSERT(__boot2_end__ - __boot2_start__ == 256,
  51. "ERROR: Pico second stage bootloader must be 256 bytes in size")
  52. /* The second stage will always enter the image at the start of .text.
  53. The debugger will use the ELF entry point, which is the _entry_point
  54. symbol if present, otherwise defaults to start of .text.
  55. This can be used to transfer control back to the bootrom on debugger
  56. launches only, to perform proper flash setup.
  57. */
  58. .flashtext : {
  59. __logical_binary_start = .;
  60. KEEP (*(.vectors))
  61. KEEP (*(.binary_info_header))
  62. __binary_info_header_end = .;
  63. KEEP (*(.reset))
  64. }
  65. .rodata : {
  66. /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */
  67. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  68. . = ALIGN(4);
  69. } > FLASH
  70. .ARM.extab :
  71. {
  72. *(.ARM.extab* .gnu.linkonce.armextab.*)
  73. } > FLASH
  74. __exidx_start = .;
  75. .ARM.exidx :
  76. {
  77. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  78. } > FLASH
  79. __exidx_end = .;
  80. /* Machine inspectable binary information */
  81. . = ALIGN(4);
  82. __binary_info_start = .;
  83. .binary_info :
  84. {
  85. KEEP(*(.binary_info.keep.*))
  86. *(.binary_info.*)
  87. } > FLASH
  88. __binary_info_end = .;
  89. . = ALIGN(4);
  90. /* Vector table goes first in RAM, to avoid large alignment hole */
  91. .ram_vector_table (COPY): {
  92. *(.ram_vector_table)
  93. } > RAM
  94. .text : {
  95. __ram_text_start__ = .;
  96. *(.init)
  97. *(.text*)
  98. *(.fini)
  99. /* Pull all c'tors into .text */
  100. *crtbegin.o(.ctors)
  101. *crtbegin?.o(.ctors)
  102. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  103. *(SORT(.ctors.*))
  104. *(.ctors)
  105. /* Followed by destructors */
  106. *crtbegin.o(.dtors)
  107. *crtbegin?.o(.dtors)
  108. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  109. *(SORT(.dtors.*))
  110. *(.dtors)
  111. *(.eh_frame*)
  112. . = ALIGN(4);
  113. __ram_text_end__ = .;
  114. } > RAM AT> FLASH
  115. __ram_text_source__ = LOADADDR(.text);
  116. .data : {
  117. __data_start__ = .;
  118. *(vtable)
  119. *(.time_critical*)
  120. . = ALIGN(4);
  121. *(.rodata*)
  122. . = ALIGN(4);
  123. *(.data*)
  124. . = ALIGN(4);
  125. *(.after_data.*)
  126. . = ALIGN(4);
  127. /* preinit data */
  128. PROVIDE_HIDDEN (__mutex_array_start = .);
  129. KEEP(*(SORT(.mutex_array.*)))
  130. KEEP(*(.mutex_array))
  131. PROVIDE_HIDDEN (__mutex_array_end = .);
  132. . = ALIGN(4);
  133. /* preinit data */
  134. PROVIDE_HIDDEN (__preinit_array_start = .);
  135. KEEP(*(SORT(.preinit_array.*)))
  136. KEEP(*(.preinit_array))
  137. PROVIDE_HIDDEN (__preinit_array_end = .);
  138. . = ALIGN(4);
  139. /* init data */
  140. PROVIDE_HIDDEN (__init_array_start = .);
  141. KEEP(*(SORT(.init_array.*)))
  142. KEEP(*(.init_array))
  143. PROVIDE_HIDDEN (__init_array_end = .);
  144. . = ALIGN(4);
  145. /* finit data */
  146. PROVIDE_HIDDEN (__fini_array_start = .);
  147. *(SORT(.fini_array.*))
  148. *(.fini_array)
  149. PROVIDE_HIDDEN (__fini_array_end = .);
  150. *(.jcr)
  151. . = ALIGN(4);
  152. /* All data end */
  153. __data_end__ = .;
  154. } > RAM AT> FLASH
  155. /* __etext is the name of the .data init source pointer (...) */
  156. __etext = LOADADDR(.data);
  157. .uninitialized_data (COPY): {
  158. . = ALIGN(4);
  159. *(.uninitialized_data*)
  160. } > RAM
  161. /* Start and end symbols must be word-aligned */
  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. end = __end__;
  188. *(.heap*)
  189. __HeapLimit = .;
  190. } > RAM
  191. /* .stack*_dummy section doesn't contains any symbols. It is only
  192. * used for linker to calculate size of stack sections, and assign
  193. * values to stack symbols later
  194. *
  195. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  196. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  197. * stack is not used then all of SCRATCH_X is free.
  198. */
  199. .stack1_dummy (COPY):
  200. {
  201. *(.stack1*)
  202. } > SCRATCH_X
  203. .stack_dummy (COPY):
  204. {
  205. *(.stack*)
  206. } > SCRATCH_Y
  207. .flash_end : {
  208. __flash_binary_end = .;
  209. } > FLASH
  210. /* stack limit is poorly named, but historically is maximum heap ptr */
  211. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  212. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  213. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  214. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  215. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  216. PROVIDE(__stack = __StackTop);
  217. /* Check if data + heap + stack exceeds RAM limit */
  218. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  219. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  220. /* todo assert on extra code */
  221. }