Skip to content

Commit 13b17af

Browse files
committed
bootloader: Add support for cleaning up RAM before application boot
Adds a new Kconfig which, when enabled, will clear all RAM to 0 before loading into the application to chain load, this can be enabled with CONFIG_SB_CLEANUP_RAM Signed-off-by: Jamie McCrae <[email protected]>
1 parent 4885bf7 commit 13b17af

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

subsys/bootloader/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ config SB_BPROT_IN_DEBUG
210210
default y
211211
depends on (HAS_HW_NRF_BPROT || HAS_HW_NRF_MPU)
212212

213+
config SB_CLEANUP_RAM
214+
bool "Perform RAM cleanup"
215+
depends on !FW_INFO_PROVIDE_ENABLE
216+
depends on CPU_CORTEX_M4 || CPU_CORTEX_M33
217+
help
218+
Sets contents of memory to 0 before jumping to application.
219+
213220
endif # IS_SECURE_BOOTLOADER
214221

215222
config IS_BOOTLOADER_IMG

subsys/bootloader/bl_boot/bl_boot.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,34 @@ void bl_boot(const struct fw_info *fw_info)
156156
__set_MSP(vector_table[0]);
157157
__set_PSP(0);
158158

159+
#if CONFIG_SB_CLEANUP_RAM
160+
__asm__ volatile (
161+
/* vector_table[1] -> r0 */
162+
" mov r0, %0\n"
163+
/* Base to write -> r1 */
164+
" mov r1, %1\n"
165+
/* Size to write -> r2 */
166+
" mov r2, %2\n"
167+
/* Value to write -> r3 */
168+
" mov r3, %3\n"
169+
"clear:\n"
170+
" str r3, [r1]\n"
171+
" add r1, r1, #4\n"
172+
" sub r2, r2, #4\n"
173+
" cbz r2, out\n"
174+
" b clear\n"
175+
"out:\n"
176+
" dsb\n"
177+
/* Jump to reset vector of an app */
178+
" bx r0\n"
179+
:
180+
: "r" (vector_table[1]), "i" (CONFIG_SRAM_BASE_ADDRESS),
181+
"i" (CONFIG_SRAM_SIZE * 1024), "i" (0)
182+
: "r0", "r1", "r2", "r3", "memory"
183+
);
184+
#else
159185
/* Call reset handler. */
160186
((void (*)(void))vector_table[1])();
187+
#endif
161188
CODE_UNREACHABLE;
162189
}

subsys/fw_info/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ config FW_INFO_VALID_VAL
118118
help
119119
The value fw_info::valid will have when valid.
120120

121+
config FW_INFO_PROVIDE_ENABLE
122+
bool
123+
help
124+
Hidden option, set if at least one *_EXT_API_ENABLED option is enabled.
125+
121126
EXT_API = EXT_API_PROVIDE
122127
id = 0x1200
123128
flags = 0

subsys/fw_info/Kconfig.template.fw_info_ext_api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ config $(EXT_API)_EXT_API_ATLEAST_REQUIRED
4141

4242
config $(EXT_API)_EXT_API_ENABLED
4343
bool "Provide the $(EXT_API) EXT_API to other images"
44+
select FW_INFO_PROVIDE_ENABLE
4445
help
4546
Provide this EXT_API to other images.
4647

0 commit comments

Comments
 (0)