Skip to content

Commit ea36c4f

Browse files
committed
Merge branch 'feature/esp_tee_c5_v5.5' into 'release/v5.5'
feat(esp_tee): Initial support for ESP32-C5 and related changes (v5.5) See merge request espressif/esp-idf!42357
2 parents fb8d033 + 50d2ecd commit ea36c4f

File tree

108 files changed

+3963
-916
lines changed

Some content is hidden

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

108 files changed

+3963
-916
lines changed

components/bootloader_support/bootloader_flash/src/bootloader_flash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
138138
#include "esp_flash_partitions.h"
139139
#include "rom/spi_flash.h"
140140

141-
extern bool esp_tee_flash_check_paddr_in_active_tee_part(size_t paddr);
141+
extern bool esp_tee_flash_check_prange_in_active_tee_part(const size_t paddr, const size_t len);
142142
#endif
143143

144144
static const char *TAG = "bootloader_flash";
@@ -524,7 +524,7 @@ esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool
524524
* by validating the address before proceeding.
525525
*/
526526
#if ESP_TEE_BUILD
527-
bool addr_chk = esp_tee_flash_check_paddr_in_active_tee_part(dest_addr);
527+
bool addr_chk = esp_tee_flash_check_prange_in_active_tee_part(dest_addr, size);
528528
if (addr_chk) {
529529
ESP_EARLY_LOGE(TAG, "bootloader_flash_write invalid dest_addr");
530530
return ESP_FAIL;
@@ -578,7 +578,7 @@ esp_err_t bootloader_flash_erase_sector(size_t sector)
578578
esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
579579
{
580580
#if ESP_TEE_BUILD
581-
bool addr_chk = esp_tee_flash_check_paddr_in_active_tee_part(start_addr);
581+
bool addr_chk = esp_tee_flash_check_prange_in_active_tee_part(start_addr, size);
582582
if (addr_chk) {
583583
return ESP_ERR_INVALID_ARG;
584584
}

components/esp_hw_support/include/esp_cpu.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,33 @@ FORCE_INLINE_ATTR void esp_cpu_intr_set_mtvt_addr(const void *mtvt_addr)
271271
{
272272
rv_utils_set_mtvt((uint32_t)mtvt_addr);
273273
}
274+
275+
/**
276+
* @brief Set the base address of the current CPU's Interrupt Vector Table (XTVT), based
277+
* on the current privilege level
278+
*
279+
* @param xtvt_addr Interrupt Vector Table's base address
280+
*
281+
* @note The XTVT table is only applicable when CLIC is supported
282+
*/
283+
FORCE_INLINE_ATTR void esp_cpu_intr_set_xtvt_addr(const void *xtvt_addr)
284+
{
285+
rv_utils_set_xtvt((uint32_t)xtvt_addr);
286+
}
274287
#endif //#if SOC_INT_CLIC_SUPPORTED
275288

276289
#if SOC_CPU_SUPPORT_WFE
277290
/**
278291
* @brief Disable the WFE (wait for event) feature for CPU.
279292
*/
280-
FORCE_INLINE_ATTR void rv_utils_disable_wfe_mode(void)
293+
FORCE_INLINE_ATTR void esp_cpu_disable_wfe_mode(void)
281294
{
295+
#if CONFIG_SECURE_ENABLE_TEE && !NON_OS_BUILD
296+
extern esprv_int_mgmt_t esp_tee_intr_sec_srv_cb;
297+
esp_tee_intr_sec_srv_cb(2, SS_RV_UTILS_WFE_MODE_ENABLE, false);
298+
#else
282299
rv_utils_wfe_mode_enable(false);
300+
#endif
283301
}
284302
#endif
285303

@@ -450,9 +468,14 @@ FORCE_INLINE_ATTR uint32_t esp_cpu_intr_get_enabled_mask(void)
450468
{
451469
#ifdef __XTENSA__
452470
return xt_utils_intr_get_enabled_mask();
471+
#else
472+
#if CONFIG_SECURE_ENABLE_TEE && !NON_OS_BUILD && CONFIG_IDF_TARGET_ESP32C5
473+
extern esprv_int_mgmt_t esp_tee_intr_sec_srv_cb;
474+
return esp_tee_intr_sec_srv_cb(1, SS_RV_UTILS_INTR_GET_ENABLED_MASK);
453475
#else
454476
return rv_utils_intr_get_enabled_mask();
455477
#endif
478+
#endif
456479
}
457480

458481
/**

components/esp_hw_support/mspi_timing_tuning/port/esp32c5/mspi_timing_tuning_configs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#define MSPI_TIMING_FLASH_MODULE_CLOCK 120
2929
#endif
3030
//------------------------------------FLASH Needs Tuning or not-------------------------------------//
31-
#if MSPI_TIMING_FLASH_STR_MODE
31+
/* TODO: [ESP-TEE | IDF-10425] The SPI1 controller is protected by APM when ESP-TEE is enabled.
32+
* MSPI tuning requires access to this controller, so it is currently disabled.
33+
*/
34+
#if MSPI_TIMING_FLASH_STR_MODE && !CONFIG_SECURE_ENABLE_TEE
3235
#define MSPI_TIMING_FLASH_NEEDS_TUNING (MSPI_TIMING_FLASH_MODULE_CLOCK > 40)
3336
#endif
3437

@@ -45,7 +48,8 @@
4548
#define MSPI_TIMING_PSRAM_MODULE_CLOCK 10 //Define this to 10MHz
4649
#endif
4750
//------------------------------------PSRAM Needs Tuning or not-------------------------------------//
48-
#if MSPI_TIMING_PSRAM_STR_MODE
51+
/* TODO: [ESP-TEE | IDF-10425] */
52+
#if MSPI_TIMING_PSRAM_STR_MODE && !CONFIG_SECURE_ENABLE_TEE
4953
#define MSPI_TIMING_PSRAM_NEEDS_TUNING (MSPI_TIMING_PSRAM_MODULE_CLOCK > 40)
5054
#endif
5155

components/esp_hw_support/port/esp32c5/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_time.c"
35
"rtc_clk.c"
@@ -8,7 +10,7 @@ set(srcs "rtc_clk_init.c"
810
"ocode_init.c"
911
)
1012

11-
if(NOT BOOTLOADER_BUILD)
13+
if(NOT non_os_build)
1214
list(APPEND srcs "sar_periph_ctrl.c")
1315
endif()
1416

components/esp_hw_support/port/esp32c5/cpu_region_protect.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ void esp_cpu_configure_region_protection(void)
126126
//
127127
esp_cpu_configure_invalid_regions();
128128

129+
/* NOTE: When ESP-TEE is active, only configure invalid memory regions in bootloader
130+
* to prevent errors before TEE initialization. TEE will handle all other
131+
* memory protection.
132+
*/
133+
#if CONFIG_SECURE_ENABLE_TEE && BOOTLOADER_BUILD
134+
return;
135+
#endif
136+
129137
//
130138
// Configure all the valid address regions using PMP
131139
//

components/esp_hw_support/port/esp32c5/esp_cpu_intr.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -15,7 +15,20 @@ void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_
1515
* Reserve interrupt line 1 for the Wifi controller.
1616
* Reserve interrupt line 6 since it is used for disabling interrupts in the interrupt allocator (INT_MUX_DISABLED_INTNO)
1717
*/
18-
const uint32_t rsvd_mask = BIT(1) | BIT(6);
18+
const uint32_t base_rsvd_mask = BIT(1) | BIT(6);
19+
20+
/* On the ESP32-C5, interrupt 31 is reserved for ESP-TEE
21+
* for operations related to secure peripherals under its control
22+
* (e.g. AES, SHA, APM)
23+
*
24+
* Interrupt 30 is reserved for handling REE interrupts occurring in TEE.
25+
*/
26+
#if CONFIG_SECURE_ENABLE_TEE
27+
const uint32_t rsvd_mask = base_rsvd_mask | BIT(30) | BIT(31);
28+
#else
29+
const uint32_t rsvd_mask = base_rsvd_mask;
30+
#endif
31+
1932
intr_desc_ret->priority = 1;
2033
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;
2134
intr_desc_ret->flags = esp_riscv_intr_num_flags(intr_num, rsvd_mask);

components/esp_hw_support/port/esp32c6/esp_cpu_intr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_
1919
// [TODO: IDF-2465]
2020
const uint32_t base_rsvd_mask = BIT(1) | BIT(3) | BIT(4) | BIT(6) | BIT(7);
2121

22-
/* On the ESP32-C6, interrupt 14 is reserved for ESP-TEE
22+
/* On the ESP32-C6, interrupt 31 is reserved for ESP-TEE
2323
* for operations related to secure peripherals under its control
2424
* (e.g. AES, SHA, APM)
2525
*/
2626
#if CONFIG_SECURE_ENABLE_TEE
27-
const uint32_t rsvd_mask = base_rsvd_mask | BIT(14);
27+
const uint32_t rsvd_mask = base_rsvd_mask | BIT(31);
2828
#else
2929
const uint32_t rsvd_mask = base_rsvd_mask;
3030
#endif

components/esp_hw_support/port/esp32h2/cpu_region_protect.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ static void esp_cpu_configure_invalid_regions(void)
6262
// 7. End of address space
6363
PMA_ENTRY_SET_TOR(11, SOC_PERIPHERAL_HIGH, PMA_NONE);
6464
PMA_ENTRY_SET_TOR(12, UINT32_MAX, PMA_TOR | PMA_NONE);
65+
66+
PMA_ENTRY_CFG_RESET(13);
67+
PMA_ENTRY_CFG_RESET(14);
68+
PMA_ENTRY_CFG_RESET(15);
6569
}
6670

6771
void esp_cpu_configure_region_protection(void)

components/esp_hw_support/port/esp32h2/esp_cpu_intr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_
1818
// [TODO: IDF-2465]
1919
const uint32_t base_rsvd_mask = BIT(3) | BIT(4) | BIT(6) | BIT(7);
2020

21-
/* On the ESP32-H2, interrupt 14 is reserved for ESP-TEE
21+
/* On the ESP32-H2, interrupt 31 is reserved for ESP-TEE
2222
* for operations related to secure peripherals under its control
2323
* (e.g. AES, SHA, APM)
2424
*/
2525
#if CONFIG_SECURE_ENABLE_TEE
26-
const uint32_t rsvd_mask = base_rsvd_mask | BIT(14);
26+
const uint32_t rsvd_mask = base_rsvd_mask | BIT(31);
2727
#else
2828
const uint32_t rsvd_mask = base_rsvd_mask;
2929
#endif

components/esp_mm/port/esp32c5/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: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,16 +10,41 @@
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
// TODO: [ESP32C5] IDF-8658
1843
const mmu_mem_region_t g_mmu_mem_regions[SOC_MMU_LINEAR_ADDRESS_REGION_NUM] = {
1944
[0] = {
20-
.start = SOC_MMU_IRAM0_LINEAR_ADDRESS_LOW,
21-
.end = SOC_MMU_IRAM0_LINEAR_ADDRESS_HIGH,
22-
.size = SOC_BUS_SIZE(SOC_MMU_IRAM0_LINEAR),
45+
.start = MMU_IRAM0_LINEAR_ADDRESS_LOW,
46+
.end = MMU_IRAM0_LINEAR_ADDRESS_HIGH,
47+
.size = MMU_IRAM0_LINEAR_ADDRESS_HIGH - MMU_IRAM0_LINEAR_ADDRESS_LOW,
2348
.bus_id = CACHE_BUS_IBUS0 | CACHE_BUS_DBUS0,
2449
.targets = MMU_TARGET_FLASH0 | MMU_TARGET_PSRAM0,
2550
.caps = MMU_MEM_CAP_EXEC | MMU_MEM_CAP_READ | MMU_MEM_CAP_WRITE | MMU_MEM_CAP_32BIT | MMU_MEM_CAP_8BIT,

0 commit comments

Comments
 (0)