gcc_arm.ld 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /******************************************************************************
  2. * @file gcc_arm.ld
  3. * @brief GNU Linker Script for Cortex-M based device
  4. ******************************************************************************/
  5. /*
  6. * Copyright (c) 2022 Arm Limited. All rights reserved.
  7. *
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the License); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. /*
  23. *-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
  24. */
  25. /*---------------------- Flash Configuration ----------------------------------
  26. <h> Flash Configuration
  27. <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
  28. <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
  29. </h>
  30. -----------------------------------------------------------------------------*/
  31. __ROM_BASE = 0x00000000;
  32. __ROM_SIZE = 0x00040000;
  33. /*--------------------- Embedded RAM Configuration ----------------------------
  34. <h> RAM Configuration
  35. <o0> RAM Base Address <0x0-0xFFFFFFFF:8>
  36. <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
  37. </h>
  38. -----------------------------------------------------------------------------*/
  39. __RAM_BASE = 0x20000000;
  40. __RAM_SIZE = 0x00020000;
  41. /*--------------------- Stack / Heap Configuration ----------------------------
  42. <h> Stack / Heap Configuration
  43. <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  44. <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  45. </h>
  46. -----------------------------------------------------------------------------*/
  47. __STACK_SIZE = 0x00000400;
  48. __HEAP_SIZE = 0x00000C00;
  49. /*
  50. *-------------------- <<< end of configuration section >>> -------------------
  51. */
  52. /* ARMv8-M stack sealing:
  53. to use ARMv8-M stack sealing set __STACKSEAL_SIZE to 8 otherwise keep 0
  54. */
  55. __STACKSEAL_SIZE = 0;
  56. MEMORY
  57. {
  58. FLASH (rx) : ORIGIN = __ROM_BASE, LENGTH = __ROM_SIZE
  59. RAM (rwx) : ORIGIN = __RAM_BASE, LENGTH = __RAM_SIZE
  60. }
  61. /* Linker script to place sections and symbol values. Should be used together
  62. * with other linker script that defines memory regions FLASH and RAM.
  63. * It references following symbols, which must be defined in code:
  64. * Reset_Handler : Entry of reset handler
  65. *
  66. * It defines following symbols, which code can use without definition:
  67. * __exidx_start
  68. * __exidx_end
  69. * __copy_table_start__
  70. * __copy_table_end__
  71. * __zero_table_start__
  72. * __zero_table_end__
  73. * __etext
  74. * __data_start__
  75. * __preinit_array_start
  76. * __preinit_array_end
  77. * __init_array_start
  78. * __init_array_end
  79. * __fini_array_start
  80. * __fini_array_end
  81. * __data_end__
  82. * __bss_start__
  83. * __bss_end__
  84. * __end__
  85. * end
  86. * __HeapLimit
  87. * __StackLimit
  88. * __StackTop
  89. * __stack
  90. * __StackSeal (only if ARMv8-M stack sealing is used)
  91. */
  92. ENTRY(Reset_Handler)
  93. SECTIONS
  94. {
  95. .text :
  96. {
  97. KEEP(*(.vectors))
  98. *(.text*)
  99. KEEP(*(.init))
  100. KEEP(*(.fini))
  101. /* .ctors */
  102. *crtbegin.o(.ctors)
  103. *crtbegin?.o(.ctors)
  104. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  105. *(SORT(.ctors.*))
  106. *(.ctors)
  107. /* .dtors */
  108. *crtbegin.o(.dtors)
  109. *crtbegin?.o(.dtors)
  110. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  111. *(SORT(.dtors.*))
  112. *(.dtors)
  113. *(.rodata*)
  114. KEEP(*(.eh_frame*))
  115. } > FLASH
  116. /*
  117. * SG veneers:
  118. * All SG veneers are placed in the special output section .gnu.sgstubs. Its start address
  119. * must be set, either with the command line option ‘--section-start’ or in a linker script,
  120. * to indicate where to place these veneers in memory.
  121. */
  122. /*
  123. .gnu.sgstubs :
  124. {
  125. . = ALIGN(32);
  126. } > FLASH
  127. */
  128. .ARM.extab :
  129. {
  130. *(.ARM.extab* .gnu.linkonce.armextab.*)
  131. } > FLASH
  132. __exidx_start = .;
  133. .ARM.exidx :
  134. {
  135. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  136. } > FLASH
  137. __exidx_end = .;
  138. .copy.table :
  139. {
  140. . = ALIGN(4);
  141. __copy_table_start__ = .;
  142. LONG (__etext)
  143. LONG (__data_start__)
  144. LONG ((__data_end__ - __data_start__) / 4)
  145. /* Add each additional data section here */
  146. /*
  147. LONG (__etext2)
  148. LONG (__data2_start__)
  149. LONG ((__data2_end__ - __data2_start__) / 4)
  150. */
  151. __copy_table_end__ = .;
  152. } > FLASH
  153. .zero.table :
  154. {
  155. . = ALIGN(4);
  156. __zero_table_start__ = .;
  157. /* Add each additional bss section here */
  158. /*
  159. LONG (__bss2_start__)
  160. LONG ((__bss2_end__ - __bss2_start__) / 4)
  161. */
  162. __zero_table_end__ = .;
  163. } > FLASH
  164. /**
  165. * Location counter can end up 2byte aligned with narrow Thumb code but
  166. * __etext is assumed by startup code to be the LMA of a section in RAM
  167. * which must be 4byte aligned
  168. */
  169. __etext = ALIGN (4);
  170. .data : AT (__etext)
  171. {
  172. __data_start__ = .;
  173. *(vtable)
  174. *(.data)
  175. *(.data.*)
  176. . = ALIGN(4);
  177. /* preinit data */
  178. PROVIDE_HIDDEN (__preinit_array_start = .);
  179. KEEP(*(.preinit_array))
  180. PROVIDE_HIDDEN (__preinit_array_end = .);
  181. . = ALIGN(4);
  182. /* init data */
  183. PROVIDE_HIDDEN (__init_array_start = .);
  184. KEEP(*(SORT(.init_array.*)))
  185. KEEP(*(.init_array))
  186. PROVIDE_HIDDEN (__init_array_end = .);
  187. . = ALIGN(4);
  188. /* finit data */
  189. PROVIDE_HIDDEN (__fini_array_start = .);
  190. KEEP(*(SORT(.fini_array.*)))
  191. KEEP(*(.fini_array))
  192. PROVIDE_HIDDEN (__fini_array_end = .);
  193. KEEP(*(.jcr*))
  194. . = ALIGN(4);
  195. /* All data end */
  196. __data_end__ = .;
  197. } > RAM
  198. /*
  199. * Secondary data section, optional
  200. *
  201. * Remember to add each additional data section
  202. * to the .copy.table above to asure proper
  203. * initialization during startup.
  204. */
  205. /*
  206. __etext2 = ALIGN (4);
  207. .data2 : AT (__etext2)
  208. {
  209. . = ALIGN(4);
  210. __data2_start__ = .;
  211. *(.data2)
  212. *(.data2.*)
  213. . = ALIGN(4);
  214. __data2_end__ = .;
  215. } > RAM2
  216. */
  217. .bss :
  218. {
  219. . = ALIGN(4);
  220. __bss_start__ = .;
  221. *(.bss)
  222. *(.bss.*)
  223. *(COMMON)
  224. . = ALIGN(4);
  225. __bss_end__ = .;
  226. } > RAM AT > RAM
  227. /*
  228. * Secondary bss section, optional
  229. *
  230. * Remember to add each additional bss section
  231. * to the .zero.table above to asure proper
  232. * initialization during startup.
  233. */
  234. /*
  235. .bss2 :
  236. {
  237. . = ALIGN(4);
  238. __bss2_start__ = .;
  239. *(.bss2)
  240. *(.bss2.*)
  241. . = ALIGN(4);
  242. __bss2_end__ = .;
  243. } > RAM2 AT > RAM2
  244. */
  245. .heap (COPY) :
  246. {
  247. . = ALIGN(8);
  248. __end__ = .;
  249. PROVIDE(end = .);
  250. . = . + __HEAP_SIZE;
  251. . = ALIGN(8);
  252. __HeapLimit = .;
  253. } > RAM
  254. .stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE - __STACKSEAL_SIZE) (COPY) :
  255. {
  256. . = ALIGN(8);
  257. __StackLimit = .;
  258. . = . + __STACK_SIZE;
  259. . = ALIGN(8);
  260. __StackTop = .;
  261. } > RAM
  262. PROVIDE(__stack = __StackTop);
  263. /* ARMv8-M stack sealing:
  264. to use ARMv8-M stack sealing uncomment '.stackseal' section
  265. */
  266. /*
  267. .stackseal (ORIGIN(RAM) + LENGTH(RAM) - __STACKSEAL_SIZE) (COPY) :
  268. {
  269. . = ALIGN(8);
  270. __StackSeal = .;
  271. . = . + 8;
  272. . = ALIGN(8);
  273. } > RAM
  274. */
  275. /* Check if data + heap + stack exceeds RAM limit */
  276. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
  277. }