gcc_arm.ld 7.3 KB

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