From 55dccc4bbaa93a7f63a97addff7b3ad8626a4c3f Mon Sep 17 00:00:00 2001 From: Xiao Xufeng Date: Sat, 10 Aug 2024 16:53:51 +0800 Subject: [PATCH] fix(MMU): fixed mmap deadlock when using multicore app with unicore bootloader Closes https://github.com/espressif/esp-idf/issues/11617 --- components/esp_system/port/cpu_start.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c index 649007cdfa..dc5ffda133 100644 --- a/components/esp_system/port/cpu_start.c +++ b/components/esp_system/port/cpu_start.c @@ -330,6 +330,17 @@ static void start_other_core(void) } #if !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE +#if CONFIG_IDF_TARGET_ESP32 +static void restore_app_mmu_from_pro_mmu(void) +{ + const int mmu_reg_num = 2048; + volatile uint32_t* from = (uint32_t*)DR_REG_FLASH_MMU_TABLE_PRO; + volatile uint32_t* to = (uint32_t*)DR_REG_FLASH_MMU_TABLE_APP; + for (int i = 0; i < mmu_reg_num; i++) { + *(to++) = *(from++); + } +} +#endif // This function is needed to make the multicore app runnable on a unicore bootloader (built with FREERTOS UNICORE). // It does some cache settings for other CPUs. void IRAM_ATTR do_multicore_settings(void) @@ -341,9 +352,11 @@ void IRAM_ATTR do_multicore_settings(void) Cache_Read_Disable(1); Cache_Flush(1); DPORT_REG_SET_BIT(DPORT_APP_CACHE_CTRL1_REG, DPORT_APP_CACHE_MMU_IA_CLR); + mmu_init(1); DPORT_REG_CLR_BIT(DPORT_APP_CACHE_CTRL1_REG, DPORT_APP_CACHE_MMU_IA_CLR); // We do not enable cache for CPU1 now because it will be done later in start_other_core(). } + restore_app_mmu_from_pro_mmu(); #endif cache_bus_mask_t cache_bus_mask_core0 = cache_ll_l1_get_enabled_bus(0);