Skip to content

Commit 77c350c

Browse files
wmrsouzakartben
authored andcommitted
soc: esp32: virtual e-fuses support
Adds support for virtual e-fuses on esp32 socs Signed-off-by: Marcio Ribeiro <[email protected]>
1 parent 85f5bd9 commit 77c350c

File tree

9 files changed

+86
-0
lines changed

9 files changed

+86
-0
lines changed

soc/espressif/common/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ endif
6262

6363
rsource "Kconfig.amp"
6464
rsource "Kconfig.console"
65+
rsource "Kconfig.efuse"
6566
rsource "Kconfig.spiram"
6667
rsource "Kconfig.esptool"
6768
rsource "Kconfig.flash"

soc/espressif/common/Kconfig.efuse

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_FAMILY_ESPRESSIF_ESP32
5+
6+
config ESP32_EFUSE_VIRTUAL
7+
bool "Simulate eFuse operations in RAM"
8+
help
9+
If "y" - The virtual mode is enabled and all eFuse operations (read and write) are redirected
10+
to RAM instead of eFuse registers, all permanent changes (via eFuse) are disabled.
11+
12+
If it is "y", then SECURE_FLASH_ENCRYPTION_MODE_RELEASE cannot be used.
13+
Because the EFUSE VIRT mode is for testing only.
14+
15+
During startup, the eFuses are copied into RAM. This mode is useful for fast tests.
16+
17+
config ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
18+
bool "Keep eFuses in flash"
19+
depends on ESP32_EFUSE_VIRTUAL
20+
help
21+
In addition to the "Simulate eFuse operations in RAM" option, this option just adds
22+
a feature to keep eFuses after reboots in flash memory. To use this mode the partition_table
23+
should have the `sys_partition` partition.
24+
25+
During startup, the eFuses are copied from flash or,
26+
in case if flash is empty, from real eFuse to RAM and then update flash.
27+
This mode is useful when need to keep changes after reboot
28+
(testing secure_boot and flash_encryption).
29+
30+
config ESP32_EFUSE_VIRTUAL_OFFSET
31+
hex
32+
depends on ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
33+
default $(dt_nodelabel_reg_addr_hex,sys_partition) if $(dt_nodelabel_exists,sys_partition)
34+
default 0x0
35+
36+
config ESP32_EFUSE_VIRTUAL_SIZE
37+
hex
38+
depends on ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
39+
default 0x2000 if $(dt_nodelabel_exists,sys_partition)
40+
default 0x0
41+
42+
config ESP32_EFUSE_MAX_BLK_LEN
43+
int
44+
default 192 if SOC_SERIES_ESP32
45+
default 256
46+
47+
endif # SOC_FAMILY_ESPRESSIF_ESP32
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include <esp_efuse.h>
9+
10+
static inline void esp_efuse_init_virtual(void)
11+
{
12+
#if CONFIG_ESP32_EFUSE_VIRTUAL
13+
#if CONFIG_ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
14+
esp_efuse_init_virtual_mode_in_flash(CONFIG_ESP32_EFUSE_VIRTUAL_OFFSET,
15+
CONFIG_ESP32_EFUSE_VIRTUAL_SIZE);
16+
#else
17+
esp_efuse_init_virtual_mode_in_ram();
18+
#endif
19+
#endif
20+
}

soc/espressif/esp32/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <esp_private/cache_utils.h>
1212
#include <esp_private/system_internal.h>
1313
#include <esp_timer.h>
14+
#include <efuse_virtual.h>
1415
#include <psram.h>
1516
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1617
#include <zephyr/sys/printk.h>
@@ -26,6 +27,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
2627

2728
esp_flash_config();
2829

30+
esp_efuse_init_virtual();
31+
2932
#if CONFIG_ESP_SPIRAM
3033
esp_init_psram();
3134

soc/espressif/esp32c2/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <esp_private/cache_utils.h>
1111
#include <esp_private/system_internal.h>
1212
#include <esp_timer.h>
13+
#include <efuse_virtual.h>
1314
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1415
#include <zephyr/kernel_structs.h>
1516
#include <kernel_internal.h>
@@ -24,6 +25,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
2425

2526
esp_flash_config();
2627

28+
esp_efuse_init_virtual();
29+
2730
/* Start Zephyr */
2831
z_cstart();
2932

soc/espressif/esp32c3/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <esp_private/cache_utils.h>
1212
#include <esp_private/system_internal.h>
1313
#include <esp_timer.h>
14+
#include <efuse_virtual.h>
1415
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1516
#include <zephyr/kernel_structs.h>
1617
#include <kernel_internal.h>
@@ -25,6 +26,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
2526

2627
esp_flash_config();
2728

29+
esp_efuse_init_virtual();
30+
2831
/* Start Zephyr */
2932
z_cstart();
3033

soc/espressif/esp32c6/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <esp_private/cache_utils.h>
1111
#include <esp_private/system_internal.h>
1212
#include <esp_timer.h>
13+
#include <efuse_virtual.h>
1314
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1415
#include <zephyr/kernel_structs.h>
1516
#include <kernel_internal.h>
@@ -24,6 +25,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
2425

2526
esp_flash_config();
2627

28+
esp_efuse_init_virtual();
29+
2730
/* Start Zephyr */
2831
z_cstart();
2932

soc/espressif/esp32s2/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <esp_private/cache_utils.h>
1111
#include <esp_private/system_internal.h>
1212
#include <esp_timer.h>
13+
#include <efuse_virtual.h>
1314
#include <psram.h>
1415
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1516
#include <zephyr/sys/printk.h>
@@ -41,6 +42,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
4142

4243
esp_flash_config();
4344

45+
esp_efuse_init_virtual();
46+
4447
#if CONFIG_ESP_SPIRAM
4548
esp_init_psram();
4649

soc/espressif/esp32s3/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <esp_private/cache_utils.h>
1212
#include <esp_private/system_internal.h>
1313
#include <esp_timer.h>
14+
#include <efuse_virtual.h>
1415
#include <psram.h>
1516
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
1617
#include <zephyr/sys/printk.h>
@@ -54,6 +55,8 @@ void IRAM_ATTR __esp_platform_app_start(void)
5455

5556
esp_flash_config();
5657

58+
esp_efuse_init_virtual();
59+
5760
#if CONFIG_ESP_SPIRAM
5861
esp_init_psram();
5962

0 commit comments

Comments
 (0)