Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zephyr: Add CONFIG_MCUBOOT_CLEANUP_RAM #2127

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ config MCUBOOT_CLEANUP_ARM_CORE
start-up code which can cause a module fault and potentially make the
module irrecoverable.

config MCUBOOT_CLEANUP_RAM
bool "Perform RAM cleanup"
depends on CPU_CORTEX_M4 || CPU_CORTEX_M33
help
Sets contents of memory to 0 before jumping to application.

config MBEDTLS_CFG_FILE
default "mcuboot-mbedtls-cfg.h"

Expand Down
27 changes: 27 additions & 0 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,34 @@ static void do_boot(struct boot_rsp *rsp)
__set_CONTROL(0x00); /* application will configures core on its own */
__ISB();
#endif
#if CONFIG_MCUBOOT_CLEANUP_RAM
__asm__ volatile (
/* vt->reset -> r0 */
" mov r0, %0\n"
/* base to write -> r1 */
" mov r1, %1\n"
/* size to write -> r2 */
" mov r2, %2\n"
/* value to write -> r3 */
" mov r3, %3\n"
"clear:\n"
" str r3, [r1]\n"
" add r1, r1, #4\n"
" sub r2, r2, #4\n"
" cbz r2, out\n"
" b clear\n"
"out:\n"
" dsb\n"
/* jump to reset vector of an app */
" bx r0\n"
:
: "r" (vt->reset), "i" (CONFIG_SRAM_BASE_ADDRESS),
"i" (CONFIG_SRAM_SIZE * 1024), "i" (0)
: "r0", "r1", "r2", "r3", "memory"
);
#else
((void (*)(void))vt->reset)();
#endif
}

#elif defined(CONFIG_XTENSA) || defined(CONFIG_RISCV)
Expand Down
Loading