lnk.ld 6.8 KB

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