1/***************************************************************************//**
2 * Linker script for Silicon Labs EFM32HG devices
3 *******************************************************************************
4 * # License
5 * <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
6 *******************************************************************************
7 *
8 * SPDX-License-Identifier: Zlib
9 *
10 * The licensor of this software is Silicon Laboratories Inc.
11 *
12 * This software is provided 'as-is', without any express or implied
13 * warranty. In no event will the authors be held liable for any damages
14 * arising from the use of this software.
15 *
16 * Permission is granted to anyone to use this software for any purpose,
17 * including commercial applications, and to alter it and redistribute it
18 * freely, subject to the following restrictions:
19 *
20 * 1. The origin of this software must not be misrepresented; you must not
21 *    claim that you wrote the original software. If you use this software
22 *    in a product, an acknowledgment in the product documentation would be
23 *    appreciated but is not required.
24 * 2. Altered source versions must be plainly marked as such, and must not be
25 *    misrepresented as being the original software.
26 * 3. This notice may not be removed or altered from any source distribution.
27 *
28 ******************************************************************************/
29
30MEMORY
31{
32  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 65536
33  RAM (rwx)  : ORIGIN = 0x20000000, LENGTH = 8192
34}
35
36/* Linker script to place sections and symbol values. Should be used together
37 * with other linker script that defines memory regions FLASH and RAM.
38 * It references following symbols, which must be defined in code:
39 *   Reset_Handler : Entry of reset handler
40 *
41 * It defines following symbols, which code can use without definition:
42 *   __exidx_start
43 *   __exidx_end
44 *   __copy_table_start__
45 *   __copy_table_end__
46 *   __zero_table_start__
47 *   __zero_table_end__
48 *   __etext
49 *   __data_start__
50 *   __preinit_array_start
51 *   __preinit_array_end
52 *   __init_array_start
53 *   __init_array_end
54 *   __fini_array_start
55 *   __fini_array_end
56 *   __data_end__
57 *   __bss_start__
58 *   __bss_end__
59 *   __end__
60 *   end
61 *   __HeapBase
62 *   __HeapLimit
63 *   __StackLimit
64 *   __StackTop
65 *   __stack
66 *   __Vectors_End
67 *   __Vectors_Size
68 */
69ENTRY(Reset_Handler)
70
71SECTIONS
72{
73  .text :
74  {
75    KEEP(*(.vectors))
76    __Vectors_End = .;
77    __Vectors_Size = __Vectors_End - __Vectors;
78    __end__ = .;
79
80    *(.text*)
81
82    KEEP(*(.init))
83    KEEP(*(.fini))
84
85    /* .ctors */
86    *crtbegin.o(.ctors)
87    *crtbegin?.o(.ctors)
88    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
89    *(SORT(.ctors.*))
90    *(.ctors)
91
92    /* .dtors */
93    *crtbegin.o(.dtors)
94    *crtbegin?.o(.dtors)
95    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
96    *(SORT(.dtors.*))
97    *(.dtors)
98
99    *(.rodata*)
100
101    KEEP(*(.eh_frame*))
102  } > FLASH
103
104  .ARM.extab :
105  {
106    *(.ARM.extab* .gnu.linkonce.armextab.*)
107  } > FLASH
108
109  __exidx_start = .;
110  .ARM.exidx :
111  {
112    *(.ARM.exidx* .gnu.linkonce.armexidx.*)
113  } > FLASH
114  __exidx_end = .;
115
116  /* To copy multiple ROM to RAM sections,
117   * uncomment .copy.table section and,
118   * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
119  /*
120  .copy.table :
121  {
122    . = ALIGN(4);
123    __copy_table_start__ = .;
124    LONG (__etext)
125    LONG (__data_start__)
126    LONG (__data_end__ - __data_start__)
127    LONG (__etext2)
128    LONG (__data2_start__)
129    LONG (__data2_end__ - __data2_start__)
130    __copy_table_end__ = .;
131  } > FLASH
132  */
133
134  /* To clear multiple BSS sections,
135   * uncomment .zero.table section and,
136   * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
137  /*
138  .zero.table :
139  {
140    . = ALIGN(4);
141    __zero_table_start__ = .;
142    LONG (__bss_start__)
143    LONG (__bss_end__ - __bss_start__)
144    LONG (__bss2_start__)
145    LONG (__bss2_end__ - __bss2_start__)
146    __zero_table_end__ = .;
147  } > FLASH
148  */
149
150  __etext = .;
151
152  .data : AT (__etext)
153  {
154    __data_start__ = .;
155    *(vtable)
156    *(.data*)
157    . = ALIGN (4);
158    PROVIDE (__ram_func_section_start = .);
159    *(.ram)
160    PROVIDE (__ram_func_section_end = .);
161
162    . = ALIGN(4);
163    /* preinit data */
164    PROVIDE_HIDDEN (__preinit_array_start = .);
165    KEEP(*(.preinit_array))
166    PROVIDE_HIDDEN (__preinit_array_end = .);
167
168    . = ALIGN(4);
169    /* init data */
170    PROVIDE_HIDDEN (__init_array_start = .);
171    KEEP(*(SORT(.init_array.*)))
172    KEEP(*(.init_array))
173    PROVIDE_HIDDEN (__init_array_end = .);
174
175    . = ALIGN(4);
176    /* finit data */
177    PROVIDE_HIDDEN (__fini_array_start = .);
178    KEEP(*(SORT(.fini_array.*)))
179    KEEP(*(.fini_array))
180    PROVIDE_HIDDEN (__fini_array_end = .);
181
182    KEEP(*(.jcr*))
183    . = ALIGN(4);
184    /* All data end */
185    __data_end__ = .;
186
187  } > RAM
188
189  .bss :
190  {
191    . = ALIGN(4);
192    __bss_start__ = .;
193    *(.bss*)
194    *(COMMON)
195    . = ALIGN(4);
196    __bss_end__ = .;
197  } > RAM
198
199  .heap (COPY):
200  {
201    __HeapBase = .;
202    __end__ = .;
203    end = __end__;
204    _end = __end__;
205    KEEP(*(.heap*))
206    __HeapLimit = .;
207  } > RAM
208
209  /* .stack_dummy section doesn't contains any symbols. It is only
210   * used for linker to calculate size of stack sections, and assign
211   * values to stack symbols later */
212  .stack_dummy (COPY):
213  {
214    KEEP(*(.stack*))
215  } > RAM
216
217  /* Set stack top to end of RAM, and stack limit move down by
218   * size of stack_dummy section */
219  __StackTop = ORIGIN(RAM) + LENGTH(RAM);
220  __StackLimit = __StackTop - SIZEOF(.stack_dummy);
221  PROVIDE(__stack = __StackTop);
222
223  /* Check if data + heap + stack exceeds RAM limit */
224  ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
225
226  /* Check if FLASH usage exceeds FLASH size */
227  ASSERT( LENGTH(FLASH) >= (__etext + SIZEOF(.data)), "FLASH memory overflowed !")
228}
229