gcc_arm.ld 6.9 KB

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