|
1 /* Linker script to configure memory regions. */ |
|
2 /* |
|
3 * SPDX-License-Identifier: BSD-3-Clause |
|
4 ****************************************************************************** |
|
5 * @attention |
|
6 * |
|
7 * Copyright (c) 2016-2020 STMicroelectronics. |
|
8 * All rights reserved. |
|
9 * |
|
10 * This software component is licensed by ST under BSD 3-Clause license, |
|
11 * the "License"; You may not use this file except in compliance with the |
|
12 * License. You may obtain a copy of the License at: |
|
13 * opensource.org/licenses/BSD-3-Clause |
|
14 * |
|
15 ****************************************************************************** |
|
16 */ |
|
17 |
|
18 #include "cmsis_nvic.h" |
|
19 |
|
20 |
|
21 #if !defined(MBED_APP_START) |
|
22 #define MBED_APP_START MBED_ROM_START |
|
23 #endif |
|
24 |
|
25 #if !defined(MBED_APP_SIZE) |
|
26 #define MBED_APP_SIZE MBED_ROM_SIZE |
|
27 #endif |
|
28 |
|
29 #if !defined(MBED_BOOT_STACK_SIZE) |
|
30 /* This value is normally defined by the tools |
|
31 to 0x1000 for bare metal and 0x400 for RTOS */ |
|
32 #define MBED_BOOT_STACK_SIZE 0x400 |
|
33 #endif |
|
34 |
|
35 /* Round up VECTORS_SIZE to 8 bytes */ |
|
36 #define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8) |
|
37 |
|
38 MEMORY |
|
39 { |
|
40 FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE |
|
41 RAM (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE |
|
42 } |
|
43 |
|
44 /* Linker script to place sections and symbol values. Should be used together |
|
45 * with other linker script that defines memory regions FLASH and RAM. |
|
46 * It references following symbols, which must be defined in code: |
|
47 * Reset_Handler : Entry of reset handler |
|
48 * |
|
49 * It defines following symbols, which code can use without definition: |
|
50 * __exidx_start |
|
51 * __exidx_end |
|
52 * __etext |
|
53 * __data_start__ |
|
54 * __preinit_array_start |
|
55 * __preinit_array_end |
|
56 * __init_array_start |
|
57 * __init_array_end |
|
58 * __fini_array_start |
|
59 * __fini_array_end |
|
60 * __data_end__ |
|
61 * __bss_start__ |
|
62 * __bss_end__ |
|
63 * __end__ |
|
64 * end |
|
65 * __HeapLimit |
|
66 * __StackLimit |
|
67 * __StackTop |
|
68 * __stack |
|
69 * _estack |
|
70 */ |
|
71 ENTRY(Reset_Handler) |
|
72 |
|
73 SECTIONS |
|
74 { |
|
75 .text : |
|
76 { |
|
77 KEEP(*(.isr_vector)) |
|
78 *(.text*) |
|
79 |
|
80 KEEP(*(.init)) |
|
81 KEEP(*(.fini)) |
|
82 |
|
83 /* .ctors */ |
|
84 *crtbegin.o(.ctors) |
|
85 *crtbegin?.o(.ctors) |
|
86 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) |
|
87 *(SORT(.ctors.*)) |
|
88 *(.ctors) |
|
89 |
|
90 /* .dtors */ |
|
91 *crtbegin.o(.dtors) |
|
92 *crtbegin?.o(.dtors) |
|
93 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) |
|
94 *(SORT(.dtors.*)) |
|
95 *(.dtors) |
|
96 |
|
97 *(.rodata*) |
|
98 |
|
99 KEEP(*(.eh_frame*)) |
|
100 } > FLASH |
|
101 |
|
102 .ARM.extab : |
|
103 { |
|
104 *(.ARM.extab* .gnu.linkonce.armextab.*) |
|
105 } > FLASH |
|
106 |
|
107 __exidx_start = .; |
|
108 .ARM.exidx : |
|
109 { |
|
110 *(.ARM.exidx* .gnu.linkonce.armexidx.*) |
|
111 } > FLASH |
|
112 __exidx_end = .; |
|
113 |
|
114 __etext = .; |
|
115 _sidata = .; |
|
116 |
|
117 .data : AT (__etext) |
|
118 { |
|
119 __data_start__ = .; |
|
120 _sdata = .; |
|
121 *(vtable) |
|
122 *(.data*) |
|
123 |
|
124 . = ALIGN(8); |
|
125 /* preinit data */ |
|
126 PROVIDE_HIDDEN (__preinit_array_start = .); |
|
127 KEEP(*(.preinit_array)) |
|
128 PROVIDE_HIDDEN (__preinit_array_end = .); |
|
129 |
|
130 . = ALIGN(8); |
|
131 /* init data */ |
|
132 PROVIDE_HIDDEN (__init_array_start = .); |
|
133 KEEP(*(SORT(.init_array.*))) |
|
134 KEEP(*(.init_array)) |
|
135 PROVIDE_HIDDEN (__init_array_end = .); |
|
136 |
|
137 . = ALIGN(8); |
|
138 /* finit data */ |
|
139 PROVIDE_HIDDEN (__fini_array_start = .); |
|
140 KEEP(*(SORT(.fini_array.*))) |
|
141 KEEP(*(.fini_array)) |
|
142 PROVIDE_HIDDEN (__fini_array_end = .); |
|
143 |
|
144 KEEP(*(.jcr*)) |
|
145 . = ALIGN(8); |
|
146 /* All data end */ |
|
147 __data_end__ = .; |
|
148 _edata = .; |
|
149 |
|
150 } > RAM |
|
151 |
|
152 /* Uninitialized data section |
|
153 * This region is not initialized by the C/C++ library and can be used to |
|
154 * store state across soft reboots. */ |
|
155 .uninitialized (NOLOAD): |
|
156 { |
|
157 . = ALIGN(32); |
|
158 __uninitialized_start = .; |
|
159 *(.uninitialized) |
|
160 KEEP(*(.keep.uninitialized)) |
|
161 . = ALIGN(32); |
|
162 __uninitialized_end = .; |
|
163 } > RAM |
|
164 |
|
165 .bss : |
|
166 { |
|
167 . = ALIGN(8); |
|
168 __bss_start__ = .; |
|
169 _sbss = .; |
|
170 *(.bss*) |
|
171 *(COMMON) |
|
172 . = ALIGN(8); |
|
173 __bss_end__ = .; |
|
174 _ebss = .; |
|
175 } > RAM |
|
176 |
|
177 .heap (COPY): |
|
178 { |
|
179 __end__ = .; |
|
180 PROVIDE(end = .); |
|
181 *(.heap*) |
|
182 . = ORIGIN(RAM) + LENGTH(RAM) - MBED_BOOT_STACK_SIZE; |
|
183 __HeapLimit = .; |
|
184 } > RAM |
|
185 |
|
186 /* .stack_dummy section doesn't contains any symbols. It is only |
|
187 * used for linker to calculate size of stack sections, and assign |
|
188 * values to stack symbols later */ |
|
189 .stack_dummy (COPY): |
|
190 { |
|
191 *(.stack*) |
|
192 } > RAM |
|
193 |
|
194 /* Set stack top to end of RAM, and stack limit move down by |
|
195 * size of stack_dummy section */ |
|
196 __StackTop = ORIGIN(RAM) + LENGTH(RAM); |
|
197 _estack = __StackTop; |
|
198 __StackLimit = __StackTop - MBED_BOOT_STACK_SIZE; |
|
199 PROVIDE(__stack = __StackTop); |
|
200 |
|
201 /* Check if data + heap + stack exceeds RAM limit */ |
|
202 ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") |
|
203 } |