From 5e181236b76ea971722a28ea482a320741750021 Mon Sep 17 00:00:00 2001 From: "Armando (Dou Yiwen)" Date: Tue, 25 Aug 2026 18:01:30 +0800 Subject: [PATCH] refactor(mspi): move esp_mspi_align and mspi_mem_barrier to esp_mspi --- components/esp_asrc_adapter/CMakeLists.txt | 2 +- components/esp_driver_dma/CMakeLists.txt | 2 +- .../test_apps/dma/main/CMakeLists.txt | 2 +- components/esp_driver_uart/CMakeLists.txt | 2 +- components/esp_hw_support/CMakeLists.txt | 10 +--- components/esp_hw_support/mspi/linker.lf | 6 -- components/esp_mspi/CMakeLists.txt | 28 +++++++--- .../esp_private/opi_flash_private.h | 0 .../esp_mspi_align/esp_mspi_align.c | 0 .../include/esp_private/esp_mspi_align.h | 0 components/esp_mspi/linker.lf | 56 ++++++++++--------- .../include/esp_private/mspi_mem_barrier.h | 0 .../mspi_mem_barrier/mspi_mem_barrier.c | 0 components/mbedtls/CMakeLists.txt | 4 +- .../g1_components/check_dependencies.py | 3 +- 15 files changed, 61 insertions(+), 54 deletions(-) delete mode 100644 components/esp_hw_support/mspi/linker.lf rename components/esp_mspi/esp32s3/{ => include}/esp_private/opi_flash_private.h (100%) rename components/{esp_hw_support/mspi => esp_mspi}/esp_mspi_align/esp_mspi_align.c (100%) rename components/{esp_hw_support/mspi => esp_mspi}/esp_mspi_align/include/esp_private/esp_mspi_align.h (100%) rename components/{esp_hw_support/mspi => esp_mspi}/mspi_mem_barrier/include/esp_private/mspi_mem_barrier.h (100%) rename components/{esp_hw_support/mspi => esp_mspi}/mspi_mem_barrier/mspi_mem_barrier.c (100%) diff --git a/components/esp_asrc_adapter/CMakeLists.txt b/components/esp_asrc_adapter/CMakeLists.txt index 643d8287dfe..569c07391f5 100644 --- a/components/esp_asrc_adapter/CMakeLists.txt +++ b/components/esp_asrc_adapter/CMakeLists.txt @@ -17,4 +17,4 @@ idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${includes} PRIV_INCLUDE_DIRS "." REQUIRES esp_hal_asrc esp_driver_dma esp_mm - PRIV_REQUIRES esp_hw_support esp_pm) + PRIV_REQUIRES esp_hw_support esp_pm esp_mspi) diff --git a/components/esp_driver_dma/CMakeLists.txt b/components/esp_driver_dma/CMakeLists.txt index 3717cc556fc..527b23899e2 100644 --- a/components/esp_driver_dma/CMakeLists.txt +++ b/components/esp_driver_dma/CMakeLists.txt @@ -50,6 +50,6 @@ idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${public_include} PRIV_INCLUDE_DIRS "src" REQUIRES ${requires} - PRIV_REQUIRES esp_mm efuse + PRIV_REQUIRES esp_mm efuse esp_mspi LDFRAGMENTS "linker.lf" ) diff --git a/components/esp_driver_dma/test_apps/dma/main/CMakeLists.txt b/components/esp_driver_dma/test_apps/dma/main/CMakeLists.txt index abb60644b69..1e19025fef4 100644 --- a/components/esp_driver_dma/test_apps/dma/main/CMakeLists.txt +++ b/components/esp_driver_dma/test_apps/dma/main/CMakeLists.txt @@ -23,7 +23,7 @@ endif() # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - PRIV_REQUIRES unity esp_mm esp_driver_gpio esp_psram esp_driver_dma efuse + PRIV_REQUIRES unity esp_mm esp_driver_gpio esp_psram esp_driver_dma efuse esp_mspi WHOLE_ARCHIVE) idf_component_get_property(lib_name esp_driver_dma COMPONENT_LIB) diff --git a/components/esp_driver_uart/CMakeLists.txt b/components/esp_driver_uart/CMakeLists.txt index 59a6485f02b..5bebc74a6df 100644 --- a/components/esp_driver_uart/CMakeLists.txt +++ b/components/esp_driver_uart/CMakeLists.txt @@ -35,7 +35,7 @@ endif() if(${target} STREQUAL "linux") set(priv_requires esp_ringbuf) else() - set(priv_requires esp_pm esp_driver_gpio esp_driver_dma esp_ringbuf esp_mm) + set(priv_requires esp_pm esp_driver_gpio esp_driver_dma esp_ringbuf esp_mm esp_mspi) endif() idf_component_register( diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 2c0fcfad34d..3123b72baa1 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -14,8 +14,6 @@ endif() set(public_include_dirs "include" "include/soc" "ldo/include" "debug_probe/include" "etm/include" - "mspi/esp_mspi_align/include" - "mspi/mspi_mem_barrier/include" "power_supply/include" "modem/include") if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/include/soc/${target}") @@ -53,9 +51,6 @@ set(priv_requires efuse # only esp_hw_support/adc_share_hw_ctrl. ) set(srcs "cpu.c" "port/${IDF_TARGET}/esp_cpu_intr.c" "esp_memory_utils.c" "port/${IDF_TARGET}/cpu_region_protect.c") -if(NOT BOOTLOADER_BUILD) - list(APPEND srcs "mspi/esp_mspi_align/esp_mspi_align.c") -endif() if(NOT non_os_build) list(APPEND srcs "esp_clk.c" "clk_ctrl_os.c" @@ -74,8 +69,7 @@ if(NOT non_os_build) "port/${target}/esp_clk_tree.c" "spi_bus_lock.c" "heap_align_hw.c" - "clk_utils.c" - "mspi/mspi_mem_barrier/mspi_mem_barrier.c") + "clk_utils.c") if(CONFIG_SOC_USB_OTG_SUPPORTED) list(APPEND srcs "usb_phy/usb_phy.c") endif() @@ -189,7 +183,7 @@ idf_component_register(SRCS ${srcs} PRIV_INCLUDE_DIRS port/include include/esp_private REQUIRES ${requires} PRIV_REQUIRES "${priv_requires}" - LDFRAGMENTS linker.lf ldo/linker.lf mspi/linker.lf) + LDFRAGMENTS linker.lf ldo/linker.lf) idf_define_esp_err_codes(HEADERS include/esp_memprot_err.h) diff --git a/components/esp_hw_support/mspi/linker.lf b/components/esp_hw_support/mspi/linker.lf deleted file mode 100644 index 2264f9f6072..00000000000 --- a/components/esp_hw_support/mspi/linker.lf +++ /dev/null @@ -1,6 +0,0 @@ -[mapping:esp_mspi_align] -archive: libesp_hw_support.a -entries: - if APP_BUILD_TYPE_PURE_RAM_APP = n: - esp_mspi_align:esp_mspi_get_alignment (noflash) - esp_mspi_align:esp_mspi_buffer_alignment_satisfied (noflash) diff --git a/components/esp_mspi/CMakeLists.txt b/components/esp_mspi/CMakeLists.txt index 1dc054ea060..8b390a16379 100644 --- a/components/esp_mspi/CMakeLists.txt +++ b/components/esp_mspi/CMakeLists.txt @@ -9,9 +9,13 @@ if(${target} STREQUAL "linux") endif() if(non_os_build OR CONFIG_APP_BUILD_TYPE_PURE_RAM_APP) - set(priv_requires bootloader_support soc esp_hal_gpio) + # efuse is required by esp_mspi_align.c to query the flash encryption state + set(priv_requires bootloader_support soc esp_hal_gpio efuse) set(requires hal esp_hal_mspi) set(srcs "spi_flash_wrap.c" "spi_flash_os_tee_stub.c") + if(NOT BOOTLOADER_BUILD) + list(APPEND srcs "esp_mspi_align/esp_mspi_align.c") + endif() if(ESP_TEE_BUILD) if(CONFIG_SECURE_TEE_EXT_FLASH_MEMPROT_SPI1) list(APPEND srcs "mspi_timing_tuning/mspi_timing_tuning.c") @@ -27,10 +31,13 @@ if(non_os_build OR CONFIG_APP_BUILD_TYPE_PURE_RAM_APP) endif() endif() else() - set(priv_requires bootloader_support soc esp_hal_gpio esp_mm) + # efuse is required by esp_mspi_align.c to query the flash encryption state + set(priv_requires bootloader_support soc esp_hal_gpio esp_mm efuse) set(requires hal esp_hal_mspi) - set(srcs "flash_brownout_hook.c" "cache_utils.c" "flash_ops.c" "spi_flash_wrap.c") + set(srcs "flash_brownout_hook.c" "cache_utils.c" "flash_ops.c" "spi_flash_wrap.c" + "esp_mspi_align/esp_mspi_align.c" + "mspi_mem_barrier/mspi_mem_barrier.c") # MSPI0 Octal flash init if(CONFIG_SOC_SPI_MEM_SUPPORT_FLASH_OPI_MODE) @@ -69,13 +76,18 @@ endif() set(include_dirs include "mspi_timing_tuning/include" "mspi_timing_tuning/tuning_scheme_impl/include" - "mspi_intr/include") + "mspi_intr/include" + "esp_mspi_align/include" + "mspi_mem_barrier/include") -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}") - list(APPEND include_dirs "${target}") +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include") + list(APPEND include_dirs "${target}/include") endif() -set(ldfragments linker.lf) +set(ldfragments "") +if(NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP) + list(APPEND ldfragments linker.lf) +endif() idf_component_register(SRCS "${srcs}" REQUIRES ${requires} @@ -90,7 +102,7 @@ if(NOT non_os_build AND NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP) # esp_mspi_get_io() queries esp_psram_io_get_cs_io() for the PSRAM CS pin idf_component_optional_requires(PRIVATE esp_psram) endif() - # Force linking init_flash_os ESP_SYSTEM_INIT_FN to ensure it's not discarded by linker + # Force linking init_flash_dpd ESP_SYSTEM_INIT_FN to ensure it's not discarded by linker target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_mspi_flash_ops_include_func") endif() diff --git a/components/esp_mspi/esp32s3/esp_private/opi_flash_private.h b/components/esp_mspi/esp32s3/include/esp_private/opi_flash_private.h similarity index 100% rename from components/esp_mspi/esp32s3/esp_private/opi_flash_private.h rename to components/esp_mspi/esp32s3/include/esp_private/opi_flash_private.h diff --git a/components/esp_hw_support/mspi/esp_mspi_align/esp_mspi_align.c b/components/esp_mspi/esp_mspi_align/esp_mspi_align.c similarity index 100% rename from components/esp_hw_support/mspi/esp_mspi_align/esp_mspi_align.c rename to components/esp_mspi/esp_mspi_align/esp_mspi_align.c diff --git a/components/esp_hw_support/mspi/esp_mspi_align/include/esp_private/esp_mspi_align.h b/components/esp_mspi/esp_mspi_align/include/esp_private/esp_mspi_align.h similarity index 100% rename from components/esp_hw_support/mspi/esp_mspi_align/include/esp_private/esp_mspi_align.h rename to components/esp_mspi/esp_mspi_align/include/esp_private/esp_mspi_align.h diff --git a/components/esp_mspi/linker.lf b/components/esp_mspi/linker.lf index 16796de9ea3..0446e2bbd7a 100644 --- a/components/esp_mspi/linker.lf +++ b/components/esp_mspi/linker.lf @@ -1,38 +1,42 @@ [mapping:esp_mspi] archive: libesp_mspi.a entries: - if APP_BUILD_TYPE_PURE_RAM_APP = n: - flash_brownout_hook (noflash) + flash_brownout_hook (noflash) - if SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM = y: - spi_flash_wrap (noflash) + if SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM = y: + spi_flash_wrap (noflash) - if ESPTOOLPY_OCT_FLASH = y || ESPTOOLPY_FLASH_MODE_AUTO_DETECT = y: - spi_flash_oct_flash_init (noflash) + if ESPTOOLPY_OCT_FLASH = y || ESPTOOLPY_FLASH_MODE_AUTO_DETECT = y: + spi_flash_oct_flash_init (noflash) - if SPI_FLASH_HPM_ON = y: - spi_flash_hpm_enable (noflash) + if SPI_FLASH_HPM_ON = y: + spi_flash_hpm_enable (noflash) - if ESP_SLEEP_SET_FLASH_DPD = y: - spi_flash_dpd_enable (noflash) - flash_ops: dpd_enter_func (noflash) - flash_ops: dpd_exit_func (noflash) + if ESP_SLEEP_SET_FLASH_DPD = y: + spi_flash_dpd_enable (noflash) + flash_ops: dpd_enter_func (noflash) + flash_ops: dpd_exit_func (noflash) - if SOC_GPIO_NEED_SOFT_ISOLATE_DURING_PD = y: - flash_ops: esp_mspi_get_io (noflash) - flash_ops: s_mspi_io_num_default (noflash) + if SOC_GPIO_NEED_SOFT_ISOLATE_DURING_PD = y: + flash_ops: esp_mspi_get_io (noflash) + flash_ops: s_mspi_io_num_default (noflash) + +[mapping:esp_mspi_align] +archive: libesp_mspi.a +entries: + esp_mspi_align:esp_mspi_get_alignment (noflash) + esp_mspi_align:esp_mspi_buffer_alignment_satisfied (noflash) [mapping:mspi_timing_tuning_driver] archive: libesp_mspi.a entries: - if APP_BUILD_TYPE_PURE_RAM_APP = n: - mspi_timing_tuning (noflash) - if SOC_MEMSPI_TIMING_TUNING_BY_MSPI_DELAY = y: - mspi_timing_by_mspi_delay (noflash) - mspi_timing_config (noflash) - if SOC_MEMSPI_TIMING_TUNING_BY_DQS = y: - mspi_timing_by_dqs (noflash) - if SOC_MEMSPI_TIMING_TUNING_BY_FLASH_DELAY = y: - mspi_timing_by_flash_delay (noflash) - if SOC_MEMSPI_TIMING_TUNING_BY_DQS = y || SOC_MEMSPI_TIMING_TUNING_BY_FLASH_DELAY = y: - mspi_timing_config (noflash) + mspi_timing_tuning (noflash) + if SOC_MEMSPI_TIMING_TUNING_BY_MSPI_DELAY = y: + mspi_timing_by_mspi_delay (noflash) + mspi_timing_config (noflash) + if SOC_MEMSPI_TIMING_TUNING_BY_DQS = y: + mspi_timing_by_dqs (noflash) + if SOC_MEMSPI_TIMING_TUNING_BY_FLASH_DELAY = y: + mspi_timing_by_flash_delay (noflash) + if SOC_MEMSPI_TIMING_TUNING_BY_DQS = y || SOC_MEMSPI_TIMING_TUNING_BY_FLASH_DELAY = y: + mspi_timing_config (noflash) diff --git a/components/esp_hw_support/mspi/mspi_mem_barrier/include/esp_private/mspi_mem_barrier.h b/components/esp_mspi/mspi_mem_barrier/include/esp_private/mspi_mem_barrier.h similarity index 100% rename from components/esp_hw_support/mspi/mspi_mem_barrier/include/esp_private/mspi_mem_barrier.h rename to components/esp_mspi/mspi_mem_barrier/include/esp_private/mspi_mem_barrier.h diff --git a/components/esp_hw_support/mspi/mspi_mem_barrier/mspi_mem_barrier.c b/components/esp_mspi/mspi_mem_barrier/mspi_mem_barrier.c similarity index 100% rename from components/esp_hw_support/mspi/mspi_mem_barrier/mspi_mem_barrier.c rename to components/esp_mspi/mspi_mem_barrier/mspi_mem_barrier.c diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt index 68990298c42..491dd0baf42 100644 --- a/components/mbedtls/CMakeLists.txt +++ b/components/mbedtls/CMakeLists.txt @@ -34,7 +34,8 @@ endif() if(NOT ${IDF_TARGET} STREQUAL "linux") set(priv_requires soc esp_hw_support) if(NOT BOOTLOADER_BUILD) - list(APPEND priv_requires esp_pm esp_driver_dma) + # esp_mspi provides esp_mspi_align, used by the AES and SHA DMA ports + list(APPEND priv_requires esp_pm esp_driver_dma esp_mspi) set(requires esp_security esp_hal_security) endif() endif() @@ -374,6 +375,7 @@ if((SHA_PERIPHERAL_TYPE STREQUAL "core" AND CONFIG_SOC_SHA_SUPPORT_DMA) OR AES_P target_link_libraries(builtin PRIVATE idf::esp_hw_support) target_link_libraries(tfpsacrypto PRIVATE idf::esp_mm) target_link_libraries(builtin PRIVATE idf::esp_mm) + target_link_libraries(tfpsacrypto PRIVATE idf::esp_mspi) if(CONFIG_SOC_SHA_GDMA OR CONFIG_SOC_AES_GDMA) if(CONFIG_SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT) target_link_libraries(tfpsacrypto PRIVATE idf::bootloader_support) diff --git a/tools/test_apps/system/g1_components/check_dependencies.py b/tools/test_apps/system/g1_components/check_dependencies.py index 71381930394..f4478511965 100644 --- a/tools/test_apps/system/g1_components/check_dependencies.py +++ b/tools/test_apps/system/g1_components/check_dependencies.py @@ -55,7 +55,8 @@ g1_g0_components = g1_g0_components_base + get_all_esp_hal_components() expected_dep_violations = { 'esp_system': ['esp_timer', 'bootloader_support', 'esp_pm'], 'esp_hw_support': ['efuse', 'bootloader_support', 'esp_driver_gpio', 'esp_timer', 'esp_pm'], - 'esp_mspi': ['bootloader_support'], + # efuse: esp_mspi_align queries the flash encryption state to derive MSPI buffer alignment + 'esp_mspi': ['bootloader_support', 'efuse'], 'cxx': ['pthread'], }