Skip to content

Commit 870a184

Browse files
committed
Merge branch 'feature/esp_tee_flash_prot_spi1' into 'master'
feat(esp_tee): Add support for flash memory isolation and protection (SPI1) Closes IDF-10481, IDF-10083, and IDF-8915 See merge request espressif/esp-idf!36454
2 parents 2038851 + 7d49f69 commit 870a184

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1240
-244
lines changed

components/bootloader_support/bootloader_flash/src/bootloader_flash.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -752,6 +752,15 @@ esp_err_t IRAM_ATTR bootloader_flash_unlock_default(void)
752752

753753
esp_err_t __attribute__((weak, alias("bootloader_flash_unlock_default"))) bootloader_flash_unlock(void);
754754

755+
756+
#if CONFIG_SECURE_TEE_EXT_FLASH_MEMPROT_SPI1 && !NON_OS_BUILD
757+
extern uint32_t bootloader_flash_execute_command_common(
758+
uint8_t command,
759+
uint32_t addr_len, uint32_t address,
760+
uint8_t dummy_len,
761+
uint8_t mosi_len, uint32_t mosi_data,
762+
uint8_t miso_len);
763+
#else
755764
IRAM_ATTR uint32_t bootloader_flash_execute_command_common(
756765
uint8_t command,
757766
uint32_t addr_len, uint32_t address,
@@ -804,6 +813,7 @@ IRAM_ATTR uint32_t bootloader_flash_execute_command_common(
804813
}
805814
return ret;
806815
}
816+
#endif
807817

808818
uint32_t IRAM_ATTR bootloader_execute_flash_command(uint8_t command, uint32_t mosi_data, uint8_t mosi_len, uint8_t miso_len)
809819
{

components/esp_tee/CMakeLists.txt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
idf_build_get_property(esp_tee_build ESP_TEE_BUILD)
2-
idf_build_get_property(custom_secure_service_tbl CUSTOM_SECURE_SERVICE_TBL)
2+
idf_build_get_property(custom_secure_service_yaml CUSTOM_SECURE_SERVICE_YAML)
33
idf_build_get_property(custom_secure_service_dir CUSTOM_SECURE_SERVICE_COMPONENT_DIR)
44
idf_build_get_property(custom_secure_service_component CUSTOM_SECURE_SERVICE_COMPONENT)
55
idf_build_get_property(target IDF_TARGET)
@@ -82,33 +82,37 @@ else()
8282
endif()
8383
endif()
8484

85-
set(secure_service_tbl_parser_py
86-
${COMPONENT_DIR}/scripts/secure_service_tbl_parser.py ${CMAKE_CURRENT_BINARY_DIR}/secure_service.tbl
85+
set(secure_service_yml
86+
${COMPONENT_DIR}/scripts/${IDF_TARGET}/sec_srv_tbl_default.yml ${custom_secure_service_yaml}
8787
)
8888

89-
set(secure_service_gen_headers
90-
${CONFIG_DIR}/secure_service_num.h ${CONFIG_DIR}/secure_service_dec.h
91-
${CONFIG_DIR}/secure_service_int.h ${CONFIG_DIR}/secure_service_ext.h
89+
set(secure_service_yml_parser_py
90+
${COMPONENT_DIR}/scripts/secure_service_yml_parser.py
9291
)
9392

9493
if(CONFIG_SECURE_ENABLE_TEE AND NOT esp_tee_build)
95-
execute_process(
96-
COMMAND cat ${COMPONENT_DIR}/scripts/${target}/secure_service.tbl ${custom_secure_service_tbl}
97-
OUTPUT_FILE secure_service.tbl
98-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
99-
)
94+
# Default secure service API families: flash_protection_spi0, flash_protection_spi1,
95+
# interrupt_handling, hal, crypto, efuse, secure_storage, ota, attestation
96+
set(exclude_srv)
97+
if(NOT CONFIG_SECURE_TEE_EXT_FLASH_MEMPROT_SPI1)
98+
list(APPEND exclude_srv "flash_protection_spi1")
99+
endif()
100100

101-
execute_process(
102-
COMMAND python ${secure_service_tbl_parser_py} ${secure_service_gen_headers}
103-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
104-
)
101+
if(NOT CONFIG_SECURE_TEE_ATTESTATION)
102+
list(APPEND exclude_srv "attestation")
103+
endif()
105104

106-
set_property(DIRECTORY ${COMPONENT_DIR} APPEND PROPERTY
107-
ADDITIONAL_MAKE_CLEAN_FILES ${secure_service_gen_headers}
105+
execute_process(
106+
COMMAND python ${secure_service_yml_parser_py}
107+
"--sec_srv" ${secure_service_yml}
108+
"--exclude" ${exclude_srv}
109+
WORKING_DIRECTORY ${CONFIG_DIR}
108110
)
109111

110112
execute_process(
111-
COMMAND python ${secure_service_tbl_parser_py} "--wrap"
113+
COMMAND python ${secure_service_yml_parser_py}
114+
"--sec_srv" ${secure_service_yml}
115+
"--exclude" ${exclude_srv} "--wrap"
112116
OUTPUT_VARIABLE wrap_list
113117
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
114118
OUTPUT_STRIP_TRAILING_WHITESPACE

components/esp_tee/Kconfig.projbuild

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,35 @@ menu "ESP-TEE (Trusted Execution Environment)"
110110

111111
endmenu
112112

113+
config SECURE_TEE_EXT_FLASH_MEMPROT_SPI1
114+
bool "Memprot: Isolate TEE flash regions over SPI1"
115+
depends on SECURE_ENABLE_TEE
116+
default n
117+
help
118+
This configuration restricts access to TEE-reserved regions in external flash
119+
by making them inaccessible to the REE via the SPI1 interface (physical addresses).
120+
121+
With this enabled, all SPI flash read, write, or erase operations over SPI1 will
122+
be routed through service calls to the TEE, introducing additional performance
123+
overhead.
124+
125+
When Flash Encryption (SECURE_FLASH_ENC_ENABLED) is enabled, the REE can still
126+
access TEE-related flash partitions over SPI1, but read operations will return
127+
encrypted data contents. This prevents attackers from inferring the TEE contents
128+
with direct reads.
129+
130+
Additionally, with Secure Boot enabled (SECURE_BOOT_V2_ENABLED), any unauthorized
131+
modifications to the TEE firmware will be detected during boot, causing signature
132+
verification to fail. Thus, these options provide a level of protection suitable for
133+
most applications. However, while the TEE firmware integrity is protected, other TEE
134+
partitions (Secure Storage, TEE OTA data) can be manipulated through direct writes.
135+
136+
Enable this option only when complete isolation of all TEE flash regions is required,
137+
even with the associated performance tradeoffs.
138+
139+
Note: All accesses to the TEE partitions over SPI0 (i.e. the MMU) are blocked
140+
unconditionally.
141+
113142
config SECURE_TEE_DEBUG_MODE
114143
bool "Enable Debug Mode"
115144
default y

0 commit comments

Comments
 (0)