fix(esp_tee): Use HAL APIs instead of ROM APIs for SPI flash service calls

Currently, REE SPI flash HAL operations are routed as service calls to TEE,
but the TEE implementation incorrectly uses ROM APIs instead of HAL APIs.
This leads to issues and is not the recommended approach.
This commit is contained in:
Laukik Hase
2025-09-23 19:05:55 +05:30
parent ccc59ed681
commit f20351eb3b
11 changed files with 37 additions and 31 deletions

View File

@@ -6,7 +6,7 @@ set(includes "include" "${target}/include")
if(esp_tee_build)
if(CONFIG_SECURE_TEE_EXT_FLASH_MEMPROT_SPI1)
list(APPEND srcs "spi_flash_hal.c")
list(APPEND srcs "spi_flash_hal.c" "spi_flash_hal_iram.c")
endif()
elseif(NOT BOOTLOADER_BUILD)
if(NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)

View File

@@ -131,15 +131,7 @@ esp_err_t spi_flash_hal_configure_host_io_mode(
addr_bitlen += SPI_FLASH_LL_CONTINUOUS_MODE_BIT_NUMS;
#endif
spi_flash_ll_set_extra_address(dev, 0);
// TODO: [IDF-13582]
// Currently, REE and TEE use different sets of APIs for flash operations -
// REE uses the IDF SPI flash driver while TEE call the ROM APIs. This inconsistency
// leads to compatibility issues on ESP32-C5.
// One specific issue arises when esp_flash_read() is used in REE, which internally
// calls spi_flash_ll_wb_mode_enable(). This function enables the WB mode bit in
// the flash write operation. However, the ROM API does not support this
// feature, resulting in failures when TEE attempts to access flash after this call.
#if SOC_SPI_MEM_SUPPORT_WB_MODE_INDEPENDENT_CONTROL && !CONFIG_SECURE_ENABLE_TEE
#if SOC_SPI_MEM_SUPPORT_WB_MODE_INDEPENDENT_CONTROL
spi_flash_ll_wb_mode_enable(dev, true);
#endif
}
@@ -218,8 +210,7 @@ esp_err_t spi_flash_hal_common_command(spi_flash_host_inst_t *host, spi_flash_tr
if (trans->miso_len > 0) {
spi_flash_ll_get_buffer_data(dev, trans->miso_data, trans->miso_len);
}
// TODO: [IDF-13582]
#if SOC_SPI_MEM_SUPPORT_WB_MODE_INDEPENDENT_CONTROL && !CONFIG_SECURE_ENABLE_TEE
#if SOC_SPI_MEM_SUPPORT_WB_MODE_INDEPENDENT_CONTROL
spi_flash_ll_wb_mode_enable(dev, false);
#endif
return ESP_OK;