Skip to content

Commit a4c2900

Browse files
author
Amanda Butler
authored
Merge pull request #951 from deepikabhavnani/heap_stack_2_region
Update the bootstrap document with 2-region memory model
2 parents 4a657f1 + 586b7c3 commit a4c2900

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

docs/porting/target/bootstrap.md

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you are updating your own linker script, you must:
1818

1919
- Reserve space for the RAM vector table.
2020
- Define the heap region:
21-
- Arm - The heap starts immediately after the region `RW_IRAM1` and ends at the start of the `ARM_LIB_STACK` region.
21+
- Arm - The heap is the `ARM_LIB_HEAP` region.
2222
- GCC_ARM - The heap starts at the symbol `__end__` and ends at the `__HeapLimit` symbol.
2323
- IAR - The heap is the `HEAP` region.
2424
- Define the boot stack region:
@@ -38,43 +38,44 @@ Arm linker script template:
3838
3939
/* Device specific values */
4040
41-
#define ROM_START 0x08000000
42-
#define ROM_SIZE 0x200000
43-
#define RAM_START 0x20000000
44-
#define RAM_SIZE 0x30000
45-
#define VECTORS 107 /* This value must match NVIC_NUM_VECTORS */
41+
/* Tools provide -DMBED_ROM_START=xxx -DMBED_ROM_SIZE=xxx -DMBED_RAM_START=xxx -DMBED_RAM_SIZE=xxx */
42+
43+
#define VECTORS xx /* This value must match NVIC_NUM_VECTORS */
4644
4745
/* Common - Do not change */
4846
4947
#if !defined(MBED_APP_START)
50-
#define MBED_APP_START ROM_START
48+
#define MBED_APP_START MBED_ROM_START
5149
#endif
5250
5351
#if !defined(MBED_APP_SIZE)
54-
#define MBED_APP_SIZE ROM_SIZE
52+
#define MBED_APP_SIZE MBED_ROM_SIZE
5553
#endif
5654
5755
#if !defined(MBED_BOOT_STACK_SIZE)
58-
/* This value is normally defined by the tools
59-
to 0x400 for mbed 2 and 0x1000 for mbed 5 */
60-
#define MBED_BOOT_STACK_SIZE 0x1000
56+
/* This value is normally defined by the tools to 0x1000 for bare metal and 0x400 for RTOS */
57+
#define MBED_BOOT_STACK_SIZE 0x400
6158
#endif
6259
6360
/* Round up VECTORS_SIZE to 8 bytes */
64-
#define VECTORS_SIZE (((VECTORS * 4) + 7) AND ~7)
61+
#define VECTORS_SIZE (((VECTORS * 4) + 7) AND ~7)
6562
66-
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
63+
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
6764
68-
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
65+
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
6966
*.o (RESET, +First)
7067
*(InRoot$$Sections)
7168
.ANY (+RO)
7269
}
7370
74-
RW_IRAM1 (RAM_START + VECTORS_SIZE) (RAM_SIZE - VECTORS_SIZE - MBED_BOOT_STACK_SIZE) { ; RW data
71+
RW_IRAM1 (RAM_START + VECTORS_SIZE) { ; RW data
7572
.ANY (+RW +ZI)
7673
}
77-
ARM_LIB_STACK (RAM_START + RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; Stack region growing down
74+
75+
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_START + MBED_RAM_SIZE - MBED_BOOT_STACK_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up
76+
}
77+
78+
ARM_LIB_STACK (RAM_START + RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; Stack region growing down
7879
}
7980
}
8081
```
@@ -84,33 +85,31 @@ IAR linker script template:
8485
```
8586
/* Device specific values */
8687
87-
define symbol ROM_START = 0x08000000;
88-
define symbol ROM_SIZE = 0x200000;
89-
define symbol RAM_START = 0x20000000;
90-
define symbol RAM_SIZE = 0x30000;
91-
define symbol VECTORS = 107; /* This value must match NVIC_NUM_VECTORS */
88+
/* Tools provide -DMBED_ROM_START=xxx -DMBED_ROM_SIZE=xxx -DMBED_RAM_START=xxx -DMBED_RAM_SIZE=xxx */
89+
90+
define symbol VECTORS = xx; /* This value must match NVIC_NUM_VECTORS */
9291
define symbol HEAP_SIZE = 0x10000;
9392
9493
/* Common - Do not change */
9594
9695
if (!isdefinedsymbol(MBED_APP_START)) {
97-
define symbol MBED_APP_START = ROM_START;
96+
define symbol MBED_APP_START = MBED_ROM_START;
9897
}
9998
10099
if (!isdefinedsymbol(MBED_APP_SIZE)) {
101-
define symbol MBED_APP_SIZE = ROM_SIZE;
100+
define symbol MBED_APP_SIZE = MBED_ROM_SIZE;
102101
}
103102
104103
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
105104
/* This value is normally defined by the tools
106-
to 0x400 for mbed 2 and 0x1000 for mbed 5 */
107-
define symbol MBED_BOOT_STACK_SIZE = 0x1000;
105+
to 0x1000 for bare metal and 0x400 for RTOS */
106+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
108107
}
109108
110109
/* Round up VECTORS_SIZE to 8 bytes */
111110
define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7;
112-
define symbol RAM_REGION_START = RAM_START + VECTORS_SIZE;
113-
define symbol RAM_REGION_SIZE = RAM_SIZE - VECTORS_SIZE;
111+
define symbol RAM_REGION_START = MBED_RAM_START + VECTORS_SIZE;
112+
define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE;
114113
115114
define memory mem with size = 4G;
116115
define region ROM_region = mem:[from MBED_APP_START size MBED_APP_SIZE];
@@ -135,26 +134,24 @@ GCC linker script template:
135134
```
136135
/* Device specific values */
137136
138-
#define ROM_START 0x08000000
139-
#define ROM_SIZE 0x200000
140-
#define RAM_START 0x20000000
141-
#define RAM_SIZE 0x30000
142-
#define VECTORS 107 /* This value must match NVIC_NUM_VECTORS */
137+
/* Tools provide -DMBED_ROM_START=xxx -DMBED_ROM_SIZE=xxx -DMBED_RAM_START=xxx -DMBED_RAM_SIZE=xxx */
138+
139+
#define VECTORS xx /* This value must match NVIC_NUM_VECTORS */
143140
144141
/* Common - Do not change */
145142
146143
#if !defined(MBED_APP_START)
147-
#define MBED_APP_START ROM_START
144+
#define MBED_APP_START MBED_ROM_START
148145
#endif
149146
150147
#if !defined(MBED_APP_SIZE)
151-
#define MBED_APP_SIZE ROM_SIZE
148+
#define MBED_APP_SIZE MBED_ROM_SIZE
152149
#endif
153150
154151
#if !defined(MBED_BOOT_STACK_SIZE)
155152
/* This value is normally defined by the tools
156-
to 0x400 for mbed 2 and 0x1000 for mbed 5 */
157-
#define MBED_BOOT_STACK_SIZE 0x1000
153+
to 0x1000 for bare metal and 0x400 for RTOS */
154+
#define MBED_BOOT_STACK_SIZE 0x400
158155
#endif
159156
160157
/* Round up VECTORS_SIZE to 8 bytes */
@@ -163,7 +160,7 @@ GCC linker script template:
163160
MEMORY
164161
{
165162
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
166-
RAM (rwx) : ORIGIN = RAM_START + VECTORS_SIZE, LENGTH = RAM_SIZE - VECTORS_SIZE
163+
RAM (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE
167164
}
168165
169166
/* Linker script to place sections and symbol values. Should be used together
@@ -237,50 +234,62 @@ SECTIONS
237234
238235
/* Location counter can end up 2byte aligned with narrow Thumb code but
239236
__etext is assumed by startup code to be the LMA of a section in RAM
240-
which must be 4byte aligned */
241-
__etext = ALIGN (4);
237+
which must be 8-byte aligned */
238+
__etext = ALIGN (8);
242239
243240
.data : AT (__etext)
244241
{
245242
__data_start__ = .;
246243
*(vtable)
247244
*(.data*)
248245
249-
. = ALIGN(4);
246+
. = ALIGN(8);
250247
/* preinit data */
251248
PROVIDE_HIDDEN (__preinit_array_start = .);
252249
KEEP(*(.preinit_array))
253250
PROVIDE_HIDDEN (__preinit_array_end = .);
254251
255-
. = ALIGN(4);
252+
. = ALIGN(8);
256253
/* init data */
257254
PROVIDE_HIDDEN (__init_array_start = .);
258255
KEEP(*(SORT(.init_array.*)))
259256
KEEP(*(.init_array))
260257
PROVIDE_HIDDEN (__init_array_end = .);
261258
262-
263-
. = ALIGN(4);
259+
. = ALIGN(8);
264260
/* finit data */
265261
PROVIDE_HIDDEN (__fini_array_start = .);
266262
KEEP(*(SORT(.fini_array.*)))
267263
KEEP(*(.fini_array))
268264
PROVIDE_HIDDEN (__fini_array_end = .);
269265
270266
KEEP(*(.jcr*))
271-
. = ALIGN(4);
267+
. = ALIGN(8);
272268
/* All data end */
273269
__data_end__ = .;
274270
275271
} > RAM
276272
273+
/* Uninitialized data section
274+
* This region is not initialized by the C/C++ library and can be used to
275+
* store state across soft reboots. */
276+
.uninitialized (NOLOAD):
277+
{
278+
. = ALIGN(32);
279+
__uninitialized_start = .;
280+
*(.uninitialized)
281+
KEEP(*(.keep.uninitialized))
282+
. = ALIGN(32);
283+
__uninitialized_end = .;
284+
} > RAM
285+
277286
.bss :
278287
{
279-
. = ALIGN(4);
288+
. = ALIGN(8);
280289
__bss_start__ = .;
281290
*(.bss*)
282291
*(COMMON)
283-
. = ALIGN(4);
292+
. = ALIGN(8);
284293
__bss_end__ = .;
285294
} > RAM
286295

0 commit comments

Comments
 (0)