diff --git a/arch/xtensa/src/common/espressif/Kconfig b/arch/xtensa/src/common/espressif/Kconfig index 601e77983f1..e4fcf22cea6 100644 --- a/arch/xtensa/src/common/espressif/Kconfig +++ b/arch/xtensa/src/common/espressif/Kconfig @@ -53,7 +53,7 @@ config ESPRESSIF_EFUSE_VIRTUAL depends on ESPRESSIF_EFUSE default n ---help--- - Enable virtual efuse support to simulate eFuse operations in RAM, changes will be reverted each reboot + Enable virtual efuse support to simulate eFuse operations in RAM, changes will be reverted each reboot. config ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH bool "Keep E-Fuses in flash" @@ -67,23 +67,25 @@ config ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH This mode is useful when need to keep changes after reboot (testing secure_boot, flash_encryption or using MCUBoot + encryption). -if ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH +if ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH || ESPRESSIF_BOOTLOADER_MCUBOOT + +menu "Virtual E-Fuse Options" config ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET - hex "E-Fuses offset in flash" - depends on ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH - default 0x250000 + hex "Virtual E-Fuses offset in flash" + default 0x10000 if ESPRESSIF_BOOTLOADER_MCUBOOT + default 0x250000 if !ESPRESSIF_BOOTLOADER_MCUBOOT ---help--- Offset in flash where the E-Fuses will be stored when using the "E-Fuses size to keep in flash" option. config ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_SIZE - hex "E-Fuses size to keep in flash" - depends on ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH + hex "Virtual E-Fuses size to keep in flash" default 0x2000 ---help--- Size of E-Fuse region to keep in flash. -endif # ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH +endmenu # Virtual E-Fuse Options +endif # ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH || ESPRESSIF_BOOTLOADER_MCUBOOT config ESPRESSIF_TEMP bool "Internal Temperature Sensor" @@ -1123,7 +1125,7 @@ comment "Application Image OTA Update support" config ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET hex "Application image primary slot offset" - default 0x10000 + default 0x20000 config ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH string "Application image primary slot device path" @@ -1131,7 +1133,7 @@ config ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH config ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET hex "Application image secondary slot offset" - default 0x110000 + default 0x120000 config ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH string "Application image secondary slot device path" @@ -1143,7 +1145,7 @@ config ESPRESSIF_OTA_SLOT_SIZE config ESPRESSIF_OTA_SCRATCH_OFFSET hex "Scratch partition offset" - default 0x210000 + default 0x220000 config ESPRESSIF_OTA_SCRATCH_SIZE hex "Scratch partition size" diff --git a/arch/xtensa/src/esp32/Bootloader.mk b/arch/xtensa/src/esp32/Bootloader.mk index 072abff7939..c98b614c727 100644 --- a/arch/xtensa/src/esp32/Bootloader.mk +++ b/arch/xtensa/src/esp32/Bootloader.mk @@ -125,6 +125,14 @@ ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) $(call cfg_en,CONFIG_IDF_TARGET_ARCH_XTENSA) \ $(call cfg_val,CONFIG_BOOTLOADER_LOG_LEVEL,3) \ } >> $(BOOTLOADER_CONFIG) +ifeq ($(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH),y) + $(Q) { \ + $(call cfg_en,CONFIG_EFUSE_VIRTUAL) \ + $(call cfg_en,CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH) \ + $(call cfg_val,CONFIG_EFUSE_VIRTUAL_OFFSET,$(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET)) \ + $(call cfg_val,CONFIG_EFUSE_VIRTUAL_SIZE,$(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_SIZE)) \ + } >> $(BOOTLOADER_CONFIG) +endif else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y) $(Q) { \ $(call cfg_en,CONFIG_PARTITION_TABLE_CUSTOM) \ diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig index 0dac8a3afba..a77fb9d4ff2 100644 --- a/arch/xtensa/src/esp32/Kconfig +++ b/arch/xtensa/src/esp32/Kconfig @@ -1835,7 +1835,7 @@ config ESP32_OTA_PARTITION_ENCRYPT config ESP32_OTA_PRIMARY_SLOT_OFFSET hex "Application image primary slot offset" - default 0x10000 + default 0x20000 config ESP32_OTA_PRIMARY_SLOT_DEVPATH string "Application image primary slot device path" @@ -1843,7 +1843,7 @@ config ESP32_OTA_PRIMARY_SLOT_DEVPATH config ESP32_OTA_SECONDARY_SLOT_OFFSET hex "Application image secondary slot offset" - default 0x110000 + default 0x120000 config ESP32_OTA_SECONDARY_SLOT_DEVPATH string "Application image secondary slot device path" @@ -1855,7 +1855,7 @@ config ESP32_OTA_SLOT_SIZE config ESP32_OTA_SCRATCH_OFFSET hex "Scratch partition offset" - default 0x210000 + default 0x220000 config ESP32_OTA_SCRATCH_SIZE hex "Scratch partition size" @@ -2793,7 +2793,7 @@ endchoice config ESP32_MCUBOOT_VERSION string "MCUboot version" depends on ESP32_APP_FORMAT_MCUBOOT - default "20f98e0a975c24864872e0df5701eb1082e9c957" + default "aa4fa2b6e17361dd3ce16a60883059778fd147a9" config ESP32_APP_MCUBOOT_HEADER_SIZE int "Application image header size (in bytes)" diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 47d995bf51a..8e2620eaa9a 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -284,5 +284,6 @@ endif distclean:: $(call DELDIR,chip/$(ESP_HAL_3RDPARTY_REPO)) + $(call DELFILE,../../../vefuse.bin) INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)common$(DELIM)espressif diff --git a/arch/xtensa/src/esp32s2/Kconfig b/arch/xtensa/src/esp32s2/Kconfig index 9354e39b984..3b7d74d8712 100644 --- a/arch/xtensa/src/esp32s2/Kconfig +++ b/arch/xtensa/src/esp32s2/Kconfig @@ -1448,7 +1448,7 @@ endchoice config ESP32S2_MCUBOOT_VERSION string "MCUboot version" - default "20f98e0a975c24864872e0df5701eb1082e9c957" + default "aa4fa2b6e17361dd3ce16a60883059778fd147a9" depends on ESP32S2_APP_FORMAT_MCUBOOT config ESP32S2_APP_MCUBOOT_HEADER_SIZE diff --git a/arch/xtensa/src/esp32s2/Make.defs b/arch/xtensa/src/esp32s2/Make.defs index e850cf1669c..a34d11426fe 100644 --- a/arch/xtensa/src/esp32s2/Make.defs +++ b/arch/xtensa/src/esp32s2/Make.defs @@ -188,3 +188,4 @@ distclean:: ifeq ($(CONFIG_ESPRESSIF_USE_ULP_RISCV_CORE),y) $(call DELDIR,chip/ulp) endif + $(call DELFILE,../../../vefuse.bin) diff --git a/arch/xtensa/src/esp32s3/Bootloader.mk b/arch/xtensa/src/esp32s3/Bootloader.mk index c247d79677e..d3f6d16e29c 100644 --- a/arch/xtensa/src/esp32s3/Bootloader.mk +++ b/arch/xtensa/src/esp32s3/Bootloader.mk @@ -96,6 +96,14 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y) $(call cfg_en,CONFIG_IDF_TARGET_ARCH_XTENSA) \ $(call cfg_val,CONFIG_BOOTLOADER_LOG_LEVEL,3) \ } >> $(BOOTLOADER_CONFIG) +ifeq ($(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH),y) + $(Q) { \ + $(call cfg_en,CONFIG_EFUSE_VIRTUAL) \ + $(call cfg_en,CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH) \ + $(call cfg_val,CONFIG_EFUSE_VIRTUAL_OFFSET,$(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET)) \ + $(call cfg_val,CONFIG_EFUSE_VIRTUAL_SIZE,$(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_SIZE)) \ + } >> $(BOOTLOADER_CONFIG) +endif else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y) $(Q) { \ $(call cfg_en,CONFIG_PARTITION_TABLE_CUSTOM) \ diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig index 8697b5d0163..ad440bb9563 100644 --- a/arch/xtensa/src/esp32s3/Kconfig +++ b/arch/xtensa/src/esp32s3/Kconfig @@ -1925,7 +1925,7 @@ comment "Application Image OTA Update support" config ESP32S3_OTA_PRIMARY_SLOT_OFFSET hex "Application image primary slot offset" - default 0x10000 + default 0x20000 config ESP32S3_OTA_PRIMARY_SLOT_DEVPATH string "Application image primary slot device path" @@ -1933,7 +1933,7 @@ config ESP32S3_OTA_PRIMARY_SLOT_DEVPATH config ESP32S3_OTA_SECONDARY_SLOT_OFFSET hex "Application image secondary slot offset" - default 0x110000 + default 0x120000 config ESP32S3_OTA_SECONDARY_SLOT_DEVPATH string "Application image secondary slot device path" @@ -1945,7 +1945,7 @@ config ESP32S3_OTA_SLOT_SIZE config ESP32S3_OTA_SCRATCH_OFFSET hex "Scratch partition offset" - default 0x210000 + default 0x220000 config ESP32S3_OTA_SCRATCH_SIZE hex "Scratch partition size" @@ -2766,7 +2766,7 @@ endchoice config ESP32S3_MCUBOOT_VERSION string "MCUboot version" - default "20f98e0a975c24864872e0df5701eb1082e9c957" + default "aa4fa2b6e17361dd3ce16a60883059778fd147a9" depends on ESP32S3_APP_FORMAT_MCUBOOT config ESP32S3_APP_MCUBOOT_HEADER_SIZE diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs index 449f0272663..ee770f4b1a7 100644 --- a/arch/xtensa/src/esp32s3/Make.defs +++ b/arch/xtensa/src/esp32s3/Make.defs @@ -274,3 +274,4 @@ distclean:: ifeq ($(CONFIG_ESPRESSIF_USE_ULP_RISCV_CORE),y) $(call DELDIR,chip/ulp) endif + $(call DELFILE,../../../vefuse.bin) diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk index d3aa9c65453..ebb8210b41d 100644 --- a/tools/esp32/Config.mk +++ b/tools/esp32/Config.mk @@ -20,6 +20,12 @@ # ############################################################################ +# MCUBoot requires a region in flash for the E-Fuse virtual mode. +# To avoid erasing this region, flash a dummy empty file to the +# virtual E-Fuse offset. + +VIRTUAL_EFUSE_BIN := vefuse.bin + # These are the macros that will be used in the NuttX make system to compile # and assemble source files and to insert the resulting object files into an # archive. These replace the default definitions at tools/Config.mk @@ -58,6 +64,12 @@ endif ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ) +define MAKE_VIRTUAL_EFUSE_BIN + $(Q)if [ ! -f "$(VIRTUAL_EFUSE_BIN)" ]; then \ + dd if=/dev/zero of=$(VIRTUAL_EFUSE_BIN) count=0 status=none; \ + fi +endef + # Configure the variables according to build environment ESPTOOL_MIN_VERSION := 4.8.0 @@ -95,6 +107,9 @@ ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y) APP_IMAGE := nuttx.bin FLASH_APP := $(APP_OFFSET) $(APP_IMAGE) else ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + + ESPTOOL_BINS += $(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET) $(VIRTUAL_EFUSE_BIN) + ifeq ($(CONFIG_ESP32_ESPTOOL_TARGET_PRIMARY),y) VERIFIED := --confirm APP_OFFSET := $(CONFIG_ESP32_OTA_PRIMARY_SLOT_OFFSET) @@ -274,6 +289,7 @@ endif define POSTBUILD $(call MKIMAGE) + $(if $(CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT),$(call MAKE_VIRTUAL_EFUSE_BIN)) $(if $(CONFIG_ESP32_MERGE_BINS),$(call MERGEBIN)) endef diff --git a/tools/esp32s2/Config.mk b/tools/esp32s2/Config.mk index b79c4d4de2e..b8402f9c8d4 100644 --- a/tools/esp32s2/Config.mk +++ b/tools/esp32s2/Config.mk @@ -20,6 +20,12 @@ # ############################################################################ +# MCUBoot requires a region in flash for the E-Fuse virtual mode. +# To avoid erasing this region, flash a dummy empty file to the +# virtual E-Fuse offset. + +VIRTUAL_EFUSE_BIN := vefuse.bin + # These are the macros that will be used in the NuttX make system to compile # and assemble source files and to insert the resulting object files into an # archive. These replace the default definitions at tools/Config.mk @@ -58,6 +64,12 @@ endif ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ) +define MAKE_VIRTUAL_EFUSE_BIN + $(Q)if [ ! -f "$(VIRTUAL_EFUSE_BIN)" ]; then \ + dd if=/dev/zero of=$(VIRTUAL_EFUSE_BIN) count=0 status=none; \ + fi +endef + # Configure the variables according to build environment ESPTOOL_MIN_VERSION := 4.8.0 @@ -83,6 +95,9 @@ ifdef ESPTOOL_BINDIR endif ifeq ($(CONFIG_ESP32S2_APP_FORMAT_MCUBOOT),y) + + ESPTOOL_BINS += $(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET) $(VIRTUAL_EFUSE_BIN) + ifeq ($(CONFIG_ESP32S2_ESPTOOL_TARGET_PRIMARY),y) VERIFIED := --confirm APP_OFFSET := $(CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET) @@ -235,6 +250,7 @@ endif define POSTBUILD $(call MKIMAGE) + $(if $(CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT),$(call MAKE_VIRTUAL_EFUSE_BIN)) $(if $(CONFIG_ESP32S2_MERGE_BINS),$(call MERGEBIN)) endef diff --git a/tools/esp32s3/Config.mk b/tools/esp32s3/Config.mk index 9d2dbf980e7..4397b545c9d 100644 --- a/tools/esp32s3/Config.mk +++ b/tools/esp32s3/Config.mk @@ -20,6 +20,12 @@ # ############################################################################ +# MCUBoot requires a region in flash for the E-Fuse virtual mode. +# To avoid erasing this region, flash a dummy empty file to the +# virtual E-Fuse offset. + +VIRTUAL_EFUSE_BIN := vefuse.bin + # These are the macros that will be used in the NuttX make system to compile # and assemble source files and to insert the resulting object files into an # archive. These replace the default definitions at tools/Config.mk @@ -56,6 +62,12 @@ endif ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ) +define MAKE_VIRTUAL_EFUSE_BIN + $(Q)if [ ! -f "$(VIRTUAL_EFUSE_BIN)" ]; then \ + dd if=/dev/zero of=$(VIRTUAL_EFUSE_BIN) count=0 status=none; \ + fi +endef + # Configure the variables according to build environment ESPTOOL_MIN_VERSION := 4.8.0 @@ -82,6 +94,9 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y) APP_IMAGE := nuttx.bin FLASH_APP := $(APP_OFFSET) $(APP_IMAGE) else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y) + + ESPTOOL_BINS += $(CONFIG_ESPRESSIF_EFUSE_VIRTUAL_KEEP_IN_FLASH_OFFSET) $(VIRTUAL_EFUSE_BIN) + ifeq ($(CONFIG_ESP32S3_ESPTOOL_TARGET_PRIMARY),y) VERIFIED := --confirm APP_OFFSET := $(CONFIG_ESP32S3_OTA_PRIMARY_SLOT_OFFSET) @@ -200,6 +215,7 @@ endif define POSTBUILD $(call MKIMAGE) + $(if $(CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT),$(call MAKE_VIRTUAL_EFUSE_BIN)) $(if $(CONFIG_ESP32S3_MERGE_BINS),$(call MERGEBIN)) endef