Skip to content

Commit 9a4bf5f

Browse files
committed
espressif: sysbuild: integrate MCUboot Espressif Port build
Enable sysbuild to build MCUboot Espressif's port as an external project. Signed-off-by: Almir Okato <[email protected]> Signed-off-by: Lucas Tamborrino <[email protected]> Signed-off-by: Marek Matej <[email protected]>
1 parent bcd6f9e commit 9a4bf5f

20 files changed

+298
-45
lines changed

scripts/ci/check_compliance.py

+10
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,17 @@ def check_no_undef_outside_kconfig(self, kconf):
10581058
"DEEP_SLEEP", # #defined by RV32M1 in ext/
10591059
"DESCRIPTION",
10601060
"ERR",
1061+
"ESP_BOOT_SWAP_USING_MOVE", # Used on MCUboot Espressif Port
1062+
"ESP_BOOT_SWAP_USING_OFFSET", # Used on MCUboot Espressif Port
1063+
"ESP_BOOT_SWAP_USING_SCRATCH", # Used on MCUboot Espressif Port
1064+
"ESP_BOOT_UPGRADE_ONLY", # Used on MCUboot Espressif Port
10611065
"ESP_DIF_LIBRARY", # Referenced in CMake comment
1066+
"ESP_SIGN_EC256", # Used on MCUboot Espressif Port
1067+
"ESP_SIGN_ED25519", # Used on MCUboot Espressif Port
1068+
"ESP_SIGN_KEY_FILE", # Used on MCUboot Espressif Port
1069+
"ESP_SIGN_NONE", # Used on MCUboot Espressif Port
1070+
"ESP_SIGN_RSA", # Used on MCUboot Espressif Port
1071+
"ESP_SINGLE_APPLICATION_SLOT", # Used on MCUboot Espressif Port
10621072
"EXPERIMENTAL",
10631073
"EXTRA_FIRMWARE_DIR", # Linux, in boards/xtensa/intel_adsp_cavs25/doc
10641074
"FFT", # Used as an example in cmake/extensions.cmake

share/sysbuild/image_configurations/MAIN_image_default.cmake

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
# This sysbuild CMake file sets the sysbuild controlled settings as properties
66
# on the main Zephyr image.
77

8-
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}")
9-
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
10-
"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}"
11-
)
12-
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE
13-
"${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}"
14-
)
15-
168
if(SB_CONFIG_BOOTLOADER_MCUBOOT)
9+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT y)
10+
11+
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
12+
"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}"
13+
)
14+
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE
15+
"${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}"
16+
)
17+
1718
if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE")
1819
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y)
1920
else()

soc/espressif/Kconfig.sysbuild

+127
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,135 @@
33

44
choice BOOTLOADER
55
default BOOTLOADER_MCUBOOT
6+
7+
# Extension for the BOOTLOADER Kconfig choice to allow
8+
# MCUboot Espressif Port to be build
9+
config BOOTLOADER_MCUBOOT_ESPRESSIF
10+
bool "MCUboot Espressif Port"
11+
depends on SOC_FAMILY_ESPRESSIF_ESP32
12+
help
13+
Use MCUboot Espressif Port as the bootloader
14+
615
endchoice
716

817
choice MCUBOOT_MODE
918
default MCUBOOT_MODE_OVERWRITE_ONLY if SOC_FAMILY_ESPRESSIF_ESP32
1019
endchoice
20+
21+
if BOOTLOADER_MCUBOOT_ESPRESSIF
22+
23+
config ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY
24+
bool "Use overwrite-only instead of swap upgrades"
25+
help
26+
If enabled, --overwrite-only option passed to imgtool to avoid
27+
adding the swap status area size when calculating overflow.
28+
29+
choice ESP_MCUBOOT_MODE
30+
prompt "Mode of operation"
31+
default ESP_MCUBOOT_MODE_SWAP_SCRATCH if BOOTLOADER_MCUBOOT_ESPRESSIF
32+
help
33+
The operating mode of MCUboot (which will also be propagated to the application).
34+
35+
config ESP_MCUBOOT_MODE_SINGLE_APP
36+
bool "Single slot"
37+
select ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY
38+
help
39+
MCUboot will only boot slot0_partition placed application and does not care about other
40+
slots. In this mode application is not able to DFU its own update to secondary slot and
41+
all updates need to be performed using MCUboot serial recovery.
42+
43+
config ESP_MCUBOOT_MODE_SWAP_USING_OFFSET
44+
bool "Swap using offset"
45+
select EXPERIMENTAL
46+
select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
47+
help
48+
MCUboot expects slot0_partition and slot1_partition to be present in DT and application
49+
will boot from slot0_partition. MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected
50+
in main application if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION.
51+
52+
config ESP_MCUBOOT_MODE_SWAP_USING_MOVE
53+
bool "Swap using move"
54+
select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
55+
help
56+
MCUboot expects slot0_partition and slot1_partition to be present in DT and application
57+
will boot from slot0_partition. MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected
58+
in main application if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION.
59+
60+
config ESP_MCUBOOT_MODE_SWAP_SCRATCH
61+
bool "Swap using scratch"
62+
select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
63+
help
64+
MCUboot expects slot0_partition, slot1_partition and scratch_partition to be present in
65+
DT, and application will boot from slot0_partition. In this mode scratch_partition is
66+
used as temporary storage when MCUboot swaps application from the secondary slot to the
67+
primary slot.
68+
MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected in main application if MCUboot
69+
has been built with MCUBOOT_DOWNGRADE_PREVENTION.
70+
71+
config ESP_MCUBOOT_MODE_OVERWRITE_ONLY
72+
bool "Overwrite"
73+
select ESP_MCUBOOT_IMGTOOL_OVERWRITE_ONLY
74+
select ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
75+
help
76+
MCUboot will take contents of secondary slot of an image and will overwrite primary slot
77+
with it. In this mode it is not possible to revert back to previous version as it is not
78+
stored in the secondary slot.
79+
This mode supports MCUBOOT_BOOTLOADER_NO_DOWNGRADE which means that the overwrite will
80+
not happen unless the version of secondary slot is higher than the version in primary
81+
slot.
82+
83+
endchoice # ESP_MCUBOOT_MODE
84+
85+
config ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
86+
bool
87+
help
88+
Selected mode supports downgrade prevention, where you cannot switch to
89+
an application with lower version than the currently running application.
90+
91+
if ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
92+
config ESP_MCUBOOT_BOOTLOADER_NO_DOWNGRADE
93+
bool "MCUboot mode has downgrade prevention enabled"
94+
help
95+
Selected MCUboot mode has downgrade prevention enabled, where you are not
96+
able to change back to image with lower version number.
97+
This options should be selected when MCUboot has been built with
98+
MCUBOOT_DOWNGRADE_PREVENTION option enabled.
99+
endif # ESP_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
100+
101+
choice ESP_BOOT_SIGNATURE_TYPE
102+
prompt "Signature type"
103+
default ESP_BOOT_SIGNATURE_TYPE_NONE
104+
105+
config ESP_BOOT_SIGNATURE_TYPE_NONE
106+
bool "No signature; use only hash check"
107+
108+
config ESP_BOOT_SIGNATURE_TYPE_RSA
109+
bool "RSA signatures"
110+
111+
if ESP_BOOT_SIGNATURE_TYPE_RSA
112+
config ESP_BOOT_SIGNATURE_RSA_LEN
113+
int "RSA signature length"
114+
range 2048 3072
115+
default 2048
116+
endif
117+
118+
config ESP_BOOT_SIGNATURE_TYPE_ECDSA_P256
119+
bool "Elliptic curve digital signatures with curve P-256"
120+
121+
config ESP_BOOT_SIGNATURE_TYPE_ED25519
122+
bool "Edwards curve digital signatures using ed25519"
123+
124+
endchoice # ESP_BOOT_SIGNATURE_TYPE
125+
126+
config ESP_BOOT_SIGNATURE_KEY_FILE
127+
string "Signing PEM key file"
128+
depends on !ESP_BOOT_SIGNATURE_TYPE_NONE
129+
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ec-p256.pem" if ESP_BOOT_SIGNATURE_TYPE_ECDSA_P256
130+
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ed25519.pem" if ESP_BOOT_SIGNATURE_TYPE_ED25519
131+
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-2048.pem" if ESP_BOOT_SIGNATURE_TYPE_RSA && ESP_BOOT_SIGNATURE_RSA_LEN=2048
132+
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-3072.pem" if ESP_BOOT_SIGNATURE_TYPE_RSA && ESP_BOOT_SIGNATURE_RSA_LEN=3072
133+
default ""
134+
help
135+
Absolute path to signing key file to use with MCUBoot.
136+
137+
endif # BOOTLOADER_MCUBOOT_ESPRESSIF

soc/espressif/common/CMakeLists.txt

+25-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
zephyr_include_directories(include)
5-
6-
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
5+
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_MCUBOOT_ESPRESSIF AND
6+
NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
77
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c)
88
endif()
99

@@ -18,13 +18,13 @@ endif()
1818

1919
message("-- Espressif HAL path: ${ESP_IDF_PATH}")
2020

21-
if((CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT) AND NOT CONFIG_SOC_ESP32C6_LPCORE)
21+
if((CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT OR CONFIG_MCUBOOT_ESPRESSIF) AND NOT CONFIG_SOC_ESP32C6_LPCORE)
2222
if(CONFIG_BUILD_OUTPUT_BIN)
2323
set(ESPTOOL_PY ${ESP_IDF_PATH}/tools/esptool_py/esptool.py)
2424
message("-- Use the esptool.py: ${ESPTOOL_PY}")
2525

2626
set(ELF2IMAGE_ARG "")
27-
if(NOT CONFIG_MCUBOOT)
27+
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_MCUBOOT_ESPRESSIF)
2828
set(ELF2IMAGE_ARG "--ram-only-header")
2929
endif()
3030

@@ -41,26 +41,36 @@ endif()
4141

4242
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
4343

44-
# Select the image origin depending on the boot configuration
4544
if(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU)
4645
dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition")
4746
elseif(CONFIG_SOC_ESP32C6_LPCORE)
4847
dt_nodelabel(dts_partition_path NODELABEL "slot0_lpcore_partition")
49-
elseif(CONFIG_MCUBOOT OR CONFIG_ESP_SIMPLE_BOOT)
50-
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
5148
else()
5249
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
5350
endif()
54-
5551
dt_reg_addr(image_off PATH ${dts_partition_path})
56-
board_runner_args(esp32 "--esp-app-address=${image_off}")
52+
53+
# Get boot partition address
54+
dt_nodelabel(dts_boot_partition_path NODELABEL "boot_partition")
55+
dt_reg_addr(boot_off PATH ${dts_boot_partition_path})
56+
57+
# Select the image origin depending on the boot configuration
58+
if(CONFIG_BOOTLOADER_MCUBOOT)
59+
board_runner_args(esp32 "--esp-app-address=${image_off}")
60+
message("-- Target partition ${dts_partition_path}")
61+
else()
62+
# In this case, it means that the current build is either
63+
# the bootloader (MCUboot, MCUboot Espressif Port) or regular
64+
# app that boots using Simple boot
65+
board_runner_args(esp32 "--esp-app-address=${boot_off}")
66+
message("-- Target partition ${dts_boot_partition_path}")
67+
endif()
68+
5769
board_runner_args(esp32 "--esp-flash-size=${esptoolpy_flashsize}MB")
5870
board_runner_args(esp32 "--esp-flash-freq=${CONFIG_ESPTOOLPY_FLASHFREQ}")
5971
board_runner_args(esp32 "--esp-flash-mode=${CONFIG_ESPTOOLPY_FLASHMODE}")
6072
board_finalize_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}")
6173

62-
message("-- Image partition ${dts_partition_path}")
63-
6474
# Look for cross references between bootloader sections
6575
if(CONFIG_MCUBOOT)
6676
message("check_callgraph using: ${ESP_IDF_PATH}/tools/ci/check_callgraph.py")
@@ -78,6 +88,10 @@ endif()
7888

7989
if(CONFIG_MCUBOOT)
8090
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../${CONFIG_SOC}/mcuboot.ld CACHE INTERNAL "")
91+
elseif(CONFIG_MCUBOOT_ESPRESSIF)
92+
# building bootloader MCUboot Espressif Port uses its linker script existing
93+
# in MCUboot repo
94+
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/empty.ld CACHE INTERNAL "")
8195
elseif(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU)
8296
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../${CONFIG_SOC}/default_appcpu.ld CACHE INTERNAL "")
8397
elseif(CONFIG_SOC_ESP32C6_LPCORE)

soc/espressif/common/Kconfig

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ config ESP32_USE_UNSUPPORTED_REVISION
1717

1818
config ESP_SIMPLE_BOOT
1919
bool "Simple Boot method"
20-
default y if !BOOTLOADER_MCUBOOT && !MCUBOOT
20+
default y if !BOOTLOADER_MCUBOOT && !MCUBOOT && !MCUBOOT_ESPRESSIF
2121
help
2222
The Simple Boot is a booting method that doesn't need a 2nd stage bootloader.
2323
Output is a single image that should be flashed at an offset defined by used SOC.
2424
Please note that this method brings the system up with all memories set-up, but
2525
all other features, such as secure boot OTA or slots management are not available.
2626

27+
# Set by MCUboot Espressif Port
28+
config MCUBOOT_ESPRESSIF
29+
bool
30+
help
31+
Hidden option used to indicate that the current image is MCUBoot
32+
Espressif Port
33+
2734
config ESP32_TIMER_TASK_STACK_SIZE
2835
int "Stack size of the high resolution ESP Timer"
2936
default 4096

soc/espressif/common/Kconfig.defconfig

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
if SOC_SERIES_ESP32C2 || SOC_SERIES_ESP32C3 || SOC_SERIES_ESP32C6
55

66
config GEN_ISR_TABLES
7-
default y if !SOC_ESP32C6_LPCORE
7+
default y if !SOC_ESP32C6_LPCORE && !MCUBOOT_ESPRESSIF
88

99
config GEN_SW_ISR_TABLE
10-
default y
10+
default y if !MCUBOOT_ESPRESSIF
1111

1212
config GEN_IRQ_VECTOR_TABLE
1313
default n
1414

1515
config DYNAMIC_INTERRUPTS
16-
default y if !SOC_ESP32C6_LPCORE
16+
default y if !SOC_ESP32C6_LPCORE && !MCUBOOT_ESPRESSIF
1717

1818
config ISR_STACK_SIZE
1919
default 2048
@@ -66,13 +66,13 @@ config XTENSA_USE_CORE_CRT1
6666
default n
6767

6868
config GEN_ISR_TABLES
69-
default y
69+
default y if !MCUBOOT_ESPRESSIF
7070

7171
config GEN_IRQ_VECTOR_TABLE
7272
default n
7373

7474
config CLOCK_CONTROL
75-
default y
75+
default y if !MCUBOOT_ESPRESSIF
7676

7777
config SOC_FLASH_ESP32
7878
default y

soc/espressif/common/empty.ld

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/* Empty linker script to allow MCUboot Espressif Port to link in its
7+
* own way when building using sysbuild.
8+
*/

soc/espressif/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
if(CONFIG_MCUBOOT_ESPRESSIF)
4+
return()
5+
endif()
6+
37
if (CONFIG_SOC_ESP32_APPCPU)
48
zephyr_sources(
59
soc_appcpu.c

soc/espressif/esp32/Kconfig

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
config SOC_SERIES_ESP32
55
select XTENSA
6-
select CLOCK_CONTROL
7-
select DYNAMIC_INTERRUPTS
6+
select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF
7+
select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF
88
select ARCH_HAS_GDBSTUB
99
select ARCH_SUPPORTS_COREDUMP
10-
select PINCTRL
10+
select PINCTRL if !MCUBOOT_ESPRESSIF
1111
select HAS_ESPRESSIF_HAL
12-
select CPU_HAS_FPU
12+
select CPU_HAS_FPU if !MCUBOOT_ESPRESSIF
1313
select HAS_PM
1414
select HAS_POWEROFF
1515

soc/espressif/esp32c2/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
if(CONFIG_MCUBOOT_ESPRESSIF)
4+
return()
5+
endif()
6+
37
zephyr_sources(
48
vectors.S
59
soc_irq.S

soc/espressif/esp32c2/Kconfig

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
config SOC_SERIES_ESP32C2
55
select RISCV
66
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
7-
select DYNAMIC_INTERRUPTS
8-
select CLOCK_CONTROL
9-
select PINCTRL
7+
select DYNAMIC_INTERRUPTS if !MCUBOOT_ESPRESSIF
8+
select CLOCK_CONTROL if !MCUBOOT_ESPRESSIF
9+
select PINCTRL if !MCUBOOT_ESPRESSIF
1010
select RISCV_ISA_RV32I
1111
select RISCV_ISA_EXT_M
1212
select RISCV_ISA_EXT_C

soc/espressif/esp32c3/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
if(CONFIG_MCUBOOT_ESPRESSIF)
4+
return()
5+
endif()
6+
37
zephyr_sources(
48
vectors.S
59
soc_irq.S

0 commit comments

Comments
 (0)