From 1785e1d329c6260387642f1c89b91ac73b30cd0f Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Thu, 27 Mar 2025 15:51:17 +0800 Subject: [PATCH] refactor(flash): spilt flash cap in esp_rom --- .../esp_rom/esp32c2/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32c2/esp_rom_caps.h | 1 + .../esp_rom/esp32c3/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32c3/esp_rom_caps.h | 1 + .../esp_rom/esp32c5/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32c5/esp_rom_caps.h | 1 + .../esp_rom/esp32c6/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32c6/esp_rom_caps.h | 1 + .../esp_rom/esp32c61/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32c61/esp_rom_caps.h | 1 + .../esp_rom/esp32h2/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32h2/esp_rom_caps.h | 1 + .../esp_rom/esp32h21/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32h21/esp_rom_caps.h | 1 + .../esp_rom/esp32h4/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32h4/esp_rom_caps.h | 1 + .../esp_rom/esp32s3/Kconfig.soc_caps.in | 4 ++ components/esp_rom/esp32s3/esp_rom_caps.h | 1 + components/spi_flash/flash_mmap.c | 8 ++-- components/spi_flash/flash_ops.c | 3 ++ examples/system/heap_task_tracking/README.md | 39 ------------------- 21 files changed, 52 insertions(+), 43 deletions(-) delete mode 100644 examples/system/heap_task_tracking/README.md diff --git a/components/esp_rom/esp32c2/Kconfig.soc_caps.in b/components/esp_rom/esp32c2/Kconfig.soc_caps.in index 155b271d04..50fbfeab1a 100644 --- a/components/esp_rom/esp32c2/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c2/Kconfig.soc_caps.in @@ -55,6 +55,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_HAS_NEWLIB bool default y diff --git a/components/esp_rom/esp32c2/esp_rom_caps.h b/components/esp_rom/esp32c2/esp_rom_caps.h index 765a7e7049..881e52ba64 100644 --- a/components/esp_rom/esp32c2/esp_rom_caps.h +++ b/components/esp_rom/esp32c2/esp_rom_caps.h @@ -19,6 +19,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions #define ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE (1) // ROM needs to set cache MMU size according to instruction and rodata for flash mmap diff --git a/components/esp_rom/esp32c3/Kconfig.soc_caps.in b/components/esp_rom/esp32c3/Kconfig.soc_caps.in index ef95398bc5..5498ffab5b 100644 --- a/components/esp_rom/esp32c3/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c3/Kconfig.soc_caps.in @@ -55,6 +55,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_HAS_ETS_PRINTF_BUG bool default y diff --git a/components/esp_rom/esp32c3/esp_rom_caps.h b/components/esp_rom/esp32c3/esp_rom_caps.h index db5ee8451f..ccb7762199 100644 --- a/components/esp_rom/esp32c3/esp_rom_caps.h +++ b/components/esp_rom/esp32c3/esp_rom_caps.h @@ -19,6 +19,7 @@ #define ESP_ROM_NEEDS_SWSETUP_WORKAROUND (1) // ROM uses 32-bit time_t. A workaround is required to prevent printf functions from crashing #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_HAS_ETS_PRINTF_BUG (1) // ROM has ets_printf bug when disable the ROM log either by eFuse or RTC storage register #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions diff --git a/components/esp_rom/esp32c5/Kconfig.soc_caps.in b/components/esp_rom/esp32c5/Kconfig.soc_caps.in index bfdb1fc951..452cdc6e64 100644 --- a/components/esp_rom/esp32c5/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c5/Kconfig.soc_caps.in @@ -63,6 +63,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_WITHOUT_REGI2C bool default y diff --git a/components/esp_rom/esp32c5/esp_rom_caps.h b/components/esp_rom/esp32c5/esp_rom_caps.h index d704bc8f75..cd9b091f65 100644 --- a/components/esp_rom/esp32c5/esp_rom_caps.h +++ b/components/esp_rom/esp32c5/esp_rom_caps.h @@ -21,6 +21,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_WITHOUT_REGI2C (1) // ROM has no regi2c APIs TODO: IDF-10110 need refactor #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NORMAL_FORMAT (1) // ROM has the newlib normal/full version of formatting functions (as opposed to the nano versions) diff --git a/components/esp_rom/esp32c6/Kconfig.soc_caps.in b/components/esp_rom/esp32c6/Kconfig.soc_caps.in index c770cf4703..7c7caef168 100644 --- a/components/esp_rom/esp32c6/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c6/Kconfig.soc_caps.in @@ -63,6 +63,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_HAS_REGI2C_BUG bool default y diff --git a/components/esp_rom/esp32c6/esp_rom_caps.h b/components/esp_rom/esp32c6/esp_rom_caps.h index b11c6db554..a66baf2574 100644 --- a/components/esp_rom/esp32c6/esp_rom_caps.h +++ b/components/esp_rom/esp32c6/esp_rom_caps.h @@ -21,6 +21,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_HAS_REGI2C_BUG (1) // ROM has the regi2c bug #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NORMAL_FORMAT (1) // ROM has the newlib normal/full version of formatting functions (as opposed to the nano versions) diff --git a/components/esp_rom/esp32c61/Kconfig.soc_caps.in b/components/esp_rom/esp32c61/Kconfig.soc_caps.in index 506b867ed3..c3d7974600 100644 --- a/components/esp_rom/esp32c61/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c61/Kconfig.soc_caps.in @@ -63,6 +63,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_WITHOUT_REGI2C bool default y diff --git a/components/esp_rom/esp32c61/esp_rom_caps.h b/components/esp_rom/esp32c61/esp_rom_caps.h index 7d0d22d405..72a5220656 100644 --- a/components/esp_rom/esp32c61/esp_rom_caps.h +++ b/components/esp_rom/esp32c61/esp_rom_caps.h @@ -21,6 +21,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_WITHOUT_REGI2C (1) // ROM has no regi2c APIs TODO: IDF-10110 need refactor #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions diff --git a/components/esp_rom/esp32h2/Kconfig.soc_caps.in b/components/esp_rom/esp32h2/Kconfig.soc_caps.in index 9f48e30fb5..7ef382eb3e 100644 --- a/components/esp_rom/esp32h2/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32h2/Kconfig.soc_caps.in @@ -55,6 +55,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_WITHOUT_REGI2C bool default y diff --git a/components/esp_rom/esp32h2/esp_rom_caps.h b/components/esp_rom/esp32h2/esp_rom_caps.h index fd5a8ed299..7e43615fd0 100644 --- a/components/esp_rom/esp32h2/esp_rom_caps.h +++ b/components/esp_rom/esp32h2/esp_rom_caps.h @@ -19,6 +19,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_WITHOUT_REGI2C (1) // ROM has no regi2c APIs #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano versions of formatting functions diff --git a/components/esp_rom/esp32h21/Kconfig.soc_caps.in b/components/esp_rom/esp32h21/Kconfig.soc_caps.in index ed4d5c912f..bc424d9813 100644 --- a/components/esp_rom/esp32h21/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32h21/Kconfig.soc_caps.in @@ -51,6 +51,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_WITHOUT_REGI2C bool default y diff --git a/components/esp_rom/esp32h21/esp_rom_caps.h b/components/esp_rom/esp32h21/esp_rom_caps.h index 54c559343e..b69f69ae3d 100644 --- a/components/esp_rom/esp32h21/esp_rom_caps.h +++ b/components/esp_rom/esp32h21/esp_rom_caps.h @@ -18,6 +18,7 @@ #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_WITHOUT_REGI2C (1) // ROM has no regi2c APIs #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano versions of formatting functions diff --git a/components/esp_rom/esp32h4/Kconfig.soc_caps.in b/components/esp_rom/esp32h4/Kconfig.soc_caps.in index 55b7dddd10..052caa5c3b 100644 --- a/components/esp_rom/esp32h4/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32h4/Kconfig.soc_caps.in @@ -47,6 +47,10 @@ config ESP_ROM_HAS_LAYOUT_TABLE bool default y +config ESP_ROM_HAS_SPI_FLASH + bool + default y + config ESP_ROM_WITHOUT_REGI2C bool default y diff --git a/components/esp_rom/esp32h4/esp_rom_caps.h b/components/esp_rom/esp32h4/esp_rom_caps.h index 8cb8b9d457..5047cfef70 100644 --- a/components/esp_rom/esp32h4/esp_rom_caps.h +++ b/components/esp_rom/esp32h4/esp_rom_caps.h @@ -17,6 +17,7 @@ #define ESP_ROM_HAS_HEAP_TLSF (1) // ROM has the implementation of the tlsf and multi-heap library #define ESP_ROM_MULTI_HEAP_WALK_PATCH (1) // ROM does not contain the patch of multi_heap_walk() #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table +#define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver #define ESP_ROM_WITHOUT_REGI2C (1) // ROM has the regi2c bug or rom does not support regi2c function #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano versions of formatting functions diff --git a/components/esp_rom/esp32s3/Kconfig.soc_caps.in b/components/esp_rom/esp32s3/Kconfig.soc_caps.in index 00bef5ab69..7723ea47d7 100644 --- a/components/esp_rom/esp32s3/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32s3/Kconfig.soc_caps.in @@ -63,6 +63,10 @@ config ESP_ROM_HAS_SPI_FLASH bool default y +config ESP_ROM_HAS_SPI_FLASH_MMAP + bool + default y + config ESP_ROM_HAS_ETS_PRINTF_BUG bool default y diff --git a/components/esp_rom/esp32s3/esp_rom_caps.h b/components/esp_rom/esp32s3/esp_rom_caps.h index f91b21a535..566c593b5a 100644 --- a/components/esp_rom/esp32s3/esp_rom_caps.h +++ b/components/esp_rom/esp32s3/esp_rom_caps.h @@ -21,6 +21,7 @@ #define ESP_ROM_NEEDS_SWSETUP_WORKAROUND (1) // ROM uses 32-bit time_t. A workaround is required to prevent printf functions from crashing #define ESP_ROM_HAS_LAYOUT_TABLE (1) // ROM has the layout table #define ESP_ROM_HAS_SPI_FLASH (1) // ROM has the implementation of SPI Flash driver +#define ESP_ROM_HAS_SPI_FLASH_MMAP (1) // ROM has the implementation of SPI Flash mmap driver #define ESP_ROM_HAS_ETS_PRINTF_BUG (1) // ROM has ets_printf bug when disable the ROM log either by eFuse or RTC storage register #define ESP_ROM_HAS_NEWLIB (1) // ROM has newlib (at least parts of it) functions included #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions diff --git a/components/spi_flash/flash_mmap.c b/components/spi_flash/flash_mmap.c index 3da15b1b3b..2554c26863 100644 --- a/components/spi_flash/flash_mmap.c +++ b/components/spi_flash/flash_mmap.c @@ -48,7 +48,7 @@ extern char _rodata_reserved_start; extern char _rodata_reserved_end; #endif -#if !CONFIG_SPI_FLASH_ROM_IMPL +#if !ESP_ROM_HAS_SPI_FLASH_MMAP || !CONFIG_SPI_FLASH_ROM_IMPL typedef struct mmap_block_t { @@ -324,9 +324,9 @@ IRAM_ATTR bool spi_flash_check_and_flush_cache(size_t start_addr, size_t length) } return ret; } -#endif //!CONFIG_SPI_FLASH_ROM_IMPL +#endif // !ESP_ROM_HAS_SPI_FLASH_MMAP || !CONFIG_SPI_FLASH_ROM_IMPL -#if !CONFIG_SPI_FLASH_ROM_IMPL || CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA +#if !ESP_ROM_HAS_SPI_FLASH_MMAP || !CONFIG_SPI_FLASH_ROM_IMPL || CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA //The ROM implementation returns physical address of the PSRAM when the .text or .rodata is in the PSRAM. //Always patch it when SPIRAM_FETCH_INSTRUCTIONS or SPIRAM_RODATA is set. size_t spi_flash_cache2phys(const void *cached) @@ -401,4 +401,4 @@ const void * spi_flash_phys2cache(size_t phys_offs, spi_flash_mmap_memory_t memo assert(ret == ESP_OK); return (const void *)ptr; } -#endif //!CONFIG_SPI_FLASH_ROM_IMPL || CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA +#endif //!ESP_ROM_HAS_SPI_FLASH_MMAP || !CONFIG_SPI_FLASH_ROM_IMPL || CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index 979d59e6a0..bc332f8e11 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -54,6 +54,7 @@ #include "bootloader_flash_config.h" #include "esp_compiler.h" #include "esp_rom_efuse.h" +#include "esp_rom_caps.h" #include "soc/chip_revision.h" #include "hal/efuse_hal.h" #if CONFIG_SPIRAM @@ -129,12 +130,14 @@ void IRAM_ATTR spi_flash_rom_impl_init(void) { spi_flash_guard_set(&g_flash_guard_default_ops); +#if ESP_ROM_HAS_SPI_FLASH_MMAP /* These two functions are in ROM only */ extern void spi_flash_mmap_os_func_set(void *(*func1)(size_t size), void (*func2)(void *p)); spi_flash_mmap_os_func_set(spi_flash_malloc_internal, heap_caps_free); extern esp_err_t spi_flash_mmap_page_num_init(uint32_t page_num); spi_flash_mmap_page_num_init(128); +#endif // ESP_ROM_HAS_SPI_FLASH_MMAP } #endif diff --git a/examples/system/heap_task_tracking/README.md b/examples/system/heap_task_tracking/README.md deleted file mode 100644 index 64f7f123c3..0000000000 --- a/examples/system/heap_task_tracking/README.md +++ /dev/null @@ -1,39 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | - -# Heap Task Tracking Example - -## Overview - -The example creates a task which allocates random amount of memory in each iteration and demonstrates use of internal API to get heap info on per task basis running in a system. - -Heap task tracking feature has dependency on some of the internal heap debugging features (e.g. heap poisoning) which allows to store task control block in metadata of each heap block. - -This adds small memory overhead on per heap block and hence this feature should be used for debugging purpose only. - -### Configure the project - -To change the `Heap Corruption Detection level`, open the project configuration menu (`idf.py menuconfig`). - -Navigate to `Component config -> Heap memory debugging` menu. In `Heap corruption detection` menu select either "Light Impact" or "Comprehensive". - -**Note:** Enabling “Comprehensive” detection has a substantial runtime performance impact. - -### Build and Flash - -Run `idf.py -p PORT flash monitor` to build and flash the project.. - -(To exit the serial monitor, type ``Ctrl-]``.) - -See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. - -## Example Output - -``` -Task: Pre-Scheduler allocs -> CAP_8BIT: 5360 CAP_32BIT: 0 -Task: esp_timer -> CAP_8BIT: 1724 CAP_32BIT: 0 -Task: ipc0 -> CAP_8BIT: 8316 CAP_32BIT: 0 -Task: main -> CAP_8BIT: 3480 CAP_32BIT: 0 -Task: ipc1 -> CAP_8BIT: 12 CAP_32BIT: 0 -Task: example_task -> CAP_8BIT: 696 CAP_32BIT: 0 -```