99#define RAM_SIZE 0x40000
1010#define VECTORS 195 /* This value must match NVIC_NUM_VECTORS */
1111
12- /* Common - Do not change */
12+ /* Round up VECTORS_SIZE to 8 bytes */
13+ #define VECTORS_SIZE (((VECTORS * 4) + 7) & ~7)
1314
14- #if !defined(MBED_APP_START )
15- #define MBED_APP_START (ROM_START + FLASH_HDR_SIZE)
15+ #if !defined(MBED_BOOT_STACK_SIZE )
16+ #define MBED_BOOT_STACK_SIZE 0x400
1617#endif
1718
18- #if !defined(MBED_APP_SIZE)
19- #define MBED_APP_SIZE (ROM_SIZE - FLASH_HDR_SIZE)
19+ #define Stack_Size MBED_BOOT_STACK_SIZE
20+
21+ #if defined(MBED_APP_START)
22+ /*
23+ * There're two cases if MBED_APP_START is defined.
24+ * Case 1: MBED_APP_START is defined as ROM_START, this happens when restrict_size is turned on, most likely for bootloader build.
25+ * In this build, include FLASH_HDR region.
26+ */
27+ #define FLASH_HDR_INCLUDED 1
28+
29+ #if MBED_APP_START == ROM_START
30+ #if defined(MBED_APP_SIZE)
31+ #define ROM_EXEC_START (ROM_START + FLASH_HDR_SIZE)
32+ #define ROM_EXEC_SIZE (MBED_APP_SIZE - FLASH_HDR_SIZE)
33+ #endif
34+ #else
35+ /*
36+ * Case 2: MBED_APP_START is defined as a value greater than ROM_START, this is most likely a build other than the bootloader. E.g., the MCC build.
37+ * In this build, exclude FLASH_HDR region. This workarounds an issue in managed boodloader MCC build where the jump address and stack pointer point to the cookie area
38+ */
39+ #undef FLASH_HDR_INCLUDED
40+ #define FLASH_HDR_INCLUDED 0
41+ #define ROM_EXEC_START MBED_APP_START
42+ #if defined(MBED_APP_SIZE)
43+ #define ROM_EXEC_SIZE MBED_APP_SIZE
44+ #else
45+ #define ROM_EXEC_SIZE (ROM_SIZE- (MBED_APP_START - ROM_START)
46+ #endif
47+ #endif
48+ #else
49+ /*
50+ * MBED_APP_START is not defined. This is most likely a bootloader build, or other apps that do not require boodloader.
51+ * In this build, include FLASH_HDR region
52+ */
53+ #define FLASH_HDR_INCLUDED 1
54+ #define ROM_EXEC_START (ROM_START + FLASH_HDR_SIZE)
55+ #if defined(MBED_APP_SIZE)
56+ #define ROM_EXEC_SIZE (MBED_APP_SIZE - FLASH_HDR_SIZE)
57+ #else
58+ #define ROM_EXEC_SIZE (ROM_SIZE - FLASH_HDR_SIZE)
59+ #endif
2060#endif
2161
22- /* Round up VECTORS_SIZE to 8 bytes */
23- #define VECTORS_SIZE (((VECTORS * 4) + 7) & ~7)
2462
63+ #if FLASH_HDR_INCLUDED == 1
64+ ;#warning include cookie
2565LR_IROM1 ROM_START ROM_SIZE {
2666
2767 ER_FLASH FLASH_HDR_START FLASH_HDR_SIZE {
2868 *(signature_section, +Last)
2969 }
3070
31- ER_IROM1 MBED_APP_START FIXED {
71+ ER_IROM1 ROM_EXEC_START FIXED {
72+ *.o (RESET, +First)
73+ *(InRoot$$Sections)
74+ .ANY (+RO)
75+ }
76+
77+ ;RW_IRAM1 (RAM_START + VECTORS_SIZE) (RAM_SIZE - VECTORS_SIZE) { ; RW data
78+ RW_IRAM1 (0x20000000+0x308) (0x00040000-0x308) { ; RW data
79+ .ANY (+RW +ZI)
80+ }
81+
82+ ARM_LIB_STACK (RAM_START+RAM_SIZE) EMPTY -Stack_Size { ; stack
83+ }
84+ }
85+ #else
86+ ;#warning exclude cookie
87+ LR_IROM1 ROM_EXEC_START ROM_EXEC_SIZE {
88+
89+ ER_IROM1 ROM_EXEC_START ROM_EXEC_SIZE {
3290 *.o (RESET, +First)
3391 *(InRoot$$Sections)
3492 .ANY (+RO)
@@ -38,5 +96,9 @@ LR_IROM1 ROM_START ROM_SIZE {
3896 RW_IRAM1 (0x20000000+0x308) (0x00040000-0x308) { ; RW data
3997 .ANY (+RW +ZI)
4098 }
99+
100+ ARM_LIB_STACK (RAM_START + RAM_SIZE) EMPTY -Stack_Size { ; stack
101+ }
41102}
103+ #endif
42104
0 commit comments