diff --git a/boards/espressif/esp32_devkitc/Kconfig.sysbuild b/boards/espressif/esp32_devkitc/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32_devkitc/Kconfig.sysbuild +++ b/boards/espressif/esp32_devkitc/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32_ethernet_kit/Kconfig.sysbuild b/boards/espressif/esp32_ethernet_kit/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32_ethernet_kit/Kconfig.sysbuild +++ b/boards/espressif/esp32_ethernet_kit/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32c3_devkitc/Kconfig.sysbuild b/boards/espressif/esp32c3_devkitc/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp32c3_devkitc/Kconfig.sysbuild +++ b/boards/espressif/esp32c3_devkitc/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32c3_devkitm/Kconfig.sysbuild b/boards/espressif/esp32c3_devkitm/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32c3_devkitm/Kconfig.sysbuild +++ b/boards/espressif/esp32c3_devkitm/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32c3_rust/Kconfig.sysbuild b/boards/espressif/esp32c3_rust/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp32c3_rust/Kconfig.sysbuild +++ b/boards/espressif/esp32c3_rust/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32c6_devkitc/Kconfig.sysbuild b/boards/espressif/esp32c6_devkitc/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32c6_devkitc/Kconfig.sysbuild +++ b/boards/espressif/esp32c6_devkitc/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32s2_devkitc/Kconfig.sysbuild b/boards/espressif/esp32s2_devkitc/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp32s2_devkitc/Kconfig.sysbuild +++ b/boards/espressif/esp32s2_devkitc/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32s2_saola/Kconfig.sysbuild b/boards/espressif/esp32s2_saola/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32s2_saola/Kconfig.sysbuild +++ b/boards/espressif/esp32s2_saola/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32s3_devkitc/Kconfig.sysbuild b/boards/espressif/esp32s3_devkitc/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp32s3_devkitc/Kconfig.sysbuild +++ b/boards/espressif/esp32s3_devkitc/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32s3_devkitm/Kconfig.sysbuild b/boards/espressif/esp32s3_devkitm/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp32s3_devkitm/Kconfig.sysbuild +++ b/boards/espressif/esp32s3_devkitm/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp32s3_eye/Kconfig.sysbuild b/boards/espressif/esp32s3_eye/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp32s3_eye/Kconfig.sysbuild +++ b/boards/espressif/esp32s3_eye/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp8684_devkitm/Kconfig.sysbuild b/boards/espressif/esp8684_devkitm/Kconfig.sysbuild index 8d3acb9e11d7c..d4947888c5524 100644 --- a/boards/espressif/esp8684_devkitm/Kconfig.sysbuild +++ b/boards/espressif/esp8684_devkitm/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/boards/espressif/esp_wrover_kit/Kconfig.sysbuild b/boards/espressif/esp_wrover_kit/Kconfig.sysbuild index 3a2d17ac5cfd0..7e11da11d95b6 100644 --- a/boards/espressif/esp_wrover_kit/Kconfig.sysbuild +++ b/boards/espressif/esp_wrover_kit/Kconfig.sysbuild @@ -1,10 +1,6 @@ # Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 -choice BOOTLOADER - default BOOTLOADER_MCUBOOT -endchoice - choice BOOT_SIGNATURE_TYPE default BOOT_SIGNATURE_TYPE_NONE endchoice diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 0c84479373725..af7556f2b1533 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -1059,7 +1059,18 @@ def check_no_undef_outside_kconfig(self, kconf): "DEEP_SLEEP", # #defined by RV32M1 in ext/ "DESCRIPTION", "ERR", + "ESP_BOOT_SWAP_USING_MOVE", # Used on MCUboot Espressif Port + "ESP_BOOT_SWAP_USING_OFFSET", # Used on MCUboot Espressif Port + "ESP_BOOT_SWAP_USING_SCRATCH", # Used on MCUboot Espressif Port + "ESP_BOOT_UPGRADE_ONLY", # Used on MCUboot Espressif Port "ESP_DIF_LIBRARY", # Referenced in CMake comment + "ESP_DOWNGRADE_PREVENTION", # Used on MCUboot Espressif Port + "ESP_SIGN_EC256", # Used on MCUboot Espressif Port + "ESP_SIGN_ED25519", # Used on MCUboot Espressif Port + "ESP_SIGN_KEY_FILE", # Used on MCUboot Espressif Port + "ESP_SIGN_NONE", # Used on MCUboot Espressif Port + "ESP_SIGN_RSA", # Used on MCUboot Espressif Port + "ESP_SINGLE_APPLICATION_SLOT", # Used on MCUboot Espressif Port "EXPERIMENTAL", "EXTRA_FIRMWARE_DIR", # Linux, in boards/xtensa/intel_adsp_cavs25/doc "FFT", # Used as an example in cmake/extensions.cmake diff --git a/share/sysbuild/image_configurations/MAIN_image_default.cmake b/share/sysbuild/image_configurations/MAIN_image_default.cmake index a6c29c8d75692..81889925b19d9 100644 --- a/share/sysbuild/image_configurations/MAIN_image_default.cmake +++ b/share/sysbuild/image_configurations/MAIN_image_default.cmake @@ -6,14 +6,15 @@ # on the main Zephyr image. set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}") -set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE - "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" -) -set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE - "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}" -) if(SB_CONFIG_BOOTLOADER_MCUBOOT) + set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE + "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" + ) + set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE + "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}" + ) + if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y) else() diff --git a/soc/espressif/Kconfig.sysbuild b/soc/espressif/Kconfig.sysbuild index e47a729549993..06870ca6b8b06 100644 --- a/soc/espressif/Kconfig.sysbuild +++ b/soc/espressif/Kconfig.sysbuild @@ -1,6 +1,141 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +choice BOOTLOADER + default BOOTLOADER_MCUBOOT + +# Extension for the BOOTLOADER Kconfig choice to allow +# MCUboot Espressif Port to be built +config BOOTLOADER_MCUBOOT_ESPRESSIF + bool "MCUboot Espressif Port" + depends on SOC_FAMILY_ESPRESSIF_ESP32 + help + Use MCUboot Espressif Port as the bootloader + +endchoice + choice MCUBOOT_MODE default MCUBOOT_MODE_OVERWRITE_ONLY if SOC_FAMILY_ESPRESSIF_ESP32 endchoice + +if BOOTLOADER_MCUBOOT_ESPRESSIF + +config ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY + bool + help + If enabled, --overwrite-only option is passed to imgtool to avoid + adding the swap status area size when calculating overflow. + +choice ESP_MCUBOOT_MODE + prompt "Mode of operation" + default ESP_MCUBOOT_MODE_SWAP_SCRATCH + help + The operating mode of MCUboot (which will also be propagated to the application). + +config ESP_MCUBOOT_MODE_SINGLE_APP + bool "Single slot" + select ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY + help + MCUboot will only boot slot0_partition placed application and does not care about other + slots. In this mode application is not able to DFU its own update to secondary slot and + all updates need to be performed using MCUboot serial recovery. + +config ESP_MCUBOOT_MODE_SWAP_USING_OFFSET + bool "Swap using offset" + select EXPERIMENTAL + select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + help + MCUboot expects slot0_partition and slot1_partition to be present in DT and application + will boot from slot0_partition. MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected + in main application if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. + +config ESP_MCUBOOT_MODE_SWAP_USING_MOVE + bool "Swap using move" + select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + help + MCUboot expects slot0_partition and slot1_partition to be present in DT and application + will boot from slot0_partition. MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected + in main application if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. + +config ESP_MCUBOOT_MODE_SWAP_SCRATCH + bool "Swap using scratch" + select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + help + MCUboot expects slot0_partition, slot1_partition and scratch_partition to be present in + DT, and application will boot from slot0_partition. In this mode scratch_partition is + used as temporary storage when MCUboot swaps application from the secondary slot to the + primary slot. + MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected in main application if MCUboot + has been built with MCUBOOT_DOWNGRADE_PREVENTION. + +config ESP_MCUBOOT_MODE_OVERWRITE_ONLY + bool "Overwrite" + select ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY + select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + help + MCUboot will take the content of secondary slot of an image and will overwrite primary + slot with it. In this mode it is not possible to revert back to previous version as it + is not stored in the secondary slot. + This mode supports MCUBOOT_BOOTLOADER_NO_DOWNGRADE which means that the overwrite will + not happen unless the version of secondary slot is higher than the version in primary + slot. + +endchoice # ESP_MCUBOOT_MODE + +config ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + bool + help + Selected mode supports downgrade prevention, where you cannot switch to + an application with lower version than the currently running application. + +if ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + +config ESP_MCUBOOT_BOOTLOADER_NO_DOWNGRADE + bool "MCUboot downgrade prevention" + help + Selected MCUboot mode has downgrade prevention, where it's not + possible to revert back to image with lower version number. + This options should be selected when MCUboot has been built with + MCUBOOT_DOWNGRADE_PREVENTION option enabled. + +endif # ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + +choice ESP_BOOT_SIGNATURE_TYPE + prompt "Signature type" + default ESP_BOOT_SIGNATURE_TYPE_NONE + +config ESP_BOOT_SIGNATURE_TYPE_NONE + bool "No signature; use only hash check" + +config ESP_BOOT_SIGNATURE_TYPE_RSA + bool "RSA signatures" + +if ESP_BOOT_SIGNATURE_TYPE_RSA + +config ESP_BOOT_SIGNATURE_RSA_LEN + int "RSA signature length" + range 2048 3072 + default 2048 + +endif + +config ESP_BOOT_SIGNATURE_TYPE_ECDSA_P256 + bool "Elliptic curve digital signatures with curve P-256" + +config ESP_BOOT_SIGNATURE_TYPE_ED25519 + bool "Edwards curve digital signatures using ed25519" + +endchoice # ESP_BOOT_SIGNATURE_TYPE + +config ESP_BOOT_SIGNATURE_KEY_FILE + string "Signing PEM key file" + depends on !ESP_BOOT_SIGNATURE_TYPE_NONE + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ec-p256.pem" if ESP_BOOT_SIGNATURE_TYPE_ECDSA_P256 + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ed25519.pem" if ESP_BOOT_SIGNATURE_TYPE_ED25519 + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-2048.pem" if ESP_BOOT_SIGNATURE_TYPE_RSA && ESP_BOOT_SIGNATURE_RSA_LEN=2048 + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-3072.pem" if ESP_BOOT_SIGNATURE_TYPE_RSA && ESP_BOOT_SIGNATURE_RSA_LEN=3072 + default "" + help + Absolute path to signing key file to use with MCUBoot. + +endif # BOOTLOADER_MCUBOOT_ESPRESSIF diff --git a/soc/espressif/common/CMakeLists.txt b/soc/espressif/common/CMakeLists.txt index ab9558b9d1807..e249ac46cce7f 100644 --- a/soc/espressif/common/CMakeLists.txt +++ b/soc/espressif/common/CMakeLists.txt @@ -2,8 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_include_directories(include) - -if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU) +if(NOT CONFIG_MCUBOOT AND NOT CONFIG_MCUBOOT_ESPRESSIF AND + NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU) zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c) endif() @@ -18,13 +18,13 @@ endif() message("-- Espressif HAL path: ${ESP_IDF_PATH}") -if((CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT) AND NOT CONFIG_SOC_ESP32C6_LPCORE) +if((CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT OR CONFIG_MCUBOOT_ESPRESSIF) AND NOT CONFIG_SOC_ESP32C6_LPCORE) if(CONFIG_BUILD_OUTPUT_BIN) set(ESPTOOL_PY ${ESP_IDF_PATH}/tools/esptool_py/esptool.py) message("-- Use the esptool.py: ${ESPTOOL_PY}") set(ELF2IMAGE_ARG "") - if(NOT CONFIG_MCUBOOT) + if(NOT CONFIG_MCUBOOT AND NOT CONFIG_MCUBOOT_ESPRESSIF) set(ELF2IMAGE_ARG "--ram-only-header") endif() @@ -41,26 +41,36 @@ endif() set_property(TARGET bintools PROPERTY disassembly_flag_inline_source) -# Select the image origin depending on the boot configuration if(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU) dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition") elseif(CONFIG_SOC_ESP32C6_LPCORE) dt_nodelabel(dts_partition_path NODELABEL "slot0_lpcore_partition") -elseif(CONFIG_MCUBOOT OR CONFIG_ESP_SIMPLE_BOOT) - dt_nodelabel(dts_partition_path NODELABEL "boot_partition") else() dt_nodelabel(dts_partition_path NODELABEL "slot0_partition") endif() - dt_reg_addr(image_off PATH ${dts_partition_path}) -board_runner_args(esp32 "--esp-app-address=${image_off}") + +# Get boot partition address +dt_nodelabel(dts_boot_partition_path NODELABEL "boot_partition") +dt_reg_addr(boot_off PATH ${dts_boot_partition_path}) + +# Select the image origin depending on the boot configuration +if(CONFIG_BOOTLOADER_MCUBOOT) + board_runner_args(esp32 "--esp-app-address=${image_off}") + message("-- Target partition ${dts_partition_path}") +else() + # In this case, it means that the current build is either + # the bootloader (MCUboot, MCUboot Espressif Port) or regular + # app that boots using Simple boot + board_runner_args(esp32 "--esp-app-address=${boot_off}") + message("-- Target partition ${dts_boot_partition_path}") +endif() + board_runner_args(esp32 "--esp-flash-size=${esptoolpy_flashsize}MB") board_runner_args(esp32 "--esp-flash-freq=${CONFIG_ESPTOOLPY_FLASHFREQ}") board_runner_args(esp32 "--esp-flash-mode=${CONFIG_ESPTOOLPY_FLASHMODE}") board_finalize_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}") -message("-- Image partition ${dts_partition_path}") - # Look for cross references between bootloader sections if(CONFIG_MCUBOOT) message("check_callgraph using: ${ESP_IDF_PATH}/tools/ci/check_callgraph.py") @@ -78,6 +88,10 @@ endif() if(CONFIG_MCUBOOT) set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../${CONFIG_SOC}/mcuboot.ld CACHE INTERNAL "") +elseif(CONFIG_MCUBOOT_ESPRESSIF) + # building bootloader MCUboot Espressif Port uses its linker script existing + # in MCUboot repo + set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/empty.ld CACHE INTERNAL "") elseif(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU) set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../${CONFIG_SOC}/default_appcpu.ld CACHE INTERNAL "") elseif(CONFIG_SOC_ESP32C6_LPCORE) diff --git a/soc/espressif/common/Kconfig b/soc/espressif/common/Kconfig index 555085435c3e2..71178d46fe6b6 100644 --- a/soc/espressif/common/Kconfig +++ b/soc/espressif/common/Kconfig @@ -17,13 +17,20 @@ config ESP32_USE_UNSUPPORTED_REVISION config ESP_SIMPLE_BOOT bool "Simple Boot method" - default y if !BOOTLOADER_MCUBOOT && !MCUBOOT + default y if !BOOTLOADER_MCUBOOT && !MCUBOOT && !MCUBOOT_ESPRESSIF help The Simple Boot is a booting method that doesn't need a 2nd stage bootloader. Output is a single image that should be flashed at an offset defined by used SOC. Please note that this method brings the system up with all memories set-up, but all other features, such as secure boot OTA or slots management are not available. +# Set by MCUboot Espressif Port +config MCUBOOT_ESPRESSIF + bool + help + Hidden option used to indicate that the current image is MCUBoot + Espressif Port + config ESP32_TIMER_TASK_STACK_SIZE int "Stack size of the high resolution ESP Timer" default 4096 diff --git a/soc/espressif/common/Kconfig.defconfig b/soc/espressif/common/Kconfig.defconfig index bcc34a1a52ca4..7fed9b121e482 100644 --- a/soc/espressif/common/Kconfig.defconfig +++ b/soc/espressif/common/Kconfig.defconfig @@ -4,16 +4,16 @@ if SOC_SERIES_ESP32C2 || SOC_SERIES_ESP32C3 || SOC_SERIES_ESP32C6 config GEN_ISR_TABLES - default y if !SOC_ESP32C6_LPCORE + default y if !SOC_ESP32C6_LPCORE && !MCUBOOT_ESPRESSIF config GEN_SW_ISR_TABLE - default y + default y if !MCUBOOT_ESPRESSIF config GEN_IRQ_VECTOR_TABLE default n config DYNAMIC_INTERRUPTS - default y if !SOC_ESP32C6_LPCORE + default y if !SOC_ESP32C6_LPCORE && !MCUBOOT_ESPRESSIF config ISR_STACK_SIZE default 2048 @@ -66,13 +66,13 @@ config XTENSA_USE_CORE_CRT1 default n config GEN_ISR_TABLES - default y + default y if !MCUBOOT_ESPRESSIF config GEN_IRQ_VECTOR_TABLE default n config CLOCK_CONTROL - default y + default y if !MCUBOOT_ESPRESSIF config SOC_FLASH_ESP32 default y diff --git a/soc/espressif/common/empty.ld b/soc/espressif/common/empty.ld new file mode 100644 index 0000000000000..966128f536ad6 --- /dev/null +++ b/soc/espressif/common/empty.ld @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Empty linker script to allow MCUboot Espressif Port to link in its + * own way when building using sysbuild. + */ diff --git a/soc/espressif/esp32/CMakeLists.txt b/soc/espressif/esp32/CMakeLists.txt index 36484e5875ecf..96b2529670c6e 100644 --- a/soc/espressif/esp32/CMakeLists.txt +++ b/soc/espressif/esp32/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + if (CONFIG_SOC_ESP32_APPCPU) zephyr_sources( soc_appcpu.c diff --git a/soc/espressif/esp32/Kconfig b/soc/espressif/esp32/Kconfig index 3457b3818cbf3..d3b3b5a9bead4 100644 --- a/soc/espressif/esp32/Kconfig +++ b/soc/espressif/esp32/Kconfig @@ -3,13 +3,13 @@ config SOC_SERIES_ESP32 select XTENSA - select CLOCK_CONTROL - select DYNAMIC_INTERRUPTS + select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF + select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF select ARCH_HAS_GDBSTUB select ARCH_SUPPORTS_COREDUMP - select PINCTRL + select PINCTRL if !MCUBOOT_ESPRESSIF select HAS_ESPRESSIF_HAL - select CPU_HAS_FPU + select CPU_HAS_FPU if !MCUBOOT_ESPRESSIF select HAS_PM select HAS_POWEROFF diff --git a/soc/espressif/esp32c2/CMakeLists.txt b/soc/espressif/esp32c2/CMakeLists.txt index 0248ccef51e47..4a578d47cf82b 100644 --- a/soc/espressif/esp32c2/CMakeLists.txt +++ b/soc/espressif/esp32c2/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + zephyr_sources( vectors.S soc_irq.S diff --git a/soc/espressif/esp32c2/Kconfig b/soc/espressif/esp32c2/Kconfig index 1e7f41e8b7455..7c07e0095a740 100644 --- a/soc/espressif/esp32c2/Kconfig +++ b/soc/espressif/esp32c2/Kconfig @@ -4,9 +4,9 @@ config SOC_SERIES_ESP32C2 select RISCV select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING - select DYNAMIC_INTERRUPTS - select CLOCK_CONTROL - select PINCTRL + select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF + select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF + select PINCTRL if !MCUBOOT_ESPRESSIF select RISCV_ISA_RV32I select RISCV_ISA_EXT_M select RISCV_ISA_EXT_C diff --git a/soc/espressif/esp32c3/CMakeLists.txt b/soc/espressif/esp32c3/CMakeLists.txt index 980863025ef72..ffe4469106953 100644 --- a/soc/espressif/esp32c3/CMakeLists.txt +++ b/soc/espressif/esp32c3/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + zephyr_sources( vectors.S soc_irq.S diff --git a/soc/espressif/esp32c3/Kconfig b/soc/espressif/esp32c3/Kconfig index 3e5455ddeb714..86d01cf565b1f 100644 --- a/soc/espressif/esp32c3/Kconfig +++ b/soc/espressif/esp32c3/Kconfig @@ -4,9 +4,9 @@ config SOC_SERIES_ESP32C3 select RISCV select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING - select DYNAMIC_INTERRUPTS - select CLOCK_CONTROL - select PINCTRL + select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF + select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF + select PINCTRL if !MCUBOOT_ESPRESSIF select RISCV_ISA_RV32I select RISCV_ISA_EXT_M select RISCV_ISA_EXT_C diff --git a/soc/espressif/esp32c6/CMakeLists.txt b/soc/espressif/esp32c6/CMakeLists.txt index 9101292b406a3..3be6ad5b366c2 100644 --- a/soc/espressif/esp32c6/CMakeLists.txt +++ b/soc/espressif/esp32c6/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + zephyr_sources_ifdef(CONFIG_SOC_ESP32C6_HPCORE vectors.S soc_irq.S diff --git a/soc/espressif/esp32c6/Kconfig b/soc/espressif/esp32c6/Kconfig index 706bbc86ac9c4..be545adebd512 100644 --- a/soc/espressif/esp32c6/Kconfig +++ b/soc/espressif/esp32c6/Kconfig @@ -4,9 +4,9 @@ config SOC_SERIES_ESP32C6 select RISCV select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING - select DYNAMIC_INTERRUPTS if SOC_ESP32C6_HPCORE - select CLOCK_CONTROL if SOC_ESP32C6_HPCORE - select PINCTRL if SOC_ESP32C6_HPCORE + select DYNAMIC_INTERRUPTS if SOC_ESP32C6_HPCORE && !MCUBOOT_ESPRESSIF + select CLOCK_CONTROL if SOC_ESP32C6_HPCORE && !MCUBOOT_ESPRESSIF + select PINCTRL if SOC_ESP32C6_HPCORE && !MCUBOOT_ESPRESSIF select RISCV_ISA_RV32I select RISCV_ISA_EXT_A select RISCV_ISA_EXT_M diff --git a/soc/espressif/esp32s2/CMakeLists.txt b/soc/espressif/esp32s2/CMakeLists.txt index 6cae59aed5b65..d9aea752b4681 100644 --- a/soc/espressif/esp32s2/CMakeLists.txt +++ b/soc/espressif/esp32s2/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + zephyr_sources( soc.c soc_cache.c diff --git a/soc/espressif/esp32s2/Kconfig b/soc/espressif/esp32s2/Kconfig index 73ebc87802926..da05b8b140b3b 100644 --- a/soc/espressif/esp32s2/Kconfig +++ b/soc/espressif/esp32s2/Kconfig @@ -4,9 +4,9 @@ config SOC_SERIES_ESP32S2 select XTENSA select ATOMIC_OPERATIONS_C - select DYNAMIC_INTERRUPTS - select CLOCK_CONTROL - select PINCTRL + select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF + select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF + select PINCTRL if !MCUBOOT_ESPRESSIF select HAS_ESPRESSIF_HAL select ARCH_SUPPORTS_COREDUMP select HAS_PM diff --git a/soc/espressif/esp32s3/CMakeLists.txt b/soc/espressif/esp32s3/CMakeLists.txt index 48c6936487bac..3acc2f2545e44 100644 --- a/soc/espressif/esp32s3/CMakeLists.txt +++ b/soc/espressif/esp32s3/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_MCUBOOT_ESPRESSIF) + return() +endif() + if (CONFIG_SOC_ESP32S3_APPCPU) zephyr_sources( diff --git a/soc/espressif/esp32s3/Kconfig b/soc/espressif/esp32s3/Kconfig index 99ebadeb44056..c9648a0e1a17e 100644 --- a/soc/espressif/esp32s3/Kconfig +++ b/soc/espressif/esp32s3/Kconfig @@ -3,12 +3,12 @@ config SOC_SERIES_ESP32S3 select XTENSA - select DYNAMIC_INTERRUPTS + select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF select ARCH_SUPPORTS_COREDUMP - select CLOCK_CONTROL - select PINCTRL + select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF + select PINCTRL if !MCUBOOT_ESPRESSIF select HAS_ESPRESSIF_HAL - select CPU_HAS_FPU + select CPU_HAS_FPU if !MCUBOOT_ESPRESSIF select HAS_PM select HAS_POWEROFF diff --git a/soc/espressif/sysbuild.cmake b/soc/espressif/sysbuild.cmake new file mode 100644 index 0000000000000..e994987ebbe9f --- /dev/null +++ b/soc/espressif/sysbuild.cmake @@ -0,0 +1,63 @@ +# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. +# SPDX-License-Identifier: Apache-2.0 + +if(SB_CONFIG_BOOTLOADER_MCUBOOT_ESPRESSIF) + set(MCUBOOT_EP_IMAGE mcuboot_espressif_port) + + ExternalZephyrProject_Add( + APPLICATION ${MCUBOOT_EP_IMAGE} + SOURCE_DIR ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/espressif/zephyr/ + ) + + set_config_bool(${DEFAULT_IMAGE} CONFIG_BOOTLOADER_MCUBOOT y) + + # Below, the MCUboot configurations for both bootloader and application images are set + + if(SB_CONFIG_ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_IMGTOOL_OVERWRITE_ONLY y) + endif() + + if(SB_CONFIG_ESP_MCUBOOT_BOOTLOADER_NO_DOWNGRADE) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_DOWNGRADE_PREVENTION y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE y) + endif() + + if(SB_CONFIG_ESP_MCUBOOT_MODE_SINGLE_APP) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SINGLE_APPLICATION_SLOT y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP y) + elseif(SB_CONFIG_ESP_MCUBOOT_MODE_SWAP_USING_OFFSET) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_BOOT_SWAP_USING_OFFSET y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_USING_OFFSET y) + elseif(SB_CONFIG_ESP_MCUBOOT_MODE_SWAP_USING_MOVE) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_BOOT_SWAP_USING_MOVE y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_USING_MOVE y) + elseif(SB_CONFIG_ESP_MCUBOOT_MODE_SWAP_SCRATCH) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_BOOT_SWAP_USING_SCRATCH y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH y) + elseif(SB_CONFIG_ESP_MCUBOOT_MODE_OVERWRITE_ONLY) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_BOOT_UPGRADE_ONLY y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY y) + endif() + + if(SB_CONFIG_ESP_BOOT_SIGNATURE_TYPE_NONE) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SIGN_NONE y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y) + else() + set_config_string(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SIGN_KEY_FILE "${SB_CONFIG_ESP_BOOT_SIGNATURE_KEY_FILE}") + set_config_string(${DEFAULT_IMAGE} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_ESP_BOOT_SIGNATURE_KEY_FILE}") + + if(SB_CONFIG_ESP_BOOT_SIGNATURE_TYPE_RSA) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SIGN_RSA y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n) + elseif(SB_CONFIG_ESP_BOOT_SIGNATURE_TYPE_ECDSA_P256) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SIGN_EC256 y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n) + elseif(SB_CONFIG_ESP_BOOT_SIGNATURE_TYPE_ED25519) + set_config_bool(${MCUBOOT_EP_IMAGE} CONFIG_ESP_SIGN_ED25519 y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n) + endif() + endif() + + sysbuild_add_dependencies(CONFIGURE ${DEFAULT_IMAGE} ${MCUBOOT_EP_IMAGE}) + sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${MCUBOOT_EP_IMAGE}) +endif() diff --git a/west.yml b/west.yml index f011720519be6..6761e556576ff 100644 --- a/west.yml +++ b/west.yml @@ -167,7 +167,7 @@ manifest: groups: - hal - name: hal_espressif - revision: e794f935ff732f4e03f2e007d1e342f881ef0d4a + revision: 023b034e805b5ef213b20bc36f7cb2709f2912fd path: modules/hal/espressif west-commands: west/west-commands.yml groups: