-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi image: using external project for multi image
This commit introduces the use of CMake External Project for multi-image builds. This commit also updates the manifest file to include the multi-image updates in the following zephyr modules - zephyr - mcuboot - nrfxlib It updates the manifest file to track upstream zephyr vewrsion of the folowing zephyr modules - tinycbor - mbedtls - mcumgr Signed-off-by: Torsten Rasmussen <[email protected]>
- Loading branch information
1 parent
f9f93a7
commit 9588c77
Showing
17 changed files
with
574 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
# | ||
# Copyright (c) 2019 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic | ||
# | ||
|
||
if(IMAGE_NAME) | ||
set_property( | ||
TARGET zephyr_property_target | ||
APPEND_STRING | ||
PROPERTY shared_vars | ||
"set(${IMAGE_NAME}KERNEL_HEX_NAME ${KERNEL_HEX_NAME})\n" | ||
) | ||
|
||
set_property( | ||
TARGET zephyr_property_target | ||
APPEND_STRING | ||
PROPERTY shared_vars | ||
"list(APPEND ${IMAGE_NAME}BUILD_BYPRODUCTS ${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME})\n" | ||
) | ||
|
||
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/shared_vars.cmake | ||
CONTENT $<TARGET_PROPERTY:zephyr_property_target,shared_vars> | ||
) | ||
endif(IMAGE_NAME) | ||
|
||
function(image_board_selection board_in board_out) | ||
# It is assumed that only the root app will be built as non-secure. | ||
# This is not a valid assumption as there might be multiple non-secure | ||
# images defined. | ||
# TODO: Allow multiple non-secure images by using Kconfig to set the | ||
# secure/non-secure property rather than using a separate board definition. | ||
if(${board_in} STREQUAL nrf9160_pca10090ns) | ||
set(${board_out} nrf9160_pca10090 PARENT_SCOPE) | ||
message("Changed board to secure nrf9160_pca10090 (NOT NS)") | ||
|
||
elseif(${board_in} STREQUAL nrf9160_pca20035ns) | ||
set(${board_out} nrf9160_pca20035 PARENT_SCOPE) | ||
message("Changed board to secure nrf9160_pca20035 (NOT NS)") | ||
|
||
elseif(${board_in} STREQUAL actinius_icarus_ns) | ||
set(${board_out} actinius_icarus PARENT_SCOPE) | ||
message("Changed board to secure actinius_icarus (NOT NS)") | ||
|
||
else() | ||
set(${board_out} ${board_in} PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
function(add_child_image name sourcedir) | ||
string(TOUPPER ${name} UPNAME) | ||
|
||
if (CONFIG_${UPNAME}_BUILD_STRATEGY_USE_HEX_FILE) | ||
assert_exists(CONFIG_${UPNAME}_HEX_FILE) | ||
message("Using ${CONFIG_${UPNAME}_HEX_FILE} instead of building ${name}") | ||
elseif (CONFIG_${UPNAME}_BUILD_STRATEGY_SKIP_BUILD) | ||
message("Skipping building of ${name}") | ||
else() | ||
# Build normally | ||
add_child_image_from_source(${name} ${sourcedir}) | ||
endif() | ||
endfunction() | ||
|
||
function(add_child_image_from_source name sourcedir) | ||
message("\n=== child image ${name} begin ===") | ||
|
||
# Construct a list of variables that, when present in the root | ||
# image, should be passed on to all child images as well. | ||
list(APPEND | ||
SHARED_MULTI_IMAGE_VARIABLES | ||
BOARD_DIR | ||
ZEPHYR_MODULES | ||
ZEPHYR_EXTRA_MODULES | ||
ZEPHYR_TOOLCHAIN_VARIANT | ||
GNUARMEMB_TOOLCHAIN_PATH | ||
EXTRA_KCONFIG_TARGETS | ||
) | ||
|
||
foreach(kconfig_target ${EXTRA_KCONFIG_TARGETS}) | ||
list(APPEND | ||
SHARED_MULTI_IMAGE_VARIABLES | ||
EXTRA_KCONFIG_TARGET_COMMAND_FOR_${kconfig_target} | ||
) | ||
endforeach() | ||
|
||
unset(image_cmake_args) | ||
list(REMOVE_DUPLICATES SHARED_MULTI_IMAGE_VARIABLES) | ||
foreach(shared_var ${SHARED_MULTI_IMAGE_VARIABLES}) | ||
if(DEFINED ${shared_var}) | ||
list(APPEND image_cmake_args | ||
-D${shared_var}=${${shared_var}} | ||
) | ||
endif() | ||
endforeach() | ||
|
||
# Set ${name}_BOARD based on what BOARD is set to. | ||
image_board_selection(${BOARD} ${name}_BOARD) | ||
|
||
get_cmake_property(VARIABLES VARIABLES) | ||
get_cmake_property(VARIABLES_CACHED CACHE_VARIABLES) | ||
|
||
set(regex "^${name}_.+") | ||
|
||
list(FILTER VARIABLES INCLUDE REGEX ${regex}) | ||
list(FILTER VARIABLES_CACHED INCLUDE REGEX ${regex}) | ||
|
||
foreach(var_name | ||
${VARIABLES} | ||
${VARIABLES_CACHED} | ||
) | ||
# This regex is guaranteed to match due to the filtering done | ||
# above, we only re-run the regex to extract the part after | ||
# '_'. We run the regex twice because it is believed that | ||
# list(FILTER is faster than doing a string(REGEX on each item. | ||
string(REGEX MATCH "^${name}_(.+)" unused_out_var ${var_name}) | ||
list(APPEND image_cmake_args | ||
-D${CMAKE_MATCH_1}=${${var_name}} | ||
) | ||
endforeach() | ||
|
||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${name}) | ||
execute_process( | ||
COMMAND ${CMAKE_COMMAND} | ||
-G${CMAKE_GENERATOR} | ||
${EXTRA_MULTI_IMAGE_CMAKE_ARGS} # E.g. --trace-expand | ||
-DIMAGE_NAME=${name}_ | ||
${image_cmake_args} | ||
${sourcedir} | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${name} | ||
RESULT_VARIABLE ret | ||
) | ||
|
||
set_property(DIRECTORY APPEND PROPERTY | ||
CMAKE_CONFIGURE_DEPENDS | ||
${CMAKE_BINARY_DIR}/${name}/zephyr/.config | ||
) | ||
|
||
if(NOT ${ret} EQUAL "0") | ||
message(FATAL_ERROR "CMake generation for ${name} failed, aborting. Command: ${ret}") | ||
endif() | ||
|
||
message("=== child image ${name} end ===\n") | ||
|
||
# Include some variables from the child image into the parent image | ||
# namespace | ||
include(${CMAKE_BINARY_DIR}/${name}/shared_vars.cmake) | ||
|
||
# Increase the scope of this variable to make it more available | ||
set(${name}_KERNEL_HEX_NAME ${${name}_KERNEL_HEX_NAME} CACHE STRING "" FORCE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(${name}_subimage | ||
SOURCE_DIR ${sourcedir} | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/${name} | ||
BUILD_BYPRODUCTS ${${name}_BUILD_BYPRODUCTS} # Set by shared_vars.cmake | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} | ||
${EXTRA_MULTI_IMAGE_BUILD_OPT} # E.g. -v | ||
INSTALL_COMMAND "" | ||
BUILD_ALWAYS True | ||
) | ||
|
||
foreach(kconfig_target | ||
menuconfig | ||
guiconfig | ||
${EXTRA_KCONFIG_TARGETS} | ||
) | ||
add_custom_target(${name}_${kconfig_target} | ||
${CMAKE_MAKE_PROGRAM} ${kconfig_target} | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${name} | ||
USES_TERMINAL | ||
) | ||
endforeach() | ||
|
||
set_property( | ||
GLOBAL APPEND PROPERTY | ||
PM_IMAGES | ||
"${name}" | ||
) | ||
endfunction() |
Oops, something went wrong.