diff --git a/boot/startup/src/arch/cortex_m0/cortex_m0_startup.s b/boot/startup/src/arch/cortex_m0/cortex_m0_startup.s index eab5591468..fd590791a0 100644 --- a/boot/startup/src/arch/cortex_m0/cortex_m0_startup.s +++ b/boot/startup/src/arch/cortex_m0/cortex_m0_startup.s @@ -17,6 +17,8 @@ * under the License. */ +#include "syscfg/syscfg.h" + .syntax unified .arch armv6-m @@ -64,6 +66,15 @@ Reset_Handler: .L_zero_table_done: +#if MYNEWT_VAL_MAIN_STACK_FILL + ldr r0, =MYNEWT_VAL_MAIN_STACK_FILL + ldr r2, =__StackLimit + mov r1, sp +0: stm r2!, {r0} + cmp r2, r1 + blt 0b +#endif + ldr r0, =__HeapBase ldr r1, =__HeapLimit bl _sbrkInit diff --git a/boot/startup/src/arch/cortex_m3/cortex_m3_startup.s b/boot/startup/src/arch/cortex_m3/cortex_m3_startup.s index 03f77f7799..4e6b20eeaf 100644 --- a/boot/startup/src/arch/cortex_m3/cortex_m3_startup.s +++ b/boot/startup/src/arch/cortex_m3/cortex_m3_startup.s @@ -17,6 +17,8 @@ * under the License. */ +#include "syscfg/syscfg.h" + .syntax unified .arch armv7-m @@ -67,6 +69,15 @@ Reset_Handler: b .L_for_each_zero_region .L_zero_table_done: +#if MYNEWT_VAL_MAIN_STACK_FILL + ldr r0, =MYNEWT_VAL_MAIN_STACK_FILL + ldr r2, =__StackLimit + mov r1, sp +0: stm r2!, {r0} + cmp r2, r1 + blt 0b +#endif + ldr r0, =__HeapBase ldr r1, =__HeapLimit bl _sbrkInit diff --git a/boot/startup/src/arch/cortex_m33/cortex_m33_startup.s b/boot/startup/src/arch/cortex_m33/cortex_m33_startup.s index 471927f42b..27f995c913 100644 --- a/boot/startup/src/arch/cortex_m33/cortex_m33_startup.s +++ b/boot/startup/src/arch/cortex_m33/cortex_m33_startup.s @@ -17,6 +17,8 @@ * under the License. */ +#include "syscfg/syscfg.h" + .syntax unified .arch armv7-m @@ -70,6 +72,15 @@ Reset_Handler: b .L_for_each_zero_region .L_zero_table_done: +#if MYNEWT_VAL_MAIN_STACK_FILL + ldr r0, =MYNEWT_VAL_MAIN_STACK_FILL + ldr r2, =__StackLimit + mov r1, sp +0: stm r2!, {r0} + cmp r2, r1 + blt 0b +#endif + ldr r0, =__HeapBase ldr r1, =__HeapLimit bl _sbrkInit diff --git a/boot/startup/src/arch/cortex_m4/cortex_m4_startup.s b/boot/startup/src/arch/cortex_m4/cortex_m4_startup.s index 03f77f7799..4e6b20eeaf 100644 --- a/boot/startup/src/arch/cortex_m4/cortex_m4_startup.s +++ b/boot/startup/src/arch/cortex_m4/cortex_m4_startup.s @@ -17,6 +17,8 @@ * under the License. */ +#include "syscfg/syscfg.h" + .syntax unified .arch armv7-m @@ -67,6 +69,15 @@ Reset_Handler: b .L_for_each_zero_region .L_zero_table_done: +#if MYNEWT_VAL_MAIN_STACK_FILL + ldr r0, =MYNEWT_VAL_MAIN_STACK_FILL + ldr r2, =__StackLimit + mov r1, sp +0: stm r2!, {r0} + cmp r2, r1 + blt 0b +#endif + ldr r0, =__HeapBase ldr r1, =__HeapLimit bl _sbrkInit diff --git a/boot/startup/src/arch/cortex_m7/cortex_m7_startup.s b/boot/startup/src/arch/cortex_m7/cortex_m7_startup.s index 03f77f7799..4e6b20eeaf 100644 --- a/boot/startup/src/arch/cortex_m7/cortex_m7_startup.s +++ b/boot/startup/src/arch/cortex_m7/cortex_m7_startup.s @@ -17,6 +17,8 @@ * under the License. */ +#include "syscfg/syscfg.h" + .syntax unified .arch armv7-m @@ -67,6 +69,15 @@ Reset_Handler: b .L_for_each_zero_region .L_zero_table_done: +#if MYNEWT_VAL_MAIN_STACK_FILL + ldr r0, =MYNEWT_VAL_MAIN_STACK_FILL + ldr r2, =__StackLimit + mov r1, sp +0: stm r2!, {r0} + cmp r2, r1 + blt 0b +#endif + ldr r0, =__HeapBase ldr r1, =__HeapLimit bl _sbrkInit diff --git a/boot/startup/syscfg.yml b/boot/startup/syscfg.yml index 92d00328ab..d416443f28 100644 --- a/boot/startup/syscfg.yml +++ b/boot/startup/syscfg.yml @@ -34,6 +34,11 @@ syscfg.defs: For bootloader it's main stack, for application this stack is used by interrupts and exceptions. value: 768 + MAIN_STACK_FILL: + description: > + Fill main stack (interrupt stack) with pattern on startup. + If not 0, value will be used as a pattern. + value: 0 INCLUDE_IMAGE_HEADER: description: Add image header to generated executable. value: 1