Skip to content

Commit

Permalink
[nrf noup] cmake: multi image build support with IMAGE prefix
Browse files Browse the repository at this point in the history
Note: This was originally submitted upstream in zephyrproject-rtos#13672 and was
      rejected. NCS is carrying it as a noup for now. Another,
      more upstream-friendly approach will be needed.

We are seeing the need to boot Zephyr applications in multiple
stages, a real-world use-case 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. To work within CMake restrictions that logical
target names must be globally unique (among other naming
restrictions), we add an IMAGE variable which is used to name the
current Zephyr application being built.

Signed-off-by: Sebastian Bøe <[email protected]>
Signed-off-by: Håkon Øye Amundsen <[email protected]>
Signed-off-by: Øyvind Rønningstad <[email protected]>
Signed-off-by: Robert Lubos <[email protected]>
Signed-off-by: Ruth Fuchss <[email protected]>
Signed-off-by: Marti Bolivar <[email protected]>

(cherry picked from commit b4d8e6d)
(cherry picked from commit 611e46e)
(cherry picked from commit 0b31f6a)
(cherry picked from commit 1b48170)
  • Loading branch information
SebastianBoe authored and mbolivar-nordic committed Aug 6, 2019
1 parent 6702fed commit 3db22ac
Show file tree
Hide file tree
Showing 26 changed files with 717 additions and 399 deletions.
216 changes: 111 additions & 105 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion arch/arm/core/cortex_m/tz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)
# Indicate that the entry veneers library file is created during linking of this firmware.
set_property(
GLOBAL APPEND PROPERTY
extra_post_build_byproducts
${IMAGE}extra_post_build_byproducts
${CMAKE_BINARY_DIR}/${CONFIG_ARM_ENTRY_VENEERS_LIB_NAME}
)
endif()
Expand Down
30 changes: 16 additions & 14 deletions arch/x86/ia32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# SPDX-License-Identifier: Apache-2.0

# Find out if we are optimizing for size
get_target_property(zephyr_COMPILE_OPTIONS zephyr_interface INTERFACE_COMPILE_OPTIONS)
get_target_property(zephyr_COMPILE_OPTIONS ${IMAGE}zephyr_interface INTERFACE_COMPILE_OPTIONS)
if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS)
zephyr_cc_option(-mpreferred-stack-boundary=2)
else()
zephyr_compile_definitions(PERF_OPT)
endif()

if(CONFIG_X86_IAMCU)
set_property(GLOBAL APPEND PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__IAMCU)
set_property(GLOBAL APPEND PROPERTY ${IMAGE}PROPERTY_LINKER_SCRIPT_DEFINES -D__IAMCU)
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-iamcu")
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "iamcu:intel")
else()
Expand Down Expand Up @@ -52,8 +52,9 @@ set(gen_idt_output_files
${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin
${CMAKE_CURRENT_BINARY_DIR}/irq_vectors_alloc.bin
)
set(gen_idt_output_target ${IMAGE}gen_idt_output)
add_custom_target(
gen_idt_output
${gen_idt_output_target}
DEPENDS
${gen_idt_output_files}
)
Expand Down Expand Up @@ -94,24 +95,25 @@ function(add_bin_file_to_the_next_link target_dependency bin)
DEPENDS ${target_dependency} ${bin}.bin
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
add_library(${bin} STATIC IMPORTED GLOBAL)
set_property(TARGET ${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
add_dependencies(${bin} ${bin}_o)
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${bin})
add_custom_target(${IMAGE}${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
add_library(${IMAGE}${bin} STATIC IMPORTED GLOBAL)
set_property(TARGET ${IMAGE}${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
add_dependencies(${IMAGE}${bin} ${IMAGE}${bin}_o)
set_property(GLOBAL APPEND PROPERTY ${IMAGE}GENERATED_KERNEL_OBJECT_FILES ${IMAGE}${bin})
endfunction()

add_bin_file_to_the_next_link(gen_idt_output staticIdt)
add_bin_file_to_the_next_link(gen_idt_output irq_int_vector_map)
add_bin_file_to_the_next_link(gen_idt_output irq_vectors_alloc)
add_bin_file_to_the_next_link(${gen_idt_output_target} staticIdt)
add_bin_file_to_the_next_link(${gen_idt_output_target} irq_int_vector_map)
add_bin_file_to_the_next_link(${gen_idt_output_target} irq_vectors_alloc)

if(CONFIG_X86_MMU)
if(CONFIG_X86_KPTI)
set(user_mmu_tables_bin user_mmu_tables.bin)
endif()

set(mmu_tables_bin_target ${IMAGE}mmu_tables_bin)
add_custom_target(
mmu_tables_bin_target
${mmu_tables_bin_target}
DEPENDS
mmu_tables.bin
${user_mmu_tables_bin}
Expand All @@ -131,9 +133,9 @@ if(CONFIG_X86_MMU)
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
)

add_bin_file_to_the_next_link( mmu_tables_bin_target mmu_tables)
add_bin_file_to_the_next_link( ${mmu_tables_bin_target} mmu_tables)
if(CONFIG_X86_KPTI)
add_bin_file_to_the_next_link(mmu_tables_bin_target user_mmu_tables)
add_bin_file_to_the_next_link(${mmu_tables_bin_target} user_mmu_tables)
endif()
endif()

Expand Down
Loading

0 comments on commit 3db22ac

Please sign in to comment.