From bae6680207409d58bcdf3e0e7163cf53c2106ec9 Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 13 Mar 2023 11:37:23 +0800 Subject: [PATCH] mmu: hal function to init, and hal function to unmap all --- .../bootloader_flash/src/bootloader_flash.c | 2 +- components/bootloader_support/src/bootloader_utility.c | 4 ++-- .../bootloader_support/src/esp32c2/bootloader_esp32c2.c | 5 +---- .../bootloader_support/src/esp32c3/bootloader_esp32c3.c | 2 +- .../bootloader_support/src/esp32c6/bootloader_esp32c6.c | 5 +---- .../bootloader_support/src/esp32h2/bootloader_esp32h2.c | 5 +---- .../bootloader_support/src/esp32h4/bootloader_esp32h4.c | 2 +- .../bootloader_support/src/esp32s2/bootloader_esp32s2.c | 2 +- .../bootloader_support/src/esp32s3/bootloader_esp32s3.c | 2 +- components/hal/include/hal/mmu_hal.h | 7 ++++++- components/hal/mmu_hal.c | 5 +++++ 11 files changed, 21 insertions(+), 20 deletions(-) diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash.c index bfa0f3097b..baba26f963 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash.c @@ -241,7 +241,7 @@ void bootloader_munmap(const void *mapping) mmu_init(0); #else cache_hal_disable(CACHE_TYPE_ALL); - mmu_hal_init(); + mmu_hal_unmap_all(); #endif mapped = false; current_read_mapping = UINT32_MAX; diff --git a/components/bootloader_support/src/bootloader_utility.c b/components/bootloader_support/src/bootloader_utility.c index 78bc5c6cf7..3910cb14f5 100644 --- a/components/bootloader_support/src/bootloader_utility.c +++ b/components/bootloader_support/src/bootloader_utility.c @@ -845,8 +845,8 @@ static void set_cache_and_start_app( #else cache_hal_disable(CACHE_TYPE_ALL); #endif - - mmu_hal_init(); + //reset MMU table first + mmu_hal_unmap_all(); //-----------------------MAP DROM-------------------------- uint32_t drom_load_addr_aligned = drom_load_addr & MMU_FLASH_MASK; diff --git a/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c b/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c index ca254e559d..ebe7cf2757 100644 --- a/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c +++ b/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c @@ -38,7 +38,6 @@ #include "esp_efuse.h" #include "hal/mmu_hal.h" #include "hal/cache_hal.h" -#include "hal/mmu_ll.h" static const char *TAG = "boot.esp32c2"; @@ -113,10 +112,8 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); - //reset mmu + //init mmu mmu_hal_init(); - // config mmu page size - mmu_ll_set_page_size(0, SPI_FLASH_MMU_PAGE_SIZE); // update flash ID bootloader_flash_update_id(); #if !CONFIG_APP_BUILD_TYPE_RAM diff --git a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c index 9c92a6a253..97fbe9d5c1 100644 --- a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c +++ b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c @@ -161,7 +161,7 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); - //reset mmu + //init mmu mmu_hal_init(); // update flash ID bootloader_flash_update_id(); diff --git a/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c b/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c index f73d5b6cb8..e1eec5bcd8 100644 --- a/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c +++ b/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c @@ -40,7 +40,6 @@ #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" #include "hal/mmu_hal.h" -#include "hal/mmu_ll.h" #include "hal/cache_hal.h" #include "hal/clk_tree_ll.h" #include "soc/lp_wdt_reg.h" @@ -169,10 +168,8 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); - //reset mmu + //init mmu mmu_hal_init(); - // config mmu page size - mmu_ll_set_page_size(0, SPI_FLASH_MMU_PAGE_SIZE); // update flash ID bootloader_flash_update_id(); // Check and run XMC startup flow diff --git a/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c b/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c index 3bb04ebbc9..5de830031f 100644 --- a/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c +++ b/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c @@ -40,7 +40,6 @@ #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" #include "hal/mmu_hal.h" -#include "hal/mmu_ll.h" #include "hal/cache_hal.h" #include "soc/lp_wdt_reg.h" #include "hal/efuse_hal.h" @@ -159,10 +158,8 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); - //reset mmu + //init mmu mmu_hal_init(); - // config mmu page size - mmu_ll_set_page_size(0, SPI_FLASH_MMU_PAGE_SIZE); // update flash ID bootloader_flash_update_id(); // Check and run XMC startup flow diff --git a/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c b/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c index fca0cfa2d8..7b48fcc756 100644 --- a/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c +++ b/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c @@ -120,7 +120,7 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); //TODO IDF-4649 - //reset mmu + //init mmu mmu_hal_init(); // update flash ID bootloader_flash_update_id(); diff --git a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c index b960b9b33c..a3b58556cc 100644 --- a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c +++ b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c @@ -142,7 +142,7 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP // init cache hal cache_hal_init(); - // reset mmu + //init mmu mmu_hal_init(); // Workaround: normal ROM bootloader exits with DROM0 cache unmasked, but 2nd bootloader exits with it masked. REG_CLR_BIT(EXTMEM_PRO_ICACHE_CTRL1_REG, EXTMEM_PRO_ICACHE_MASK_DROM0); diff --git a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c index 5fba0cdd6c..fd49d120a7 100644 --- a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c +++ b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c @@ -180,7 +180,7 @@ esp_err_t bootloader_init(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP //init cache hal cache_hal_init(); - //reset mmu + //init mmu mmu_hal_init(); // update flash ID bootloader_flash_update_id(); diff --git a/components/hal/include/hal/mmu_hal.h b/components/hal/include/hal/mmu_hal.h index 13a611e105..8bb629640f 100644 --- a/components/hal/include/hal/mmu_hal.h +++ b/components/hal/include/hal/mmu_hal.h @@ -14,10 +14,15 @@ extern "C" { #endif /** - * Unmap all the MMU table. After this all external memory vaddr are not available + * MMU Hal layer initialisation */ void mmu_hal_init(void); +/** + * Unmap all the MMU table. After this all external memory vaddr are not available + */ +void mmu_hal_unmap_all(void); + /** * Helper functions to convert the MMU page numbers into bytes. e.g.: * - When MMU page size is 16KB, page_num = 2 will be converted into 32KB diff --git a/components/hal/mmu_hal.c b/components/hal/mmu_hal.c index 3f31259bfb..171f4fdc19 100644 --- a/components/hal/mmu_hal.c +++ b/components/hal/mmu_hal.c @@ -19,7 +19,12 @@ void mmu_hal_init(void) #if CONFIG_ESP_ROM_RAM_APP_NEEDS_MMU_INIT ROM_Boot_Cache_Init(); #endif + mmu_ll_set_page_size(0, CONFIG_MMU_PAGE_SIZE); + mmu_hal_unmap_all(); +} +void mmu_hal_unmap_all(void) +{ mmu_ll_unmap_all(0); #if !CONFIG_FREERTOS_UNICORE mmu_ll_unmap_all(1);