gcc_arm.ld 6.8 KB

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