Skip to content

Commit

Permalink
bootloader: Add support for cleaning up RAM before application boot
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nordicjm committed Dec 12, 2024
1 parent 4885bf7 commit 13b17af
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions subsys/bootloader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ config SB_BPROT_IN_DEBUG
default y
depends on (HAS_HW_NRF_BPROT || HAS_HW_NRF_MPU)

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

endif # IS_SECURE_BOOTLOADER

config IS_BOOTLOADER_IMG
Expand Down
27 changes: 27 additions & 0 deletions subsys/bootloader/bl_boot/bl_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,34 @@ void bl_boot(const struct fw_info *fw_info)
__set_MSP(vector_table[0]);
__set_PSP(0);

#if CONFIG_SB_CLEANUP_RAM
__asm__ volatile (
/* vector_table[1] -> 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" (vector_table[1]), "i" (CONFIG_SRAM_BASE_ADDRESS),
"i" (CONFIG_SRAM_SIZE * 1024), "i" (0)
: "r0", "r1", "r2", "r3", "memory"
);
#else
/* Call reset handler. */
((void (*)(void))vector_table[1])();
#endif
CODE_UNREACHABLE;
}
5 changes: 5 additions & 0 deletions subsys/fw_info/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ config FW_INFO_VALID_VAL
help
The value fw_info::valid will have when valid.

config FW_INFO_PROVIDE_ENABLE
bool
help
Hidden option, set if at least one *_EXT_API_ENABLED option is enabled.

EXT_API = EXT_API_PROVIDE
id = 0x1200
flags = 0
Expand Down
1 change: 1 addition & 0 deletions subsys/fw_info/Kconfig.template.fw_info_ext_api
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ config $(EXT_API)_EXT_API_ATLEAST_REQUIRED

config $(EXT_API)_EXT_API_ENABLED
bool "Provide the $(EXT_API) EXT_API to other images"
select FW_INFO_PROVIDE_ENABLE
help
Provide this EXT_API to other images.

Expand Down

0 comments on commit 13b17af

Please sign in to comment.