Skip to content

Commit 24ac8cc

Browse files
committed
boot: zephyr: Fix disabling I/D caches
Fixes an issue whereby the instruction and data caches being disabled before booting code had bit-rotted and no longer worked, adds a new Kconfig that allows this option to be turned off if wanted. Signed-off-by: Jamie McCrae <[email protected]>
1 parent 5d067f0 commit 24ac8cc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

boot/zephyr/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ config MCUBOOT_ACTION_HOOKS
690690
'mcuboot_status_type_t' is listed in
691691
boot/bootutil/include/bootutil/mcuboot_status.h
692692

693+
config BOOT_DISABLE_CACHES
694+
bool "Disable I/D caches before chain-loading application"
695+
depends on CPU_HAS_ICACHE || CPU_HAS_DCACHE
696+
default y
697+
help
698+
Will flush and disable the instruction and data caches on the CPU prior to
699+
booting an application, this is required on some ARM Cortex devices and
700+
increases protection against data leakage from MCUboot to applications via
701+
these caches.
702+
693703
endmenu
694704

695705
config MCUBOOT_DEVICE_SETTINGS

boot/zephyr/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <soc.h>
2828
#include <zephyr/linker/linker-defs.h>
2929

30+
#if defined(CONFIG_BOOT_DISABLE_CACHES)
31+
#include <zephyr/cache.h>
32+
#endif
33+
3034
#if defined(CONFIG_ARM)
3135
#include <cmsis_core.h>
3236
#endif
@@ -176,10 +180,12 @@ static void do_boot(struct boot_rsp *rsp)
176180
#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
177181
cleanup_arm_nvic(); /* cleanup NVIC registers */
178182

179-
#ifdef CONFIG_CPU_CORTEX_M_HAS_CACHE
180-
/* Disable instruction cache and data cache before chain-load the application */
181-
SCB_DisableDCache();
182-
SCB_DisableICache();
183+
#if defined(CONFIG_BOOT_DISABLE_CACHES)
184+
/* Flush and disable instruction/data caches before chain-loading the application */
185+
(void)sys_cache_instr_flush_all();
186+
(void)sys_cache_data_flush_all();
187+
sys_cache_instr_disable();
188+
sys_cache_data_disable();
183189
#endif
184190

185191
#if CONFIG_CPU_HAS_ARM_MPU || CONFIG_CPU_HAS_NXP_MPU

0 commit comments

Comments
 (0)