arch: arm: cortex_m: z_arm_mpu_init: fix D-Cache invalidation

In case CONFIG_NOCACHE_MEMORY=y, the D-Cache need to be clean and
invalidated before enabling the MPU to make sure no data from a
__nocache__ region is present in the D-Cache.

If the D-Cache is disabled, SCB_CleanInvalidateDCache() shall not be
used as it might contains random data for random addresses, and this
might just create a bus fault.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
Aurelien Jarno 2021-05-13 15:34:00 +02:00 committed by Kumar Gala
commit be49df628f

View file

@ -326,11 +326,13 @@ int z_arm_mpu_init(void)
arm_core_mpu_disable();
#if defined(CONFIG_NOCACHE_MEMORY)
/* Clean and invalidate data cache if
/* Clean and invalidate data cache if it is enabled and
* that was not already done at boot
*/
#if !defined(CONFIG_INIT_ARCH_HW_AT_BOOT)
if (SCB->CCR & SCB_CCR_DC_Msk) {
SCB_CleanInvalidateDCache();
}
#endif
#endif /* CONFIG_NOCACHE_MEMORY */