lnk.ld 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_ARMCM4.h"
  25. __STACK_SIZE = 0x2000;
  26. __HEAP_SIZE = 0x50000;
  27. MEMORY
  28. {
  29. ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 512K
  30. DTCM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
  31. DTCM2 (xrw) : ORIGIN = 0x20020000, LENGTH = 384K
  32. }
  33. ENTRY(Reset_Handler)
  34. SECTIONS
  35. {
  36. .text :
  37. {
  38. KEEP(*(.vectors))
  39. *(.text*)
  40. KEEP(*(.init))
  41. KEEP(*(.fini))
  42. /* .ctors */
  43. *crtbegin.o(.ctors)
  44. *crtbegin?.o(.ctors)
  45. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  46. *(SORT(.ctors.*))
  47. *(.ctors)
  48. /* .dtors */
  49. *crtbegin.o(.dtors)
  50. *crtbegin?.o(.dtors)
  51. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  52. *(SORT(.dtors.*))
  53. *(.dtors)
  54. *(.rodata*)
  55. KEEP(*(.eh_frame*))
  56. } > ITCM
  57. /*
  58. * SG veneers:
  59. * All SG veneers are placed in the special output section .gnu.sgstubs. Its start address
  60. * must be set, either with the command line option ‘--section-start’ or in a linker script,
  61. * to indicate where to place these veneers in memory.
  62. */
  63. /*
  64. .gnu.sgstubs :
  65. {
  66. . = ALIGN(32);
  67. } > FLASH
  68. */
  69. .ARM.extab :
  70. {
  71. *(.ARM.extab* .gnu.linkonce.armextab.*)
  72. } > ITCM
  73. __exidx_start = .;
  74. .ARM.exidx :
  75. {
  76. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  77. } > ITCM
  78. __exidx_end = .;
  79. .copy.table :
  80. {
  81. . = ALIGN(4);
  82. __copy_table_start__ = .;
  83. LONG (__etext)
  84. LONG (__data_start__)
  85. LONG (__data_end__ - __data_start__)
  86. /* Add each additional data section here */
  87. /*
  88. LONG (__etext2)
  89. LONG (__data2_start__)
  90. LONG (__data2_end__ - __data2_start__)
  91. */
  92. __copy_table_end__ = .;
  93. } > ITCM
  94. .zero.table :
  95. {
  96. . = ALIGN(4);
  97. __zero_table_start__ = .;
  98. /* Add each additional bss section here */
  99. /*
  100. LONG (__bss2_start__)
  101. LONG (__bss2_end__ - __bss2_start__)
  102. */
  103. __zero_table_end__ = .;
  104. } > DTCM
  105. /**
  106. * Location counter can end up 2byte aligned with narrow Thumb code but
  107. * __etext is assumed by startup code to be the LMA of a section in RAM
  108. * which must be 4byte aligned
  109. */
  110. .data :
  111. {
  112. __data_start__ = .;
  113. *(vtable)
  114. *(.data)
  115. *(.data.*)
  116. . = ALIGN(4);
  117. /* preinit data */
  118. PROVIDE_HIDDEN (__preinit_array_start = .);
  119. KEEP(*(.preinit_array))
  120. PROVIDE_HIDDEN (__preinit_array_end = .);
  121. . = ALIGN(4);
  122. /* init data */
  123. PROVIDE_HIDDEN (__init_array_start = .);
  124. KEEP(*(SORT(.init_array.*)))
  125. KEEP(*(.init_array))
  126. PROVIDE_HIDDEN (__init_array_end = .);
  127. . = ALIGN(4);
  128. /* finit data */
  129. PROVIDE_HIDDEN (__fini_array_start = .);
  130. KEEP(*(SORT(.fini_array.*)))
  131. KEEP(*(.fini_array))
  132. PROVIDE_HIDDEN (__fini_array_end = .);
  133. KEEP(*(.jcr*))
  134. . = ALIGN(4);
  135. /* All data end */
  136. __data_end__ = .;
  137. } > ITCM AT > DTCM
  138. __etext = ADDR(.data);
  139. /*
  140. * Secondary data section, optional
  141. *
  142. * Remember to add each additional data section
  143. * to the .copy.table above to asure proper
  144. * initialization during startup.
  145. */
  146. /*
  147. __etext2 = ALIGN (4);
  148. .data2 : AT (__etext2)
  149. {
  150. . = ALIGN(4);
  151. __data2_start__ = .;
  152. *(.data2)
  153. *(.data2.*)
  154. . = ALIGN(4);
  155. __data2_end__ = .;
  156. } > RAM2
  157. */
  158. .bss :
  159. {
  160. . = ALIGN(4);
  161. __bss_start__ = .;
  162. *(.bss)
  163. *(.bss.*)
  164. *(COMMON)
  165. . = ALIGN(4);
  166. __bss_end__ = .;
  167. } > DTCM2
  168. /*
  169. * Secondary bss section, optional
  170. *
  171. * Remember to add each additional bss section
  172. * to the .zero.table above to asure proper
  173. * initialization during startup.
  174. */
  175. /*
  176. .bss2 :
  177. {
  178. . = ALIGN(4);
  179. __bss2_start__ = .;
  180. *(.bss2)
  181. *(.bss2.*)
  182. . = ALIGN(4);
  183. __bss2_end__ = .;
  184. } > RAM2 AT > RAM2
  185. */
  186. .heap (COPY) :
  187. {
  188. . = ALIGN(8);
  189. __end__ = .;
  190. PROVIDE(end = .);
  191. __HeapBase = .;
  192. . = . + __HEAP_SIZE;
  193. . = ALIGN(8);
  194. __HeapLimit = .;
  195. } > DTCM2
  196. .stack (ORIGIN(DTCM2) + LENGTH(DTCM2) - __STACK_SIZE) (COPY) :
  197. {
  198. . = ALIGN(8);
  199. __StackLimit = .;
  200. . = . + __STACK_SIZE;
  201. . = ALIGN(8);
  202. __StackTop = .;
  203. } > DTCM2
  204. PROVIDE(__stack = __StackTop);
  205. /* Check if data + heap + stack exceeds DTCM2 limit */
  206. ASSERT(__StackLimit >= __HeapLimit, "region DTCM2 overflowed with stack")
  207. }