Skip to content

Commit 8175451

Browse files
author
Amanda Butler
authored
Merge pull request #739 from c1728p9/linker_script_update
Update linker script templates to include stack
2 parents c928ab9 + f17f052 commit 8175451

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

docs/porting/target/bootstrap.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ After adding the core files, the next step is to add linker scripts for Mbed OS.
1717
If you are updating your own linker script, you must:
1818

1919
- Reserve space for the RAM vector table.
20-
- Define the start of the heap:
21-
- Arm - The heap starts immediately after the region `RW_IRAM1`.
22-
- GCC_ARM - The heap starts at the symbol `__end__`.
20+
- 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.
22+
- GCC_ARM - The heap starts at the symbol `__end__` and ends at the `__HeapLimit` symbol.
2323
- IAR - The heap is the `HEAP` region.
24-
- Add defines for a relocatable application - `MBED_APP_START` and `MBED_APP_SIZE`.
25-
- Add preprocessing directive `#! armcc -E` (ARM compiler only).
24+
- Define the boot stack region:
25+
- Arm - The boot stack is the `ARM_LIB_STACK` region.
26+
- GCC_ARM - The boot stack starts at the symbol `__StackLimit` and ends at the symbol `__StackTop`.
27+
- IAR - The boot stack is the `CSTACK` region.
28+
- Add defines for a relocatable application - `MBED_APP_START` and `MBED_APP_SIZE`.
29+
- Add the define for boot stack size - `MBED_BOOT_STACK_SIZE`.
30+
- Add preprocessing directive `#! armcc -E` (ARM compiler only).
2631

2732
If you are using the below linker script, then you need to update all the defines in the `/* Device specific values */` section for your target.
2833

@@ -49,8 +54,14 @@ Arm linker script template:
4954
#define MBED_APP_SIZE ROM_SIZE
5055
#endif
5156
57+
#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
61+
#endif
62+
5263
/* Round up VECTORS_SIZE to 8 bytes */
53-
#define VECTORS_SIZE (((VECTORS * 4) + 7) & ~7)
64+
#define VECTORS_SIZE (((VECTORS * 4) + 7) AND ~7)
5465
5566
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
5667
@@ -60,9 +71,11 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE {
6071
.ANY (+RO)
6172
}
6273
63-
RW_IRAM1 (RAM_START + VECTORS_SIZE) (RAM_SIZE - VECTORS_SIZE) { ; RW data
74+
RW_IRAM1 (RAM_START + VECTORS_SIZE) (RAM_SIZE - VECTORS_SIZE - MBED_BOOT_STACK_SIZE) { ; RW data
6475
.ANY (+RW +ZI)
6576
}
77+
ARM_LIB_STACK (RAM_START + RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; Stack region growing down
78+
}
6679
}
6780
```
6881

@@ -88,17 +101,22 @@ if (!isdefinedsymbol(MBED_APP_SIZE)) {
88101
define symbol MBED_APP_SIZE = ROM_SIZE;
89102
}
90103
104+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
105+
/* 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;
108+
}
109+
91110
/* Round up VECTORS_SIZE to 8 bytes */
92111
define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7;
93112
define symbol RAM_REGION_START = RAM_START + VECTORS_SIZE;
94113
define symbol RAM_REGION_SIZE = RAM_SIZE - VECTORS_SIZE;
95-
define symbol ISR_STACK_SIZE = 0x400;
96114
97115
define memory mem with size = 4G;
98116
define region ROM_region = mem:[from MBED_APP_START size MBED_APP_SIZE];
99117
define region RAM_region = mem:[from RAM_REGION_START size RAM_REGION_SIZE];
100118
101-
define block CSTACK with alignment = 8, size = ISR_STACK_SIZE { };
119+
define block CSTACK with alignment = 8, size = MBED_BOOT_STACK_SIZE { };
102120
define block HEAP with alignment = 8, size = HEAP_SIZE { };
103121
104122
initialize by copy { readwrite };
@@ -133,6 +151,12 @@ GCC linker script template:
133151
#define MBED_APP_SIZE ROM_SIZE
134152
#endif
135153
154+
#if !defined(MBED_BOOT_STACK_SIZE)
155+
/* 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
158+
#endif
159+
136160
/* Round up VECTORS_SIZE to 8 bytes */
137161
#define VECTORS_SIZE (((VECTORS * 4) + 7) & 0xFFFFFFF8)
138162
@@ -265,6 +289,7 @@ SECTIONS
265289
__end__ = .;
266290
PROVIDE(end = .);
267291
*(.heap*)
292+
. = ORIGIN(RAM) + LENGTH(RAM) - MBED_BOOT_STACK_SIZE;
268293
__HeapLimit = .;
269294
} > RAM
270295
@@ -279,7 +304,7 @@ SECTIONS
279304
/* Set stack top to end of RAM, and stack limit move down by
280305
* size of stack_dummy section */
281306
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
282-
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
307+
__StackLimit = __StackTop - MBED_BOOT_STACK_SIZE;
283308
PROVIDE(__stack = __StackTop);
284309
285310
/* Check if data + heap + stack exceeds RAM limit */

0 commit comments

Comments
 (0)