Skip to content

Commit b435f73

Browse files
LucasTamboralmir-okato
authored andcommitted
boot: espressif: integrate Espressif Port with Zephyr sysbuild system
Enable building MCUboot Espressif Port through Zephyr's sysbuild for Espressif chips. Signed-off-by: Lucas Tamborrino <[email protected]> Signed-off-by: Almir Okato <[email protected]>
1 parent cb55846 commit b435f73

File tree

12 files changed

+783
-53
lines changed

12 files changed

+783
-53
lines changed

boot/espressif/CMakeLists.txt

+76-52
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,83 @@ cmake_policy(SET CMP0109 NEW)
77

88
include(${CMAKE_CURRENT_LIST_DIR}/tools/utils.cmake)
99

10-
set(MCUBOOT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
11-
set(ESPRESSIF_PORT_DIR ${MCUBOOT_ROOT_DIR}/boot/espressif)
10+
# SYSBUILD variable indicates that the build was triggered by Zephyr sysbuild
11+
if(SYSBUILD)
12+
message(STATUS "Building MCUboot for Zephyr OS -- ESPRESSIF PORT")
1213

13-
set(APP_NAME mcuboot_${MCUBOOT_TARGET})
14-
set(APP_EXECUTABLE ${APP_NAME}.elf)
15-
set(EXPECTED_IDF_HAL_VERSION "5.1.4")
14+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1615

17-
project(mcuboot_${MCUBOOT_TARGET})
16+
# Set Zephyr referenced variables
17+
set(MCUBOOT_ROOT_DIR ${ZEPHYR_MCUBOOT_MODULE_DIR})
18+
set(ESPRESSIF_PORT_DIR ${MCUBOOT_ROOT_DIR}/boot/espressif)
19+
set(MCUBOOT_TARGET ${CONFIG_SOC})
20+
set(ESP_HAL_PATH ${ZEPHYR_HAL_ESPRESSIF_MODULE_DIR})
21+
set(APP_EXECUTABLE ${ZEPHYR_CURRENT_LIBRARY})
22+
set(EXPECTED_IDF_HAL_VERSION "5.1.5")
1823

19-
add_executable(
20-
${APP_EXECUTABLE}
21-
${ESPRESSIF_PORT_DIR}/main.c
22-
)
24+
project(NONE)
25+
else()
26+
set(MCUBOOT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
27+
set(ESPRESSIF_PORT_DIR ${MCUBOOT_ROOT_DIR}/boot/espressif)
2328

24-
# Set MCUboot Espressif Port configuration file
25-
if(NOT DEFINED MCUBOOT_CONFIG_FILE)
26-
set(MCUBOOT_CONFIG_FILE "${ESPRESSIF_PORT_DIR}/port/${MCUBOOT_TARGET}/bootloader.conf")
27-
message("MCUBOOT_CONFIG_FILE: ${MCUBOOT_CONFIG_FILE}")
28-
endif()
29+
set(APP_NAME mcuboot_${MCUBOOT_TARGET})
30+
set(APP_EXECUTABLE ${APP_NAME}.elf)
31+
set(EXPECTED_IDF_HAL_VERSION "5.1.4")
2932

30-
string(REPLACE " " ";" MCUBOOT_CONFIG_FILE_LIST "${MCUBOOT_CONFIG_FILE}")
31-
foreach(CONFIG_FILE ${MCUBOOT_CONFIG_FILE_LIST})
32-
if(NOT EXISTS "${CONFIG_FILE}")
33-
message(FATAL_ERROR "MCUboot configuration file does not exist at ${CONFIG_FILE}")
34-
endif()
35-
parse_and_set_config_file(${CONFIG_FILE})
36-
endforeach()
33+
project(mcuboot_${MCUBOOT_TARGET})
3734

38-
# Fetch and set toolchain
39-
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
40-
if(DEFINED TOOLCHAIN_BIN_DIR)
41-
message("CMAKE_TOOLCHAIN_FILE not defined, searching for toolchain compiler in TOOLCHAIN_BIN_DIR: ${TOOLCHAIN_BIN_DIR}")
42-
set(CMAKE_SYSTEM_NAME Generic)
35+
add_executable(
36+
${APP_EXECUTABLE}
37+
${ESPRESSIF_PORT_DIR}/main.c
38+
)
4339

44-
file(GLOB C_COMPILER_BIN "${TOOLCHAIN_BIN_DIR}/*${MCUBOOT_ARCH}*elf-gcc")
45-
if(NOT C_COMPILER_BIN)
46-
message(FATAL_ERROR "No C compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C compiling tools compatible with the target")
47-
endif()
48-
set(CMAKE_C_COMPILER ${C_COMPILER_BIN})
49-
set(CMAKE_ASM_COMPILER ${C_COMPILER_BIN})
50-
message("C compiler found: ${CMAKE_C_COMPILER}")
40+
# Set MCUboot Espressif Port configuration file
41+
if(NOT DEFINED MCUBOOT_CONFIG_FILE)
42+
set(MCUBOOT_CONFIG_FILE "${ESPRESSIF_PORT_DIR}/port/${MCUBOOT_TARGET}/bootloader.conf")
43+
message("MCUBOOT_CONFIG_FILE: ${MCUBOOT_CONFIG_FILE}")
44+
endif()
5145

52-
file(GLOB CXX_COMPILER_BIN "${TOOLCHAIN_BIN_DIR}/*${MCUBOOT_ARCH}*elf-g++")
53-
if(NOT CXX_COMPILER_BIN)
54-
message(FATAL_ERROR "No C++ compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C++ compiling tools compatible with the target")
46+
string(REPLACE " " ";" MCUBOOT_CONFIG_FILE_LIST "${MCUBOOT_CONFIG_FILE}")
47+
foreach(CONFIG_FILE ${MCUBOOT_CONFIG_FILE_LIST})
48+
if(NOT EXISTS "${CONFIG_FILE}")
49+
message(FATAL_ERROR "MCUboot configuration file does not exist at ${CONFIG_FILE}")
5550
endif()
56-
set(CMAKE_CXX_COMPILER ${CXX_COMPILER_BIN})
57-
message("CXX compiler found: ${CMAKE_CXX_COMPILER}")
51+
parse_and_set_config_file(${CONFIG_FILE})
52+
endforeach()
53+
54+
# Fetch and set toolchain
55+
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
56+
if(DEFINED TOOLCHAIN_BIN_DIR)
57+
message("CMAKE_TOOLCHAIN_FILE not defined, searching for toolchain compiler in TOOLCHAIN_BIN_DIR: ${TOOLCHAIN_BIN_DIR}")
58+
set(CMAKE_SYSTEM_NAME Generic)
59+
60+
file(GLOB C_COMPILER_BIN "${TOOLCHAIN_BIN_DIR}/*${MCUBOOT_ARCH}*elf-gcc")
61+
if(NOT C_COMPILER_BIN)
62+
message(FATAL_ERROR "No C compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C compiling tools compatible with the target")
63+
endif()
64+
set(CMAKE_C_COMPILER ${C_COMPILER_BIN})
65+
set(CMAKE_ASM_COMPILER ${C_COMPILER_BIN})
66+
message("C compiler found: ${CMAKE_C_COMPILER}")
67+
68+
file(GLOB CXX_COMPILER_BIN "${TOOLCHAIN_BIN_DIR}/*${MCUBOOT_ARCH}*elf-g++")
69+
if(NOT CXX_COMPILER_BIN)
70+
message(FATAL_ERROR "No C++ compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C++ compiling tools compatible with the target")
71+
endif()
72+
set(CMAKE_CXX_COMPILER ${CXX_COMPILER_BIN})
73+
message("CXX compiler found: ${CMAKE_CXX_COMPILER}")
74+
else()
75+
# Set toolchain file that expect the same toolchain as IDF sets on PATH
76+
set(CMAKE_TOOLCHAIN_FILE ${ESPRESSIF_PORT_DIR}/tools/toolchain-${MCUBOOT_TARGET}.cmake)
77+
message("No user-defined toolchain, setting default toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
78+
endif()
79+
80+
# This flag is needed when redefining a different compiler toolchain at this point
81+
# on CMakeLists, the reason is that CMake does a compiler testing prior to building
82+
# that may fail due to cross-compilation
83+
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
5884
else()
59-
# Set toolchain file that expect the same toolchain as IDF sets on PATH
60-
set(CMAKE_TOOLCHAIN_FILE ${ESPRESSIF_PORT_DIR}/tools/toolchain-${MCUBOOT_TARGET}.cmake)
61-
message("No user-defined toolchain, setting default toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
85+
message("CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
6286
endif()
63-
64-
# This flag is needed when redefining a different compiler toolchain at this point
65-
# on CMakeLists, the reason is that CMake does a compiler testing prior to building
66-
# that may fail due to cross-compilation
67-
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
68-
else()
69-
message("CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
7087
endif()
7188

7289
# Set directories
@@ -342,9 +359,16 @@ add_custom_command(
342359
COMMENT "Preprocessing bootloader.ld linker script..."
343360
)
344361

345-
list(APPEND LDFLAGS
346-
"-Wl,--Map=${APP_NAME}.map"
347-
)
362+
if(SYSBUILD)
363+
# Building from Zephyr uses its own defined functions to set the
364+
# sources for building
365+
include(zephyr/zephyr.cmake)
366+
return()
367+
else()
368+
list(APPEND LDFLAGS
369+
"-Wl,--Map=${APP_NAME}.map"
370+
)
371+
endif()
348372

349373
add_subdirectory(hal)
350374

0 commit comments

Comments
 (0)