Skip to content

Commit 88f66ae

Browse files
committed
Merge branch 'feature/esp_tee_h2' into 'master'
feat(esp_tee): Support for ESP32-H2 See merge request espressif/esp-idf!37708
2 parents ebd4caf + b8e48fb commit 88f66ae

Some content is hidden

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

42 files changed

+1823
-228
lines changed

components/bootloader_support/bootloader_flash/src/bootloader_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
136136
#if ESP_TEE_BUILD
137137
#include "esp_fault.h"
138138
#include "esp_flash_partitions.h"
139-
#include "esp32c6/rom/spi_flash.h"
139+
#include "rom/spi_flash.h"
140140

141141
extern bool esp_tee_flash_check_paddr_in_active_tee_part(size_t paddr);
142142
#endif

components/esp_hw_support/port/esp32h2/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
idf_build_get_property(non_os_build NON_OS_BUILD)
2+
13
set(srcs "rtc_clk_init.c"
24
"rtc_clk.c"
35
"pmu_param.c"
@@ -7,7 +9,7 @@ set(srcs "rtc_clk_init.c"
79
"chip_info.c"
810
)
911

10-
if(NOT BOOTLOADER_BUILD)
12+
if(NOT non_os_build)
1113
list(APPEND srcs "sar_periph_ctrl.c")
1214
endif()
1315

components/esp_hw_support/port/esp32h2/cpu_region_protect.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -112,6 +112,14 @@ void esp_cpu_configure_region_protection(void)
112112
//
113113
esp_cpu_configure_invalid_regions();
114114

115+
/* NOTE: When ESP-TEE is active, only configure invalid memory regions in bootloader
116+
* to prevent errors before TEE initialization. TEE will handle all other
117+
* memory protection.
118+
*/
119+
#if CONFIG_SECURE_ENABLE_TEE && BOOTLOADER_BUILD
120+
return;
121+
#endif
122+
115123
//
116124
// Configure all the valid address regions using PMP
117125
//

components/esp_hw_support/port/esp32h2/esp_cpu_intr.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "esp_cpu.h"
88
#include "esp_riscv_intr.h"
9+
#include "sdkconfig.h"
910

1011
void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_desc_ret)
1112
{
@@ -15,7 +16,18 @@ void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_
1516
* Interrupts 3, 4 and 7 are unavailable for PULP CPU as they are bound to Core-Local Interrupts (CLINT)
1617
*/
1718
// [TODO: IDF-2465]
18-
const uint32_t rsvd_mask = BIT(3) | BIT(4) | BIT(6) | BIT(7);
19+
const uint32_t base_rsvd_mask = BIT(3) | BIT(4) | BIT(6) | BIT(7);
20+
21+
/* On the ESP32-H2, interrupt 14 is reserved for ESP-TEE
22+
* for operations related to secure peripherals under its control
23+
* (e.g. AES, SHA, APM)
24+
*/
25+
#if CONFIG_SECURE_ENABLE_TEE
26+
const uint32_t rsvd_mask = base_rsvd_mask | BIT(14);
27+
#else
28+
const uint32_t rsvd_mask = base_rsvd_mask;
29+
#endif
30+
1931

2032
intr_desc_ret->priority = 1;
2133
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;

components/esp_mm/port/esp32h2/ext_mem_layout.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,15 +10,40 @@
1010
#include "../ext_mem_layout.h"
1111
#include "hal/mmu_types.h"
1212

13+
/* NOTE: With ESP-TEE enabled:
14+
* - The start address is moved by the size of TEE IDROM segments since these
15+
* segments are placed at the start of the linear address space
16+
* - TEE IROM and DROM segments are both 64KB (CONFIG_SECURE_TEE_IROM_SIZE,
17+
* CONFIG_SECURE_TEE_DROM_SIZE) for now. Thus, the number of reserved entries
18+
* from the start would be (64KB + 64KB)/MMU_PAGE_SIZE
19+
* - The last few MMU entries are reserved for TEE flash operations. The number
20+
* of reserved entries matches the size of TEE IDROM segments (IROM + DROM)
21+
* plus one additional entry, i.e. (64KB + 64KB)/MMU_PAGE_SIZE + 1
22+
*/
23+
#if CONFIG_SECURE_ENABLE_TEE
24+
#define TEE_MMU_MEM_REG_START_OFFS (CONFIG_SECURE_TEE_IROM_SIZE + CONFIG_SECURE_TEE_DROM_SIZE)
25+
#define TEE_MMU_RESV_PAGES ((CONFIG_SECURE_TEE_IROM_SIZE + CONFIG_SECURE_TEE_DROM_SIZE) / CONFIG_MMU_PAGE_SIZE)
26+
#define TEE_MMU_MEM_REG_END_OFFS ((TEE_MMU_RESV_PAGES + 1) * CONFIG_MMU_PAGE_SIZE)
27+
28+
#define MMU_MEM_REG_START_ADDR_W_TEE (SOC_MMU_IRAM0_LINEAR_ADDRESS_LOW + TEE_MMU_MEM_REG_START_OFFS)
29+
#define MMU_MEM_REG_END_ADDR_W_TEE (SOC_MMU_IRAM0_LINEAR_ADDRESS_HIGH - TEE_MMU_MEM_REG_END_OFFS)
30+
31+
#define MMU_IRAM0_LINEAR_ADDRESS_LOW MMU_MEM_REG_START_ADDR_W_TEE
32+
#define MMU_IRAM0_LINEAR_ADDRESS_HIGH MMU_MEM_REG_END_ADDR_W_TEE
33+
#else
34+
#define MMU_IRAM0_LINEAR_ADDRESS_LOW SOC_MMU_IRAM0_LINEAR_ADDRESS_LOW
35+
#define MMU_IRAM0_LINEAR_ADDRESS_HIGH SOC_MMU_IRAM0_LINEAR_ADDRESS_HIGH
36+
#endif
37+
1338
/**
1439
* The start addresses in this list should always be sorted from low to high, as MMU driver will need to
1540
* coalesce adjacent regions
1641
*/
1742
const mmu_mem_region_t g_mmu_mem_regions[SOC_MMU_LINEAR_ADDRESS_REGION_NUM] = {
1843
[0] = {
19-
.start = SOC_MMU_IRAM0_LINEAR_ADDRESS_LOW,
20-
.end = SOC_MMU_IRAM0_LINEAR_ADDRESS_HIGH,
21-
.size = SOC_BUS_SIZE(SOC_MMU_IRAM0_LINEAR),
44+
.start = MMU_IRAM0_LINEAR_ADDRESS_LOW,
45+
.end = MMU_IRAM0_LINEAR_ADDRESS_HIGH,
46+
.size = MMU_IRAM0_LINEAR_ADDRESS_HIGH - MMU_IRAM0_LINEAR_ADDRESS_LOW,
2247
.bus_id = CACHE_BUS_IBUS0 | CACHE_BUS_DBUS0,
2348
.targets = MMU_TARGET_FLASH0,
2449
.caps = MMU_MEM_CAP_EXEC | MMU_MEM_CAP_READ | MMU_MEM_CAP_32BIT | MMU_MEM_CAP_8BIT,

components/esp_rom/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,8 @@ if(CONFIG_ESP_ROM_HAS_VERSION)
131131
endif()
132132

133133
if(ESP_TEE_BUILD)
134-
if(target STREQUAL "esp32c6")
135-
rom_linker_script("spiflash")
136-
rom_linker_script("heap")
137-
endif()
134+
rom_linker_script("spiflash")
135+
rom_linker_script("heap")
138136
endif()
139137

140138
if(BOOTLOADER_BUILD)

components/esp_system/ld/esp32h2/memory.ld.in

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
#include "sdkconfig.h"
1616
#include "ld.common"
1717

18-
#define SRAM_SEG_START 0x40800000
18+
#if !CONFIG_SECURE_ENABLE_TEE
19+
#define SRAM_SEG_START (0x40800000)
20+
#else
21+
#define SRAM_SEG_START (0x40800000 + CONFIG_SECURE_TEE_IRAM_SIZE + CONFIG_SECURE_TEE_DRAM_SIZE)
22+
#define FLASH_SEG_OFFSET (CONFIG_SECURE_TEE_IROM_SIZE + CONFIG_SECURE_TEE_DROM_SIZE)
23+
#endif // CONFIG_SECURE_ENABLE_TEE
24+
1925
#define SRAM_SEG_END 0x4083EFD0 /* 2nd stage bootloader iram_loader_seg start address */
2026
#define SRAM_SEG_SIZE SRAM_SEG_END - SRAM_SEG_START
2127

@@ -35,8 +41,14 @@ MEMORY
3541
*/
3642

3743
#if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
44+
#if CONFIG_SECURE_ENABLE_TEE
45+
/* Flash mapped instruction data */
46+
irom_seg (RX) : org = 0x42000020 + FLASH_SEG_OFFSET,
47+
len = IDRAM0_2_SEG_SIZE - FLASH_SEG_OFFSET - 0x20
48+
#else
3849
/* Flash mapped instruction data */
3950
irom_seg (RX) : org = 0x42000020, len = IDRAM0_2_SEG_SIZE - 0x20
51+
#endif
4052

4153
/**
4254
* (0x20 offset above is a convenience for the app binary image generation.
@@ -54,8 +66,14 @@ MEMORY
5466
sram_seg (RWX) : org = SRAM_SEG_START, len = SRAM_SEG_SIZE
5567

5668
#if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
69+
#if CONFIG_SECURE_ENABLE_TEE
5770
/* Flash mapped constant data */
71+
drom_seg (R) : org = 0x42000020 + FLASH_SEG_OFFSET,
72+
len = IDRAM0_2_SEG_SIZE - FLASH_SEG_OFFSET - 0x20
73+
#else
74+
/* Flash mapped instruction data */
5875
drom_seg (R) : org = 0x42000020, len = IDRAM0_2_SEG_SIZE - 0x20
76+
#endif
5977

6078
/* (See irom_seg for meaning of 0x20 offset in the above.) */
6179
#endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS

components/esp_system/ld/esp32h2/sections.ld.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,22 @@ SECTIONS
173173

174174
/* Vectors go to start of IRAM */
175175
ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
176+
_vector_table_start = ABSOLUTE(.);
176177
KEEP(*(.exception_vectors_table.text));
177178
KEEP(*(.exception_vectors.text));
178179

180+
ALIGNED_SYMBOL(4, _invalid_pc_placeholder)
181+
182+
/* esp_tee_config_t structure: used to share information between the TEE and REE
183+
* (e.g. interrupt handler addresses, REE flash text-rodata boundaries, etc.)
184+
* This symbol is expected by the TEE at an offset of 0x300 from the vector table start.
185+
*/
186+
#if CONFIG_SECURE_ENABLE_TEE
187+
ALIGNED_SYMBOL(0x10, _esp_tee_app_cfg)
188+
ASSERT(ABSOLUTE(.) == _vector_table_start + 0x2e0, "esp_tee_app_cfg must be at an offset 0x2e0 from the vector table start");
189+
*libesp_tee.a:(.esp_tee_app_cfg);
190+
#endif
191+
179192
/* Code marked as running out of IRAM */
180193
_iram_text_start = ABSOLUTE(.);
181194

components/esp_system/port/soc/esp32h2/clk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,14 @@ __attribute__((weak)) void esp_perip_clk_init(void)
277277
periph_ll_disable_clk_set_rst(PERIPH_ASSIST_DEBUG_MODULE);
278278
#endif
279279
periph_ll_disable_clk_set_rst(PERIPH_RSA_MODULE);
280+
#if !CONFIG_SECURE_ENABLE_TEE
281+
// NOTE: [ESP-TEE] The TEE is responsible for the AES and SHA peripherals
280282
periph_ll_disable_clk_set_rst(PERIPH_AES_MODULE);
281283
periph_ll_disable_clk_set_rst(PERIPH_SHA_MODULE);
282284
periph_ll_disable_clk_set_rst(PERIPH_ECC_MODULE);
283285
periph_ll_disable_clk_set_rst(PERIPH_HMAC_MODULE);
284286
periph_ll_disable_clk_set_rst(PERIPH_DS_MODULE);
287+
#endif
285288
periph_ll_disable_clk_set_rst(PERIPH_ECDSA_MODULE);
286289

287290
// TODO: Replace with hal implementation

components/esp_tee/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ idf_build_get_property(target IDF_TARGET)
66
# headers & sources here are compiled into the app, not the esp_tee binary
77
# (see subproject/ for the esp_tee binary build files)
88

9-
# ESP-TEE is currently supported only on the ESP32-C6 SoC
10-
if(NOT ${target} STREQUAL "esp32c6")
9+
# ESP-TEE is currently supported only on the ESP32-C6 and ESP32-H2 SoCs
10+
if(NOT ${target} STREQUAL "esp32c6" AND NOT ${target} STREQUAL "esp32h2")
1111
return()
1212
endif()
1313

0 commit comments

Comments
 (0)