Skip to content

Commit 39aab3d

Browse files
committed
zephyr: Add CONFIG_MCUBOOT_CLEANUP_RAM
Add Kconfig option to cleanup RAM in MCUboot before passing control to an application. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 8a2e2ed commit 39aab3d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

boot/zephyr/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ config MCUBOOT_CLEANUP_ARM_CORE
219219
start-up code which can cause a module fault and potentially make the
220220
module irrecoverable.
221221

222+
config MCUBOOT_CLEANUP_RAM
223+
bool "Perform RAM cleanup"
224+
depends on CPU_CORTEX_M4 || CPU_CORTEX_M33
225+
help
226+
Sets contents of memory to 0 before jumping to application.
227+
222228
config MBEDTLS_CFG_FILE
223229
default "mcuboot-mbedtls-cfg.h"
224230

boot/zephyr/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,34 @@ static void do_boot(struct boot_rsp *rsp)
236236
__set_CONTROL(0x00); /* application will configures core on its own */
237237
__ISB();
238238
#endif
239+
#if CONFIG_MCUBOOT_CLEANUP_RAM
240+
__asm__ volatile (
241+
/* vt->reset -> r0 */
242+
" mov r0, %0\n"
243+
/* base to write -> r1 */
244+
" mov r1, %1\n"
245+
/* size to write -> r2 */
246+
" mov r2, %2\n"
247+
/* value to write -> r3 */
248+
" mov r3, %3\n"
249+
"clear:\n"
250+
" str r3, [r1]\n"
251+
" add r1, r1, #4\n"
252+
" sub r2, r2, #4\n"
253+
" cbz r2, out\n"
254+
" b clear\n"
255+
"out:\n"
256+
" dsb\n"
257+
/* jump to reset vector of an app */
258+
" bx r0\n"
259+
:
260+
: "r" (vt->reset), "i" (CONFIG_SRAM_BASE_ADDRESS),
261+
"i" (CONFIG_SRAM_SIZE * 1024), "i" (0)
262+
: "r0", "r1", "r2", "r3", "memory"
263+
);
264+
#else
239265
((void (*)(void))vt->reset)();
266+
#endif
240267
}
241268

242269
#elif defined(CONFIG_XTENSA) || defined(CONFIG_RISCV)

0 commit comments

Comments
 (0)