1/***************************************************************************//**
2 * Linker script for Silicon Labs EFM32JG12B 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
30
31MEMORY
32{
33  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1048576
34  RAM (rwx)  : ORIGIN = 0x20000000, LENGTH = 262144
35}
36
37/* Linker script to place sections and symbol values. Should be used together
38 * with other linker script that defines memory regions FLASH and RAM.
39 * It references following symbols, which must be defined in code:
40 *   Reset_Handler : Entry of reset handler
41 *
42 * It defines following symbols, which code can use without definition:
43 *   __exidx_start
44 *   __exidx_end
45 *   __copy_table_start__
46 *   __copy_table_end__
47 *   __zero_table_start__
48 *   __zero_table_end__
49 *   __etext
50 *   __data_start__
51 *   __preinit_array_start
52 *   __preinit_array_end
53 *   __init_array_start
54 *   __init_array_end
55 *   __fini_array_start
56 *   __fini_array_end
57 *   __data_end__
58 *   __bss_start__
59 *   __bss_end__
60 *   __end__
61 *   end
62 *   __HeapBase
63 *   __HeapLimit
64 *   __StackLimit
65 *   __StackTop
66 *   __stack
67 *   __Vectors_End
68 *   __Vectors_Size
69 */
70ENTRY(Reset_Handler)
71
72SECTIONS
73{
74  .text :
75  {
76    KEEP(*(.vectors))
77    __Vectors_End = .;
78    __Vectors_Size = __Vectors_End - __Vectors;
79    __end__ = .;
80
81    *(.text*)
82
83    KEEP(*(.init))
84    KEEP(*(.fini))
85
86    /* .ctors */
87    *crtbegin.o(.ctors)
88    *crtbegin?.o(.ctors)
89    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
90    *(SORT(.ctors.*))
91    *(.ctors)
92
93    /* .dtors */
94    *crtbegin.o(.dtors)
95    *crtbegin?.o(.dtors)
96    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
97    *(SORT(.dtors.*))
98    *(.dtors)
99
100    *(.rodata*)
101
102    KEEP(*(.eh_frame*))
103  } > FLASH
104
105  .ARM.extab :
106  {
107    *(.ARM.extab* .gnu.linkonce.armextab.*)
108  } > FLASH
109
110  __exidx_start = .;
111  .ARM.exidx :
112  {
113    *(.ARM.exidx* .gnu.linkonce.armexidx.*)
114  } > FLASH
115  __exidx_end = .;
116
117  /* To copy multiple ROM to RAM sections,
118   * uncomment .copy.table section and,
119   * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
120  /*
121  .copy.table :
122  {
123    . = ALIGN(4);
124    __copy_table_start__ = .;
125    LONG (__etext)
126    LONG (__data_start__)
127    LONG (__data_end__ - __data_start__)
128    LONG (__etext2)
129    LONG (__data2_start__)
130    LONG (__data2_end__ - __data2_start__)
131    __copy_table_end__ = .;
132  } > FLASH
133  */
134
135  /* To clear multiple BSS sections,
136   * uncomment .zero.table section and,
137   * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
138  /*
139  .zero.table :
140  {
141    . = ALIGN(4);
142    __zero_table_start__ = .;
143    LONG (__bss_start__)
144    LONG (__bss_end__ - __bss_start__)
145    LONG (__bss2_start__)
146    LONG (__bss2_end__ - __bss2_start__)
147    __zero_table_end__ = .;
148  } > FLASH
149  */
150
151  __etext = .;
152
153  .data : AT (__etext)
154  {
155    __data_start__ = .;
156    *(vtable)
157    *(.data*)
158    . = ALIGN (4);
159    PROVIDE (__ram_func_section_start = .);
160    *(.ram)
161    PROVIDE (__ram_func_section_end = .);
162
163    . = ALIGN(4);
164    /* preinit data */
165    PROVIDE_HIDDEN (__preinit_array_start = .);
166    KEEP(*(.preinit_array))
167    PROVIDE_HIDDEN (__preinit_array_end = .);
168
169    . = ALIGN(4);
170    /* init data */
171    PROVIDE_HIDDEN (__init_array_start = .);
172    KEEP(*(SORT(.init_array.*)))
173    KEEP(*(.init_array))
174    PROVIDE_HIDDEN (__init_array_end = .);
175
176    . = ALIGN(4);
177    /* finit data */
178    PROVIDE_HIDDEN (__fini_array_start = .);
179    KEEP(*(SORT(.fini_array.*)))
180    KEEP(*(.fini_array))
181    PROVIDE_HIDDEN (__fini_array_end = .);
182
183    KEEP(*(.jcr*))
184    . = ALIGN(4);
185    /* All data end */
186    __data_end__ = .;
187
188  } > RAM
189
190  .bss :
191  {
192    . = ALIGN(4);
193    __bss_start__ = .;
194    *(.bss*)
195    *(COMMON)
196    . = ALIGN(4);
197    __bss_end__ = .;
198  } > RAM
199
200  .heap (COPY):
201  {
202    __HeapBase = .;
203    __end__ = .;
204    end = __end__;
205    _end = __end__;
206    KEEP(*(.heap*))
207    __HeapLimit = .;
208  } > RAM
209
210  /* .stack_dummy section doesn't contains any symbols. It is only
211   * used for linker to calculate size of stack sections, and assign
212   * values to stack symbols later */
213  .stack_dummy (COPY):
214  {
215    KEEP(*(.stack*))
216  } > RAM
217
218  /* Set stack top to end of RAM, and stack limit move down by
219   * size of stack_dummy section */
220  __StackTop = ORIGIN(RAM) + LENGTH(RAM);
221  __StackLimit = __StackTop - SIZEOF(.stack_dummy);
222  PROVIDE(__stack = __StackTop);
223
224  /* Check if data + heap + stack exceeds RAM limit */
225  ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
226
227  /* Check if FLASH usage exceeds FLASH size */
228  ASSERT( LENGTH(FLASH) >= (__etext + SIZEOF(.data)), "FLASH memory overflowed !")
229}
230