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.8KB

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