Skip to content

Commit cb4c738

Browse files
committed
Merge branch 'refactor/esp_tee_ss_layer_in_flash' into 'master'
refactor(esp_tee): Place the secure services `_ss_` layer in the flash by default See merge request espressif/esp-idf!38336
2 parents 3d83751 + a0031cf commit cb4c738

File tree

19 files changed

+552
-655
lines changed

19 files changed

+552
-655
lines changed

components/esp_tee/Kconfig.projbuild

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ menu "ESP-TEE (Trusted Execution Environment)"
1414
config SECURE_TEE_IRAM_SIZE
1515
hex "IRAM region size"
1616
default 0x8000
17-
range 0x8000 0x10000
17+
range 0x7000 0xA000
1818
help
1919
This configuration sets the IRAM size for the TEE module.
20-
This should be a multiple of 0x1000.
20+
This should be 256-byte (0x100) aligned.
2121

2222
config SECURE_TEE_DRAM_SIZE
2323
hex "DRAM region size"
24-
default 0x8000
25-
range 0x8000 0x10000
24+
default 0x6000
25+
range 0x5000 0x7000
2626
help
2727
This configuration sets the DRAM size for the TEE module.
28-
This should be a multiple of 0x1000.
28+
This should be 256-byte (0x100) aligned.
2929

3030
config SECURE_TEE_STACK_SIZE
3131
hex "Stack size"
@@ -34,7 +34,7 @@ menu "ESP-TEE (Trusted Execution Environment)"
3434
help
3535
This configuration sets the stack size for the TEE module.
3636
The TEE stack will be allocated from the TEE DRAM region.
37-
This should be a multiple of 0x100.
37+
This should be 16-byte (0x10) aligned.
3838

3939
config SECURE_TEE_INTR_STACK_SIZE
4040
hex "Interrupt Stack size"
@@ -43,7 +43,7 @@ menu "ESP-TEE (Trusted Execution Environment)"
4343
help
4444
This configuration sets the interrupt stack size for the TEE module.
4545
The TEE interrupt stack will be allocated from the TEE DRAM region.
46-
This should be a multiple of 0x100.
46+
This should be 16-byte (0x10) aligned.
4747

4848
config SECURE_TEE_IROM_SIZE
4949
hex

components/esp_tee/include/private/esp_tee_binary.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ extern "C" {
2323
#define ALIGN_UP_TO_MMU_PAGE_SIZE(addr) (((addr) + (SOC_MMU_PAGE_SIZE) - 1) & ~((SOC_MMU_PAGE_SIZE) - 1))
2424
#define ALIGN_DOWN_TO_MMU_PAGE_SIZE(addr) ((addr) & ~((SOC_MMU_PAGE_SIZE) - 1))
2525

26+
#if ((CONFIG_SECURE_TEE_IRAM_SIZE) & (0xFF))
27+
#error "CONFIG_SECURE_TEE_IRAM_SIZE must be 256-byte (0x100) aligned"
28+
#endif
29+
30+
#if ((CONFIG_SECURE_TEE_DRAM_SIZE) & (0xFF))
31+
#error "CONFIG_SECURE_TEE_DRAM_SIZE must be 256-byte (0x100) aligned"
32+
#endif
33+
34+
#if ((CONFIG_SECURE_TEE_STACK_SIZE) & 0xF)
35+
#error "CONFIG_SECURE_TEE_STACK_SIZE must be 16-byte (0x10) aligned"
36+
#endif
37+
38+
#if ((CONFIG_SECURE_TEE_INTR_STACK_SIZE) & 0xF)
39+
#error "CONFIG_SECURE_TEE_INTR_STACK_SIZE must be 16-byte (0x10) aligned"
40+
#endif
41+
2642
/* NOTE: ESP32-C6 - TEE/REE memory regions */
2743
/* TEE I/DRAM */
2844
#define SOC_S_IRAM_START (SOC_IRAM_LOW)

components/esp_tee/scripts/esp32c6/sec_srv_tbl_default.yml

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,10 @@ secure_services:
134134
- family: hal
135135
entries:
136136
- id: 54
137-
type: IDF
138-
function: efuse_hal_chip_revision
139-
args: 0
140-
- id: 55
141-
type: IDF
142-
function: efuse_hal_get_chip_ver_pkg
143-
args: 1
144-
- id: 56
145-
type: IDF
146-
function: efuse_hal_get_disable_wafer_version_major
147-
args: 0
148-
- id: 57
149-
type: IDF
150-
function: efuse_hal_get_mac
151-
args: 1
152-
- id: 58
153137
type: IDF
154138
function: wdt_hal_init
155139
args: 4
156-
- id: 59
140+
- id: 55
157141
type: IDF
158142
function: wdt_hal_deinit
159143
args: 1
@@ -256,22 +240,7 @@ secure_services:
256240
type: IDF
257241
function: esp_ecc_point_verify
258242
args: 1
259-
# ID: 134-149 (16) - eFuse
260-
- family: efuse
261-
entries:
262-
- id: 134
263-
type: IDF
264-
function: esp_efuse_check_secure_version
265-
args: 1
266-
- id: 135
267-
type: IDF
268-
function: esp_efuse_read_field_blob
269-
args: 3
270-
- id: 136
271-
type: IDF
272-
function: esp_flash_encryption_enabled
273-
args: 0
274-
# ID: 150-169 (20) - Reserved for future use
243+
# ID: 134-169 (36) - Reserved for future use
275244
- family: attestation
276245
entries:
277246
- id: 170

components/esp_tee/src/esp_secure_service_wrapper.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <stdarg.h>
77

88
#include "esp_err.h"
9-
#include "esp_efuse.h"
109
#include "esp_random.h"
1110

1211
#include "hal/sha_types.h"
@@ -32,43 +31,6 @@ void IRAM_ATTR __wrap_esp_rom_route_intr_matrix(int cpu_no, uint32_t model_num,
3231
esp_tee_service_call(4, SS_ESP_ROM_ROUTE_INTR_MATRIX, cpu_no, model_num, intr_num);
3332
}
3433

35-
/* ---------------------------------------------- eFuse ------------------------------------------------- */
36-
37-
uint32_t __wrap_efuse_hal_chip_revision(void)
38-
{
39-
return esp_tee_service_call(1, SS_EFUSE_HAL_CHIP_REVISION);
40-
}
41-
42-
uint32_t __wrap_efuse_hal_get_chip_ver_pkg(void)
43-
{
44-
return esp_tee_service_call(1, SS_EFUSE_HAL_GET_CHIP_VER_PKG);
45-
}
46-
47-
bool __wrap_efuse_hal_get_disable_wafer_version_major(void)
48-
{
49-
return esp_tee_service_call(1, SS_EFUSE_HAL_GET_DISABLE_WAFER_VERSION_MAJOR);
50-
}
51-
52-
void __wrap_efuse_hal_get_mac(uint8_t *mac)
53-
{
54-
esp_tee_service_call(2, SS_EFUSE_HAL_GET_MAC, mac);
55-
}
56-
57-
bool __wrap_esp_efuse_check_secure_version(uint32_t secure_version)
58-
{
59-
return esp_tee_service_call(4, SS_ESP_EFUSE_CHECK_SECURE_VERSION, secure_version);
60-
}
61-
62-
esp_err_t __wrap_esp_efuse_read_field_blob(const esp_efuse_desc_t *field[], void *dst, size_t dst_size_bits)
63-
{
64-
return esp_tee_service_call(4, SS_ESP_EFUSE_READ_FIELD_BLOB, (uint32_t)field, (uint32_t)dst, (uint32_t)dst_size_bits);
65-
}
66-
67-
bool __wrap_esp_flash_encryption_enabled(void)
68-
{
69-
return esp_tee_service_call(1, SS_ESP_FLASH_ENCRYPTION_ENABLED);
70-
}
71-
7234
/* ---------------------------------------------- RTC_WDT ------------------------------------------------- */
7335

7436
void __wrap_wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescaler, bool enable_intr)

components/esp_tee/subproject/components/tee_sec_storage/include/esp_tee_sec_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include <stddef.h>
1313
#include <stdint.h>
1414
#include <stdbool.h>
15+
#include "esp_err.h"
1516

1617
#define MIN_SEC_STG_SLOT_ID 0 /*!< Minimum secure storage slot ID */
1718
#define MAX_SEC_STG_SLOT_ID 14 /*!< Maximum secure storage slot ID */

components/esp_tee/subproject/main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(include)
99
set(srcs "core/esp_tee_init.c"
1010
"core/esp_tee_intr.c"
1111
"core/esp_secure_services.c"
12+
"core/esp_secure_services_iram.c"
1213
"core/esp_secure_dispatcher.c"
1314
"core/esp_secure_service_table.c")
1415

components/esp_tee/subproject/main/common/panic/esp_tee_panic.c

Lines changed: 27 additions & 36 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
*/
@@ -20,12 +20,12 @@
2020
#include "esp_tee.h"
2121
#include "esp_tee_apm_intr.h"
2222
#include "esp_tee_rv_utils.h"
23+
2324
#include "panic_helper.h"
25+
#include "sdkconfig.h"
2426

2527
#define RV_FUNC_STK_SZ (32)
2628

27-
#define tee_panic_print(format, ...) esp_rom_printf(DRAM_STR(format), ##__VA_ARGS__)
28-
2929
static void tee_panic_end(void)
3030
{
3131
// Disable interrupts
@@ -67,26 +67,27 @@ void abort(void)
6767
ESP_INFINITE_LOOP();
6868
}
6969

70+
static void panic_print_info(const void *frame, int core)
71+
{
72+
panic_print_registers((const void *)frame, core);
73+
tee_panic_print("\n");
74+
panic_print_backtrace((const void *)frame, 100);
75+
tee_panic_print("\n");
76+
tee_panic_print("Rebooting...\r\n\n");
77+
78+
tee_panic_end();
79+
}
80+
7081
static void panic_handler(void *frame, bool pseudo_exccause)
7182
{
7283
int fault_core = esp_cpu_get_core_id();
73-
74-
tee_panic_print("\n=================================================\n");
75-
tee_panic_print("Secure exception occurred on Core %d\n", fault_core);
7684
if (pseudo_exccause) {
7785
panic_print_isrcause((const void *)frame, fault_core);
7886
} else {
7987
panic_print_exccause((const void *)frame, fault_core);
8088
}
81-
tee_panic_print("=================================================\n");
8289

83-
panic_print_registers((const void *)frame, fault_core);
84-
tee_panic_print("\n");
85-
panic_print_backtrace((const void *)frame, 100);
86-
tee_panic_print("\n");
87-
tee_panic_print("Rebooting...\r\n\n");
88-
89-
tee_panic_end();
90+
panic_print_info((const void *)frame, fault_core);
9091
ESP_INFINITE_LOOP();
9192
}
9293

@@ -105,34 +106,24 @@ void tee_apm_violation_isr(void *arg)
105106
intptr_t exc_sp = RV_READ_CSR(mscratch);
106107
RvExcFrame *frame = (RvExcFrame *)exc_sp;
107108

108-
apm_ctrl_path_t *apm_excp_type = NULL;
109-
apm_ctrl_exception_info_t excp_info;
110-
111-
apm_excp_type = (apm_ctrl_path_t *)arg;
109+
apm_ctrl_path_t *apm_excp_type = (apm_ctrl_path_t *)arg;
110+
apm_ctrl_exception_info_t excp_info = {
111+
.apm_path = {
112+
.apm_ctrl = apm_excp_type->apm_ctrl,
113+
.apm_m_path = apm_excp_type->apm_m_path,
114+
}
115+
};
112116

113-
excp_info.apm_path.apm_ctrl = apm_excp_type->apm_ctrl;
114-
excp_info.apm_path.apm_m_path = apm_excp_type->apm_m_path;
115117
apm_hal_apm_ctrl_get_exception_info(&excp_info);
116-
117-
/* Clear APM M path interrupt. */
118118
apm_hal_apm_ctrl_exception_clear(apm_excp_type);
119119

120120
int fault_core = esp_cpu_get_core_id();
121+
panic_print_rsn((const void *)frame, fault_core, esp_tee_apm_excp_type_to_str(excp_info.excp_type));
121122

122-
tee_panic_print("\n=================================================\n");
123-
tee_panic_print("APM permission violation occurred on Core %d\n", fault_core);
124-
tee_panic_print("Guru Meditation Error: Core %d panic'ed (%s). ", fault_core, esp_tee_apm_excp_type_to_str(excp_info.excp_type));
125-
tee_panic_print("Exception was unhandled.\n");
126-
tee_panic_print("Fault addr: 0x%x | Mode: %s\n", excp_info.excp_addr, esp_tee_apm_excp_mode_to_str(excp_info.excp_mode));
127-
tee_panic_print("Module: %s | Path: 0x%02x\n", esp_tee_apm_excp_ctrl_to_str(excp_info.apm_path.apm_ctrl), excp_info.apm_path.apm_m_path);
128-
tee_panic_print("Master: %s | Region: 0x%02x\n", esp_tee_apm_excp_mid_to_str(excp_info.excp_id), excp_info.excp_regn);
129-
tee_panic_print("=================================================\n");
130-
panic_print_registers((const void *)frame, fault_core);
131-
tee_panic_print("\n");
132-
panic_print_backtrace((const void *)frame, 100);
133-
tee_panic_print("\n");
134-
tee_panic_print("Rebooting...\r\n\n");
123+
tee_panic_print("Access addr: 0x%x | Mode: %s\n", excp_info.excp_addr, esp_tee_apm_excp_mode_to_str(excp_info.excp_mode));
124+
tee_panic_print("Module: %s | Path: %d\n", esp_tee_apm_excp_ctrl_to_str(excp_info.apm_path.apm_ctrl), excp_info.apm_path.apm_m_path);
125+
tee_panic_print("Master: %s | Region: %d\n", esp_tee_apm_excp_mid_to_str(excp_info.excp_id), (excp_info.excp_regn == 0) ? 0 : (__builtin_ffs(excp_info.excp_regn) - 1));
135126

136-
tee_panic_end();
127+
panic_print_info((const void *)frame, fault_core);
137128
ESP_INFINITE_LOOP();
138129
}

components/esp_tee/subproject/main/common/panic/panic_helper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
#include <stdarg.h>
7+
#include "esp_rom_sys.h"
8+
9+
#if CONFIG_SECURE_TEE_DEBUG_MODE
10+
#define tee_panic_print(format, ...) esp_rom_printf(DRAM_STR(format), ##__VA_ARGS__)
11+
#else
12+
#define tee_panic_print(format, ...)
13+
#endif
614

715
void panic_print_backtrace(const void *f, int depth);
816

917
void panic_print_registers(const void *f, int core);
1018

19+
void panic_print_rsn(const void *f, int core, const char *rsn);
20+
1121
void panic_print_exccause(const void *f, int core);
1222

1323
void panic_print_isrcause(const void *f, int core);

0 commit comments

Comments
 (0)