1
2/* Linker script to place sections and symbol values. Should be used together
3 * with other linker script that defines memory regions FLASH and RAM.
4 * It references following symbols, which must be defined in code:
5 *   Reset_Handler : Entry of reset handler
6 *
7 * It defines following symbols, which code can use without definition:
8 *   __exidx_start
9 *   __exidx_end
10 *   __copy_table_start__
11 *   __copy_table_end__
12 *   __zero_table_start__
13 *   __zero_table_end__
14 *   __etext
15 *   __data_start__
16 *   __preinit_array_start
17 *   __preinit_array_end
18 *   __init_array_start
19 *   __init_array_end
20 *   __fini_array_start
21 *   __fini_array_end
22 *   __data_end__
23 *   __bss_start__
24 *   __bss_end__
25 *   __end__
26 *   end
27 *   __HeapLimit
28 *   __StackLimit
29 *   __StackTop
30 *   __stack
31 */
32ENTRY(Reset_Handler)
33
34SECTIONS
35{
36    .text :
37    {
38        KEEP(*(.isr_vector))
39        *(.text*)
40
41        KEEP(*(.init))
42        KEEP(*(.fini))
43
44        /* .ctors */
45        *crtbegin.o(.ctors)
46        *crtbegin?.o(.ctors)
47        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
48        *(SORT(.ctors.*))
49        *(.ctors)
50
51        /* .dtors */
52        *crtbegin.o(.dtors)
53        *crtbegin?.o(.dtors)
54        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
55        *(SORT(.dtors.*))
56        *(.dtors)
57
58        *(.rodata*)
59
60        KEEP(*(.eh_frame*))
61    } > FLASH
62
63    .ARM.extab :
64    {
65        *(.ARM.extab* .gnu.linkonce.armextab.*)
66    } > FLASH
67
68    __exidx_start = .;
69    .ARM.exidx :
70    {
71        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
72    } > FLASH
73    __exidx_end = .;
74
75    /* To copy multiple ROM to RAM sections,
76     * uncomment .copy.table section and,
77     * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
78
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        __copy_table_end__ = .;
87    } > FLASH
88
89
90    /* To clear multiple BSS sections,
91     * uncomment .zero.table section and,
92     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
93    .zero.table :
94    {
95        . = ALIGN(4);
96        __zero_table_start__ = .;
97        LONG (__bss_start__)
98        LONG (__bss_end__ - __bss_start__)
99        __zero_table_end__ = .;
100    } > FLASH
101
102    __etext = .;
103
104    .data : AT (__etext)
105    {
106        __data_start__ = .;
107        *(vtable)
108        *(.data*)
109
110        . = ALIGN(4);
111        /* preinit data */
112        PROVIDE_HIDDEN (__preinit_array_start = .);
113        KEEP(*(.preinit_array))
114        PROVIDE_HIDDEN (__preinit_array_end = .);
115
116        . = ALIGN(4);
117        /* init data */
118        PROVIDE_HIDDEN (__init_array_start = .);
119        KEEP(*(SORT(.init_array.*)))
120        KEEP(*(.init_array))
121        PROVIDE_HIDDEN (__init_array_end = .);
122
123
124        . = ALIGN(4);
125        /* finit data */
126        PROVIDE_HIDDEN (__fini_array_start = .);
127        KEEP(*(SORT(.fini_array.*)))
128        KEEP(*(.fini_array))
129        PROVIDE_HIDDEN (__fini_array_end = .);
130
131        KEEP(*(.jcr*))
132        . = ALIGN(4);
133        /* All data end */
134        __data_end__ = .;
135
136    } > RAM
137
138    .bss :
139    {
140        . = ALIGN(4);
141        __bss_start__ = .;
142        *(.bss*)
143        *(COMMON)
144        . = ALIGN(4);
145        __bss_end__ = .;
146    } > RAM
147
148    .heap (COPY):
149    {
150        __end__ = .;
151        PROVIDE(end = .);
152        *(.heap*)
153        __HeapLimit = .;
154    } > RAM
155
156    /* .stack_dummy section doesn't contains any symbols. It is only
157     * used for linker to calculate size of stack sections, and assign
158     * values to stack symbols later */
159    .stack_dummy (COPY):
160    {
161        *(.stack*)
162    } > RAM
163
164    /* Set stack top to end of RAM, and stack limit move down by
165     * size of stack_dummy section */
166    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
167    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
168    PROVIDE(__stack = __StackTop);
169
170    /* Check if data + heap + stack exceeds RAM limit */
171    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
172}
173