Skip to content

Commit e5a8ea0

Browse files
committed
Merge branch 'fix/c5_default_apm_cfg' into 'master'
fix(security): Set all APM masters to operate in TEE mode by default See merge request espressif/esp-idf!39006
2 parents 7cf5dac + 8a999ea commit e5a8ea0

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

components/bootloader_support/src/bootloader_mem.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ void bootloader_init_mem(void)
2727
*/
2828
#ifdef SOC_APM_CTRL_FILTER_SUPPORTED
2929
apm_hal_apm_ctrl_filter_enable_all(false);
30-
#endif
30+
/* [APM] On power-up, only the HP CPU starts in TEE mode; others default to REE2.
31+
* APM blocks REE0–REE2 access by default. C5 ECO2 adds per-peripheral control
32+
* (default REEx blocking), but config support is pending. As a workaround,
33+
* all masters are set to TEE mode.
34+
*/
35+
#if SOC_APM_SUPPORT_TEE_PERI_ACCESS_CTRL
36+
apm_tee_hal_set_master_secure_mode_all(APM_LL_SECURE_MODE_TEE);
37+
#endif // SOC_APM_SUPPORT_TEE_PERI_ACCESS_CTRL
38+
#endif // SOC_APM_CTRL_FILTER_SUPPORTED
3139
#endif
3240

3341
#ifdef CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE

components/hal/apm_hal.c

Lines changed: 11 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
*/
@@ -58,6 +58,16 @@ void apm_tee_hal_set_master_secure_mode(apm_ll_apm_ctrl_t apm_ctrl, apm_ll_maste
5858
apm_tee_ll_set_master_secure_mode(apm_ctrl, master_id, sec_mode);
5959
}
6060

61+
void apm_tee_hal_set_master_secure_mode_all(apm_ll_secure_mode_t sec_mode)
62+
{
63+
for (int i = 0; i < APM_LL_MASTER_MAX; i++) {
64+
apm_tee_hal_set_master_secure_mode(HP_APM_CTRL, i, sec_mode);
65+
}
66+
#if SOC_LP_CORE_SUPPORTED
67+
apm_tee_hal_set_master_secure_mode(LP_APM_CTRL, APM_LL_MASTER_LPCORE, sec_mode);
68+
#endif
69+
}
70+
6171
void apm_tee_hal_clk_gating_enable(bool enable)
6272
{
6373
apm_tee_ll_clk_gating_enable(enable);

components/hal/include/hal/apm_hal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ typedef struct {
136136
void apm_tee_hal_set_master_secure_mode(apm_ll_apm_ctrl_t apm_ctrl, apm_ll_master_id_t master_id,
137137
apm_ll_secure_mode_t sec_mode);
138138

139+
/**
140+
* @brief Set all masters to a given secure mode
141+
*
142+
* @param sec_mode Secure mode
143+
*/
144+
void apm_tee_hal_set_master_secure_mode_all(apm_ll_secure_mode_t sec_mode);
145+
139146
/**
140147
* @brief TEE controller clock auto gating enable
141148
*

components/soc/esp32c5/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,10 @@ config SOC_APM_LP_APM0_SUPPORTED
14271427
bool
14281428
default y
14291429

1430+
config SOC_APM_SUPPORT_TEE_PERI_ACCESS_CTRL
1431+
bool
1432+
default y
1433+
14301434
config SOC_CRYPTO_DPA_PROTECTION_SUPPORTED
14311435
bool
14321436
default y

components/soc/esp32c5/include/soc/soc_caps.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@
558558
#define SOC_BOOTLOADER_ANTI_ROLLBACK_SUPPORTED (0)
559559

560560
/*-------------------------- APM CAPS-----------------------------------------*/
561-
#define SOC_APM_CTRL_FILTER_SUPPORTED 1 /*!< Support for APM control filter */
562-
#define SOC_APM_LP_APM0_SUPPORTED 1 /*!< Support for LP APM0 control filter */
561+
#define SOC_APM_CTRL_FILTER_SUPPORTED 1 /*!< Support for APM control filter */
562+
#define SOC_APM_LP_APM0_SUPPORTED 1 /*!< Support for LP APM0 control filter */
563+
#define SOC_APM_SUPPORT_TEE_PERI_ACCESS_CTRL 1 /*!< Support for TEE controller per-peripheral access control */
563564

564565
/*------------------------ Anti DPA (Security) CAPS --------------------------*/
565566
#define SOC_CRYPTO_DPA_PROTECTION_SUPPORTED 1

0 commit comments

Comments
 (0)