You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bootloader_shell.ld 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 max 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. FLASH_IMGHDR(rx) : ORIGIN = 0x10000000 + 360k, LENGTH = 4k
  32. FLASH_APP(rx) : ORIGIN = 0x10000000 + 364k, LENGTH = 2048k - 364k
  33. RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
  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. /* Second stage bootloader is prepended to the image. It must be 256 bytes big
  41. and checksummed. It is usually built by the boot_stage2 target
  42. in the Raspberry Pi Pico SDK
  43. */
  44. .flash_begin : {
  45. __flash_binary_start = .;
  46. } > FLASH
  47. .boot2 : {
  48. __boot2_start__ = .;
  49. KEEP (*(.boot2))
  50. __boot2_end__ = .;
  51. } > FLASH
  52. ASSERT(__boot2_end__ - __boot2_start__ == 256,
  53. "ERROR: Pico second stage bootloader must be 256 bytes in size")
  54. /*
  55. * Name a section for the image header and app binary
  56. * In combined builds, the contents will get replaced post-build
  57. */
  58. .app_hdr : {
  59. . = ALIGN(4k);
  60. __app_hdr = .;
  61. LONG(0xdeaddead)
  62. LONG(0)
  63. LONG(0xdeaddead)
  64. } > FLASH_IMGHDR
  65. .app_bin : {
  66. . = ALIGN(4k);
  67. __app_bin = .;
  68. LONG(0)
  69. } > FLASH_APP
  70. /* The second stage will always enter the image at the start of .text.
  71. The debugger will use the ELF entry point, which is the _entry_point
  72. symbol if present, otherwise defaults to start of .text.
  73. This can be used to transfer control back to the bootrom on debugger
  74. launches only, to perform proper flash setup.
  75. */
  76. .text : {
  77. __logical_binary_start = .;
  78. KEEP (*(.vectors))
  79. KEEP (*(.binary_info_header))
  80. __binary_info_header_end = .;
  81. KEEP (*(.reset))
  82. /* TODO revisit this now memset/memcpy/float in ROM */
  83. /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
  84. * FLASH ... we will include any thing excluded here in .data below by default */
  85. *(.init)
  86. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
  87. *(.fini)
  88. /* Pull all c'tors into .text */
  89. *crtbegin.o(.ctors)
  90. *crtbegin?.o(.ctors)
  91. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  92. *(SORT(.ctors.*))
  93. *(.ctors)
  94. /* Followed by destructors */
  95. *crtbegin.o(.dtors)
  96. *crtbegin?.o(.dtors)
  97. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  98. *(SORT(.dtors.*))
  99. *(.dtors)
  100. *(.eh_frame*)
  101. . = ALIGN(4);
  102. } > FLASH
  103. .rodata : {
  104. *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
  105. . = ALIGN(4);
  106. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
  107. . = ALIGN(4);
  108. } > FLASH
  109. .ARM.extab :
  110. {
  111. *(.ARM.extab* .gnu.linkonce.armextab.*)
  112. } > FLASH
  113. __exidx_start = .;
  114. .ARM.exidx :
  115. {
  116. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  117. } > FLASH
  118. __exidx_end = .;
  119. /* Machine inspectable binary information */
  120. . = ALIGN(4);
  121. __binary_info_start = .;
  122. .binary_info :
  123. {
  124. KEEP(*(.binary_info.keep.*))
  125. *(.binary_info.*)
  126. } > FLASH
  127. __binary_info_end = .;
  128. . = ALIGN(4);
  129. /* End of .text-like segments */
  130. __etext = .;
  131. .ram_vector_table (COPY): {
  132. *(.ram_vector_table)
  133. } > RAM
  134. .data : {
  135. __data_start__ = .;
  136. *(vtable)
  137. *(.time_critical*)
  138. /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
  139. *(.text*)
  140. . = ALIGN(4);
  141. *(.rodata*)
  142. . = ALIGN(4);
  143. *(.data*)
  144. . = ALIGN(4);
  145. *(.after_data.*)
  146. . = ALIGN(4);
  147. /* preinit data */
  148. PROVIDE_HIDDEN (__mutex_array_start = .);
  149. KEEP(*(SORT(.mutex_array.*)))
  150. KEEP(*(.mutex_array))
  151. PROVIDE_HIDDEN (__mutex_array_end = .);
  152. . = ALIGN(4);
  153. /* preinit data */
  154. PROVIDE_HIDDEN (__preinit_array_start = .);
  155. KEEP(*(SORT(.preinit_array.*)))
  156. KEEP(*(.preinit_array))
  157. PROVIDE_HIDDEN (__preinit_array_end = .);
  158. . = ALIGN(4);
  159. /* init data */
  160. PROVIDE_HIDDEN (__init_array_start = .);
  161. KEEP(*(SORT(.init_array.*)))
  162. KEEP(*(.init_array))
  163. PROVIDE_HIDDEN (__init_array_end = .);
  164. . = ALIGN(4);
  165. /* finit data */
  166. PROVIDE_HIDDEN (__fini_array_start = .);
  167. *(SORT(.fini_array.*))
  168. *(.fini_array)
  169. PROVIDE_HIDDEN (__fini_array_end = .);
  170. *(.jcr)
  171. . = ALIGN(4);
  172. /* All data end */
  173. __data_end__ = .;
  174. } > RAM AT> FLASH
  175. .uninitialized_data (COPY): {
  176. . = ALIGN(4);
  177. *(.uninitialized_data*)
  178. } > RAM
  179. /* Start and end symbols must be word-aligned */
  180. .scratch_x : {
  181. __scratch_x_start__ = .;
  182. *(.scratch_x.*)
  183. . = ALIGN(4);
  184. __scratch_x_end__ = .;
  185. } > SCRATCH_X AT > FLASH
  186. __scratch_x_source__ = LOADADDR(.scratch_x);
  187. .scratch_y : {
  188. __scratch_y_start__ = .;
  189. *(.scratch_y.*)
  190. . = ALIGN(4);
  191. __scratch_y_end__ = .;
  192. } > SCRATCH_Y AT > FLASH
  193. __scratch_y_source__ = LOADADDR(.scratch_y);
  194. .bss : {
  195. . = ALIGN(4);
  196. __bss_start__ = .;
  197. *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
  198. *(COMMON)
  199. . = ALIGN(4);
  200. __bss_end__ = .;
  201. } > RAM
  202. .heap (COPY):
  203. {
  204. __end__ = .;
  205. end = __end__;
  206. *(.heap*)
  207. __HeapLimit = .;
  208. } > RAM
  209. /* .stack*_dummy section doesn't contains any symbols. It is only
  210. * used for linker to calculate size of stack sections, and assign
  211. * values to stack symbols later
  212. *
  213. * stack1 section may be empty/missing if platform_launch_core1 is not used */
  214. /* by default we put core 0 stack at the end of scratch Y, so that if core 1
  215. * stack is not used then all of SCRATCH_X is free.
  216. */
  217. .stack1_dummy (COPY):
  218. {
  219. *(.stack1*)
  220. } > SCRATCH_X
  221. .stack_dummy (COPY):
  222. {
  223. *(.stack*)
  224. } > SCRATCH_Y
  225. .flash_end : {
  226. __flash_binary_end = .;
  227. } > FLASH
  228. /* stack limit is poorly named, but historically is maximum heap ptr */
  229. __StackLimit = ORIGIN(RAM) + LENGTH(RAM);
  230. __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
  231. __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
  232. __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
  233. __StackBottom = __StackTop - SIZEOF(.stack_dummy);
  234. PROVIDE(__stack = __StackTop);
  235. /* Check if data + heap + stack exceeds RAM limit */
  236. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
  237. ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
  238. /* todo assert on extra code */
  239. }