Skip to content

soc: esp32: virtual e-fuses support #90165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions soc/espressif/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ endif

rsource "Kconfig.amp"
rsource "Kconfig.console"
rsource "Kconfig.efuse"
rsource "Kconfig.spiram"
rsource "Kconfig.esptool"
rsource "Kconfig.flash"
47 changes: 47 additions & 0 deletions soc/espressif/common/Kconfig.efuse
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

if SOC_FAMILY_ESPRESSIF_ESP32

config ESP32_EFUSE_VIRTUAL
bool "Simulate eFuse operations in RAM"
help
If "y" - The virtual mode is enabled and all eFuse operations (read and write) are redirected
to RAM instead of eFuse registers, all permanent changes (via eFuse) are disabled.

If it is "y", then SECURE_FLASH_ENCRYPTION_MODE_RELEASE cannot be used.
Because the EFUSE VIRT mode is for testing only.

During startup, the eFuses are copied into RAM. This mode is useful for fast tests.

config ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
bool "Keep eFuses in flash"
depends on ESP32_EFUSE_VIRTUAL
help
In addition to the "Simulate eFuse operations in RAM" option, this option just adds
a feature to keep eFuses after reboots in flash memory. To use this mode the partition_table
should have the `sys_partition` partition.

During startup, the eFuses are copied from flash or,
in case if flash is empty, from real eFuse to RAM and then update flash.
This mode is useful when need to keep changes after reboot
(testing secure_boot and flash_encryption).

config ESP32_EFUSE_VIRTUAL_OFFSET
hex
depends on ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
default $(dt_nodelabel_reg_addr_hex,sys_partition) if $(dt_nodelabel_exists,sys_partition)
default 0x0

config ESP32_EFUSE_VIRTUAL_SIZE
hex
depends on ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
default 0x2000 if $(dt_nodelabel_exists,sys_partition)
default 0x0

config ESP32_EFUSE_MAX_BLK_LEN
int
default 192 if SOC_SERIES_ESP32
default 256

endif # SOC_FAMILY_ESPRESSIF_ESP32
21 changes: 21 additions & 0 deletions soc/espressif/common/include/efuse_virtual.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <esp_efuse.h>

static inline void esp_efuse_init_virtual(void)
{
#if CONFIG_ESP32_EFUSE_VIRTUAL
#if CONFIG_ESP32_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_init_virtual_mode_in_flash(CONFIG_ESP32_EFUSE_VIRTUAL_OFFSET,
CONFIG_ESP32_EFUSE_VIRTUAL_SIZE);
#else
esp_efuse_init_virtual_mode_in_ram();
#endif
#endif
}

3 changes: 3 additions & 0 deletions soc/espressif/esp32/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <psram.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/sys/printk.h>
Expand All @@ -26,6 +27,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

#if CONFIG_ESP_SPIRAM
esp_init_psram();

Expand Down
3 changes: 3 additions & 0 deletions soc/espressif/esp32c2/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/kernel_structs.h>
#include <kernel_internal.h>
Expand All @@ -24,6 +25,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

/* Start Zephyr */
z_cstart();

Expand Down
3 changes: 3 additions & 0 deletions soc/espressif/esp32c3/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/kernel_structs.h>
#include <kernel_internal.h>
Expand All @@ -25,6 +26,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

/* Start Zephyr */
z_cstart();

Expand Down
3 changes: 3 additions & 0 deletions soc/espressif/esp32c6/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/kernel_structs.h>
#include <kernel_internal.h>
Expand All @@ -24,6 +25,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

/* Start Zephyr */
z_cstart();

Expand Down
3 changes: 3 additions & 0 deletions soc/espressif/esp32s2/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <psram.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/sys/printk.h>
Expand Down Expand Up @@ -41,6 +42,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

#if CONFIG_ESP_SPIRAM
esp_init_psram();

Expand Down
3 changes: 3 additions & 0 deletions soc/espressif/esp32s3/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <esp_private/cache_utils.h>
#include <esp_private/system_internal.h>
#include <esp_timer.h>
#include <efuse_virtual.h>
#include <psram.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
#include <zephyr/sys/printk.h>
Expand Down Expand Up @@ -54,6 +55,8 @@ void IRAM_ATTR __esp_platform_app_start(void)

esp_flash_config();

esp_efuse_init_virtual();

#if CONFIG_ESP_SPIRAM
esp_init_psram();

Expand Down
Loading