Skip to content

Commit 1707136

Browse files
committed
cmake: multi image build support
Add support for non-recursive single-toolchain multi-image builds. This resolves #7868. We are seeing the need to boot Zephyr applications in multiple stages, a real-world usecase of even a 3-stage bootloader has been identified and tested. Each bootloader needs to be individually upgrade-able and have it's own configurations of Zephyr libraries. To achieve this each bootloader is organized as it's own executable. The problem is that the build system can only build one executable. This creates a usability issue as the user must invoke a large set of arcane commands to build, sign, and flash each bootloader. To resolve this we re-organize the build system such that it can build multiple executables. Signed-off-by: Sebastian Bøe <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]>
1 parent 24c862c commit 1707136

File tree

47 files changed

+825
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+825
-456
lines changed

CMakeLists.txt

Lines changed: 120 additions & 92 deletions
Large diffs are not rendered by default.

arch/posix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ zephyr_compile_options(
1717
# @Intent: Obtain compiler specific flags for no freestanding compilation
1818
toolchain_cc_no_freestanding_options()
1919

20-
zephyr_include_directories(${BOARD_DIR})
20+
zephyr_include_directories(${${IMAGE}BOARD_DIR})
2121

2222
if (CONFIG_COVERAGE)
2323
toolchain_cc_coverage()

arch/x86/ia32.cmake

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2019 Intel Corp.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# Find out if we are optimizing for size
5-
get_target_property(zephyr_COMPILE_OPTIONS zephyr_interface INTERFACE_COMPILE_OPTIONS)
6-
if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS)
4+
if(CONFIG_SIZE_OPTIMIZATIONS)
75
zephyr_cc_option(-mpreferred-stack-boundary=2)
86
else()
97
zephyr_compile_definitions(PERF_OPT)
@@ -40,8 +38,9 @@ set(gen_idt_output_files
4038
${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin
4139
${CMAKE_CURRENT_BINARY_DIR}/irq_vectors_alloc.bin
4240
)
41+
set(gen_idt_output_target ${IMAGE}gen_idt_output)
4342
add_custom_target(
44-
gen_idt_output
43+
${gen_idt_output_target}
4544
DEPENDS
4645
${gen_idt_output_files}
4746
)
@@ -82,25 +81,26 @@ function(add_bin_file_to_the_next_link target_dependency bin)
8281
DEPENDS ${target_dependency} ${bin}.bin
8382
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
8483
)
85-
add_custom_target(${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
86-
add_library(${bin} STATIC IMPORTED GLOBAL)
87-
set_property(TARGET ${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
88-
add_dependencies(${bin} ${bin}_o)
89-
set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${bin})
84+
add_custom_target(${IMAGE}${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
85+
add_library(${IMAGE}${bin} STATIC IMPORTED GLOBAL)
86+
set_property(TARGET ${IMAGE}${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
87+
add_dependencies(${IMAGE}${bin} ${IMAGE}${bin}_o)
88+
set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${IMAGE}${bin})
9089
endfunction()
9190

92-
add_bin_file_to_the_next_link(gen_idt_output staticIdt)
93-
add_bin_file_to_the_next_link(gen_idt_output irq_int_vector_map)
94-
add_bin_file_to_the_next_link(gen_idt_output irq_vectors_alloc)
91+
add_bin_file_to_the_next_link(${gen_idt_output_target} staticIdt)
92+
add_bin_file_to_the_next_link(${gen_idt_output_target} irq_int_vector_map)
93+
add_bin_file_to_the_next_link(${gen_idt_output_target} irq_vectors_alloc)
9594

9695
if(CONFIG_GDT_DYNAMIC)
9796
# Use gen_gdt.py and objcopy to generate gdt.o from from the elf
9897
# file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the
9998
# way.
10099
#
101100
# ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o
101+
set(gdt_bin_target ${IMAGE}gdt_bin)
102102
add_custom_target(
103-
gdt_bin_target
103+
${gdt_bin_target}
104104
DEPENDS
105105
gdt.bin
106106
)
@@ -116,5 +116,5 @@ if(CONFIG_GDT_DYNAMIC)
116116
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
117117
)
118118

119-
add_bin_file_to_the_next_link(gdt_bin_target gdt)
119+
add_bin_file_to_the_next_link(${gdt_bin_target} gdt)
120120
endif()

boards/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# To avoid a lot of empty CMakeLists.txt files we assume it is not an
44
# error if it is missing
55

6-
if(EXISTS ${BOARD_DIR}/CMakeLists.txt)
6+
if(EXISTS ${${IMAGE}BOARD_DIR}/CMakeLists.txt)
77
if(USING_OUT_OF_TREE_BOARD)
8-
set(build_dir boards/${ARCH}/${BOARD})
8+
set(build_dir boards/${ARCH}/${${IMAGE}BOARD})
99
else()
1010
unset(build_dir)
1111
endif()
1212

13-
add_subdirectory(${BOARD_DIR} ${build_dir})
13+
add_subdirectory(${${IMAGE}BOARD_DIR} ${build_dir})
1414
endif()

boards/arm/lpcxpresso54114/board.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7+
message(STATUS "============================ HELLO FOR ${BOARD}")
8+
79
set_ifndef(LPCLINK_FW jlink)
810

911
if(LPCLINK_FW STREQUAL jlink)

boards/arm/qemu_cortex_r5/board.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH}
1414
)
1515

1616
set(QEMU_KERNEL_OPTION
17-
"-device;loader,file=$<TARGET_FILE:zephyr_final>,cpu-num=4"
17+
"-device;loader,file=$<TARGET_FILE:${IMAGE}zephyr_final>,cpu-num=4"
1818
)
1919

2020
board_set_debugger_ifnset(qemu)

boards/xtensa/intel_s1000_crb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(CONFIG_PINMUX_INTEL_S1000)
66
endif()
77

88
set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY extra_post_build_commands
9-
COMMAND ${PYTHON_EXECUTABLE} ${BOARD_DIR}/support/create_board_img.py
9+
COMMAND ${PYTHON_EXECUTABLE} ${${IMAGE}BOARD_DIR}/support/create_board_img.py
1010
-i ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
1111
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}_${BOARD}.bin
1212
-l $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2019 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
choice
8+
prompt "build strategy"
9+
default $(image)_BUILD_STRATEGY_FROM_SOURCE
10+
11+
config $(image)_BUILD_STRATEGY_SKIP_BUILD
12+
# Mandatory option when being built through 'zephyr_add_image'
13+
bool "Skip building"
14+
15+
config $(image)_BUILD_STRATEGY_FROM_SOURCE
16+
# Mandatory option when being built through 'zephyr_add_image'
17+
bool "Build from source"
18+
19+
endchoice

0 commit comments

Comments
 (0)