File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -276,6 +276,35 @@ void RAMFUNCTION hal_cache_invalidate(void)
276276 ISB ();
277277}
278278
279+ /* Make the GFXMMU virtual-buffer window inaccessible while the D-cache is
280+ * on. The window is Normal memory in the default map, the core may read
281+ * Normal memory speculatively once the D-cache is enabled, and with the
282+ * GFXMMU clock off such a read stalls the bus for good: no fault, and the
283+ * debugger loses the core. A no-access region stops the read being issued. */
284+ static void mpu_guard_enable (void )
285+ {
286+ MPU_RNR = GFXMMU_MPU_REGION ;
287+ MPU_RBAR = GFXMMU_VBUF_BASE ;
288+ MPU_RASR = MPU_RASR_XN | MPU_RASR_SIZE_16MB | MPU_RASR_ENABLE ;
289+ #ifdef WOLFBOOT_NO_MPU
290+ /* Nothing else has set the MPU up: keep the default map for the rest */
291+ MPU_CTRL = MPU_CTRL_PRIVDEFENA | MPU_CTRL_ENABLE ;
292+ #endif
293+ DSB ();
294+ ISB ();
295+ }
296+
297+ static void mpu_guard_disable (void )
298+ {
299+ #ifdef WOLFBOOT_NO_MPU
300+ MPU_CTRL = 0 ;
301+ #endif
302+ MPU_RNR = GFXMMU_MPU_REGION ;
303+ MPU_RASR = 0 ;
304+ DSB ();
305+ ISB ();
306+ }
307+
279308static void dcache_enable (void )
280309{
281310 uint32_t sets , ways ;
@@ -884,6 +913,7 @@ void hal_init(void)
884913 icache_enable ();
885914 octospi_gpio_init ();
886915 octospi_init ();
916+ mpu_guard_enable ();
887917 dcache_enable ();
888918#ifdef DEBUG_UART
889919 uart_init ();
@@ -905,6 +935,7 @@ void hal_prepare_boot(void)
905935 octospi_enable_mmap ();
906936 dcache_disable ();
907937 icache_disable ();
938+ mpu_guard_disable ();
908939}
909940
910941#endif /* !WOLFBOOT_UNIT_TEST_FLASH_ERASE */
Original file line number Diff line number Diff line change 454454#define CCSIDR (*(volatile uint32_t *)(0xE000ED80UL))
455455#define CSSELR (*(volatile uint32_t *)(0xE000ED84UL))
456456
457+ #define MPU_CTRL (*(volatile uint32_t *)(0xE000ED94UL))
458+ #define MPU_RNR (*(volatile uint32_t *)(0xE000ED98UL))
459+ #define MPU_RBAR (*(volatile uint32_t *)(0xE000ED9CUL))
460+ #define MPU_RASR (*(volatile uint32_t *)(0xE000EDA0UL))
461+ #define MPU_CTRL_ENABLE (1 << 0)
462+ #define MPU_CTRL_PRIVDEFENA (1 << 2)
463+ #define MPU_RASR_ENABLE (1 << 0)
464+ #define MPU_RASR_SIZE_16MB (23 << 1)
465+ #define MPU_RASR_XN (1 << 28)
466+
467+ /* GFXMMU virtual buffers 0..3. A read here never completes while the
468+ * GFXMMU clock is off. */
469+ #define GFXMMU_VBUF_BASE (0x25000000UL)
470+ /* MPU region for the guard: one mpu_init() in src/boot_arm.c leaves free. */
471+ #define GFXMMU_MPU_REGION 3
472+
457473#define CACHE_LINE_SIZE 32
458474
459475#endif /* _STM32H7S_DEF_INCLUDED */
You can’t perform that action at this time.
0 commit comments