@@ -7,66 +7,83 @@ cmake_policy(SET CMP0109 NEW)
7
7
8
8
include (${CMAKE_CURRENT_LIST_DIR} /tools/utils.cmake)
9
9
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" )
12
13
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} )
16
15
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" )
18
23
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 )
23
28
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" )
29
32
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} )
37
34
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
+ )
43
39
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 ()
51
45
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} " )
55
50
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" )
58
84
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} " )
62
86
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} " )
70
87
endif ()
71
88
72
89
# Set directories
@@ -342,9 +359,16 @@ add_custom_command(
342
359
COMMENT "Preprocessing bootloader.ld linker script..."
343
360
)
344
361
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 ()
348
372
349
373
add_subdirectory (hal)
350
374
0 commit comments