Skip to content

Commit e52e2d2

Browse files
committed
refactor(startup): move key manager specific code to esp_security component
1 parent 336f938 commit e52e2d2

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

components/esp_security/src/init.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,44 @@
66

77
#include "esp_private/startup_internal.h"
88
#include "sdkconfig.h"
9+
#include "soc/soc_caps.h"
910
#include "esp_crypto_clk.h"
1011
#include "esp_efuse.h"
1112
#include "esp_efuse_table.h"
1213
#include "esp_security_priv.h"
1314
#include "esp_err.h"
15+
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
16+
#include "hal/key_mgr_ll.h"
17+
#endif
1418

1519
__attribute__((unused)) static const char *TAG = "esp_security";
1620

21+
static void esp_key_mgr_init(void)
22+
{
23+
// The following operation makes the Key Manager to use eFuse key for ECDSA and XTS-AES operation by default
24+
// This is to keep the default behavior same as the other chips
25+
// If the Key Manager configuration is already locked then following operation does not have any effect
26+
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
27+
// Enable key manager clock
28+
// Using ll APIs which do not require critical section
29+
_key_mgr_ll_enable_bus_clock(true);
30+
_key_mgr_ll_enable_peripheral_clock(true);
31+
32+
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
33+
};
34+
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY
35+
key_mgr_ll_set_key_usage(ESP_KEY_MGR_ECDSA_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
36+
#endif
37+
#if SOC_KEY_MANAGER_FE_KEY_DEPLOY
38+
key_mgr_ll_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
39+
#endif
40+
#endif /* SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY */
41+
}
42+
1743
ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
1844
{
1945
esp_crypto_clk_init();
46+
esp_key_mgr_init();
2047
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
2148
esp_crypto_dpa_protection_startup();
2249
#endif

components/esp_system/port/cpu_start.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@
7171
#include "soc/hp_sys_clkrst_reg.h"
7272
#endif
7373

74-
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
75-
#include "hal/key_mgr_ll.h"
76-
#endif
77-
7874
#include "esp_private/rtc_clk.h"
7975

8076
#if SOC_INT_CLIC_SUPPORTED
@@ -319,22 +315,6 @@ static void start_other_core(void)
319315
}
320316
#endif
321317

322-
// The following operation makes the Key Manager to use eFuse key for ECDSA and XTS-AES operation by default
323-
// This is to keep the default behavior same as the other chips
324-
// If the Key Manager configuration is already locked then following operation does not have any effect
325-
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
326-
// Enable key manager clock
327-
// Using ll APIs which do not require critical section
328-
_key_mgr_ll_enable_bus_clock(true);
329-
_key_mgr_ll_enable_peripheral_clock(true);
330-
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY
331-
key_mgr_ll_set_key_usage(ESP_KEY_MGR_ECDSA_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
332-
#endif
333-
#if SOC_KEY_MANAGER_FE_KEY_DEPLOY
334-
key_mgr_ll_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
335-
#endif
336-
#endif /* SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY */
337-
338318
ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1);
339319

340320
bool cpus_up = false;

0 commit comments

Comments
 (0)