diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fbd2f38dd82a0..851037aedf1c16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,33 +45,63 @@ assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMa # is the last station. See "logical_target_for_zephyr_elf" below for # details. set(CMAKE_EXECUTABLE_SUFFIX .elf) -set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_prebuilt) -set(ZEPHYR_FINAL_EXECUTABLE zephyr_final) +set(FLASH_DEPS) +set(ZEPHYR_PREBUILT_EXECUTABLE ${IMAGE}zephyr_prebuilt) +set(ZEPHYR_FINAL_EXECUTABLE ${IMAGE}zephyr_final) # Set some phony targets to collect dependencies -set(OFFSETS_H_TARGET offsets_h) -set(SYSCALL_MACROS_H_TARGET syscall_macros_h_target) -set(SYSCALL_LIST_H_TARGET syscall_list_h_target) -set(DRIVER_VALIDATION_H_TARGET driver_validation_h_target) -set(KOBJ_TYPES_H_TARGET kobj_types_h_target) -set(LINKER_SCRIPT_TARGET linker_script_target) +set(OFFSETS_H_TARGET ${IMAGE}offsets_h) +set(SYSCALL_MACROS_H_TARGET ${IMAGE}syscall_macros_h_target) +set(SYSCALL_LIST_H_TARGET ${IMAGE}syscall_list_h_target) +set(DRIVER_VALIDATION_H_TARGET ${IMAGE}driver_validation_h_target) +set(KOBJ_TYPES_H_TARGET ${IMAGE}kobj_types_h_target) +set(LINKER_SCRIPT_TARGET ${IMAGE}linker_script_target) +set(OFFSETS_LIB ${IMAGE}offsets) +set(KERNEL_LIBRARY ${IMAGE}kernel) -define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") -set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) # BFD format +set(PRIV_STACKS_PREBUILT ${IMAGE}priv_stacks_prebuilt) -# "zephyr_interface" is a source-less library that encapsulates all the global +define_property(TARGET PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") +set_target_properties(${ZEPHYR_TARGET} PROPERTIES PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) # BFD format + +# ${IMAGE}zephyr_interface is a source-less library that encapsulates all the global # compiler options needed by all source files. All zephyr libraries, # including the library named "zephyr" link with this library to # obtain these flags. # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#interface-libraries -add_library(zephyr_interface INTERFACE) +add_library(${IMAGE}zephyr_interface INTERFACE) # "zephyr" is a catch-all CMake library for source files that can be # built purely with the include paths, defines, and other compiler # flags that come with zephyr_interface. zephyr_library_named(zephyr) +# Define common ZEPHYR_TARGET property definitions and set initial +# values. +define_property(TARGET PROPERTY GENERATED_KERNEL_SOURCE_FILES + BRIEF_DOCS "Source files that are generated after Zephyr has been linked once." + FULL_DOCS "\ +Source files that are generated after Zephyr has been linked once.\ +May include isr_tables.c etc." + ) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES GENERATED_KERNEL_SOURCE_FILES "") + +define_property(TARGET PROPERTY GENERATED_KERNEL_OBJECT_FILES + BRIEF_DOCS "Object files that are generated after Zephyr has been linked once." + FULL_DOCS "\ +Object files that are generated after Zephyr has been linked once.\ +May include mmu tables, etc." + ) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES GENERATED_KERNEL_OBJECT_FILES "") + + +define_property(TARGET PROPERTY ZEPHYR_INTERFACE_LIBS + BRIEF_DOCS "Global list of all Zephyr interface libs that should be linked in." + FULL_DOCS "Global list of all Zephyr interface libs that should be linked in. +zephyr_interface_library_named() appends libs to this list.") +set_target_properties(${ZEPHYR_TARGET} PROPERTIES ZEPHYR_INTERFACE_LIBS "") + zephyr_include_directories( kernel/include ${ARCH_DIR}/${ARCH}/include @@ -347,7 +377,7 @@ if(CONFIG_USERSPACE) set(APP_SMEM_ALIGNED_DEP app_smem_aligned_linker) set(APP_SMEM_UNALIGNED_DEP app_smem_unaligned_linker) if(CONFIG_ARM) - set(PRIV_STACK_DEP priv_stacks_prebuilt) + set(PRIV_STACK_DEP ${PRIV_STACKS_PREBUILT}) endif() endif() @@ -363,7 +393,7 @@ if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) endif() else() # Try a board specific linker file - set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) + set(LINKER_SCRIPT ${${IMAGE}BOARD_DIR}/linker.ld) if(NOT EXISTS ${LINKER_SCRIPT}) # If not available, try an SoC specific linker file set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) @@ -386,7 +416,7 @@ configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h) # Error-out when the deprecated naming convention is found (until # after 1.14.0 has been released) foreach(path - ${BOARD_DIR}/dts.fixup + ${${IMAGE}BOARD_DIR}/dts.fixup ${PROJECT_SOURCE_DIR}/soc/${ARCH}/${SOC_PATH}/dts.fixup ${APPLICATION_SOURCE_DIR}/dts.fixup ) @@ -399,24 +429,24 @@ foreach(path endif() endforeach() -set_ifndef( DTS_BOARD_FIXUP_FILE ${BOARD_DIR}/dts_fixup.h) -set_ifndef( DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts_fixup.h) -set( DTS_APP_FIXUP_FILE ${APPLICATION_SOURCE_DIR}/dts_fixup.h) +set_ifndef(${IMAGE}DTS_BOARD_FIXUP_FILE ${${IMAGE}BOARD_DIR}/dts_fixup.h) +set_ifndef(${IMAGE}DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts_fixup.h) +set( DTS_APP_FIXUP_FILE ${APPLICATION_SOURCE_DIR}/dts_fixup.h) -set_ifndef(DTS_CAT_OF_FIXUP_FILES ${ZEPHYR_BINARY_DIR}/include/generated/generated_dts_board_fixups.h) +set_ifndef(${IMAGE}DTS_CAT_OF_FIXUP_FILES ${ZEPHYR_BINARY_DIR}/include/generated/generated_dts_board_fixups.h) # Concatenate the fixups into a single header file for easy # #include'ing -file(WRITE ${DTS_CAT_OF_FIXUP_FILES} "/* May only be included by generated_dts_board.h */\n\n") +file(WRITE ${${IMAGE}DTS_CAT_OF_FIXUP_FILES} "/* May only be included by generated_dts_board.h */\n\n") foreach(fixup_file - ${DTS_BOARD_FIXUP_FILE} - ${DTS_SOC_FIXUP_FILE} + ${${IMAGE}DTS_BOARD_FIXUP_FILE} + ${${IMAGE}DTS_SOC_FIXUP_FILE} ${DTS_APP_FIXUP_FILE} ${shield_dts_fixups} ) if(EXISTS ${fixup_file}) file(READ ${fixup_file} contents) - file(APPEND ${DTS_CAT_OF_FIXUP_FILES} "${contents}") + file(APPEND ${${IMAGE}DTS_CAT_OF_FIXUP_FILES} "${contents}") endif() endforeach() @@ -426,12 +456,11 @@ endforeach() # build are not exported to external build systems #5605"; when we # integrate with an external build system we read out all compiler # flags when the external project is created. So an external project -# defined in subsys or ext will not get global flags added by drivers/ +# defined in subsys or ext will not get image-global flags added by drivers/ # or tests/ as the subdirectories are ordered now. # # Another example of when the order matters is the reading and writing -# of global properties such as ZEPHYR_LIBS or -# GENERATED_KERNEL_OBJECT_FILES. +# of properties such as ZEPHYR_LIBS or GENERATED_KERNEL_OBJECT_FILES. # # Arch is placed early because it defines important compiler flags # that must be exported to external build systems defined in @@ -470,7 +499,7 @@ if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) # this binary_dir is created but stays empty. Object files land in # the main binary dir instead. # https://cmake.org/pipermail/cmake/2019-June/069547.html - add_subdirectory(${module_path} ${CMAKE_BINARY_DIR}/modules/${module_name}) + add_subdirectory(${module_path} ${CMAKE_CURRENT_BINARY_DIR}/${module_name}) endforeach() endif() @@ -612,13 +641,10 @@ gen_kobj(KOBJ_INCLUDE_PATH) # Generate offsets.c.obj from offsets.c # Generate offsets.h from offsets.c.obj -set(OFFSETS_LIB offsets) - set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c) set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) - add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH}) -target_link_libraries(${OFFSETS_LIB} zephyr_interface) +target_link_libraries(${OFFSETS_LIB} ${IMAGE}zephyr_interface) add_dependencies( ${OFFSETS_LIB} ${SYSCALL_LIST_H_TARGET} ${SYSCALL_MACROS_H_TARGET} @@ -644,17 +670,17 @@ zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) add_subdirectory(kernel) # Read list content -get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) +get_target_property(ZEPHYR_LIBS_PROPERTY ${ZEPHYR_TARGET} ZEPHYR_LIBS) foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) - # TODO: Could this become an INTERFACE property of zephyr_interface? + # TODO: Could this become an INTERFACE property of ${IMAGE}zephyr_interface? add_dependencies(${zephyr_lib} ${OFFSETS_H_TARGET}) endforeach() -get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) +get_target_property(OUTPUT_FORMAT ${ZEPHYR_TARGET} PROPERTY_OUTPUT_FORMAT) if (CONFIG_CODE_DATA_RELOCATION) - set(CODE_RELOCATION_DEP code_relocation_source_lib) + set(CODE_RELOCATION_DEP ${IMAGE}code_relocation_source_lib) endif() # CONFIG_CODE_DATA_RELOCATION configure_linker_script( @@ -718,7 +744,7 @@ if(CONFIG_GEN_ISR_TABLES) ${GEN_ISR_TABLE_EXTRA_ARG} DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} ) - set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) endif() if(CONFIG_CODE_DATA_RELOCATION) @@ -732,13 +758,13 @@ if(CONFIG_USERSPACE) string(REPLACE "-fprofile-arcs" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") string(REPLACE "-fno-inline" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") - get_property(include_dir_in_interface TARGET zephyr_interface + get_property(include_dir_in_interface TARGET ${IMAGE}zephyr_interface PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - get_property(sys_include_dir_in_interface TARGET zephyr_interface + get_property(sys_include_dir_in_interface TARGET ${IMAGE}zephyr_interface PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) - get_property(compile_definitions_interface TARGET zephyr_interface + get_property(compile_definitions_interface TARGET ${IMAGE}zephyr_interface PROPERTY INTERFACE_COMPILE_DEFINITIONS) endif() @@ -755,6 +781,14 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) set(PRIV_STACKS_OUTPUT_OBJ priv_stacks_hash.c.obj) set(PRIV_STACKS_OUTPUT_OBJ_RENAMED priv_stacks_hash_renamed.o) + set(PRIV_STACKS_T ${IMAGE}priv_stacks) + set(PRIV_STACKS_OUTPUT_SRC_PRE_T ${IMAGE}priv_stacks_output_src_pre) + set(PRIV_STACKS_OUTPUT_SRC_T ${IMAGE}priv_stacks_output_src) + set(PRIV_STACKS_OUTPUT_LIB ${IMAGE}priv_stacks_output_lib) + set(PRIV_STACKS_OUTPUT_LIB_INTERFACE ${IMAGE}priv_stacks_output_lib_interface) + set(PRIV_STACKS_OUTPUT_OBJ_RENAMED_T ${IMAGE}priv_stacks_output_obj_renamed) + set(PRIV_STACKS_OUTPUT_OBJ_RENAMED_LIB ${IMAGE}priv_stacks_output_obj_renamed_lib) + # Essentially what we are doing here is extracting some information # out of the nearly finished elf file, generating the source code # for a hash table based on that information, and then compiling and @@ -769,13 +803,13 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) COMMAND ${PYTHON_EXECUTABLE} ${GEN_PRIV_STACKS} - --kernel $ + --kernel $ --output ${PRIV_STACKS} $<$:--verbose> - DEPENDS priv_stacks_prebuilt + DEPENDS ${PRIV_STACKS_PREBUILT} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(priv_stacks DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS}) + add_custom_target(${PRIV_STACKS_T} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS}) # Use gperf to generate C code (PRIV_STACKS_OUTPUT_SRC_PRE) which implements a # perfect hashtable based on PRIV_STACKS @@ -785,10 +819,11 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) ${GPERF} -C --output-file ${PRIV_STACKS_OUTPUT_SRC_PRE} ${PRIV_STACKS} - DEPENDS priv_stacks ${PRIV_STACKS} + DEPENDS ${PRIV_STACKS_T} ${PRIV_STACKS} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(priv_stacks_output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE}) + add_custom_target(${PRIV_STACKS_OUTPUT_SRC_PRE_T} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE}) # For our purposes the code/data generated by gperf is not optimal. # @@ -804,10 +839,11 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) -o ${PRIV_STACKS_OUTPUT_SRC} -p "struct _k_priv_stack_map" $<$:--verbose> - DEPENDS priv_stacks_output_src_pre ${PRIV_STACKS_OUTPUT_SRC_PRE} + DEPENDS ${PRIV_STACKS_OUTPUT_SRC_PRE_T} ${PRIV_STACKS_OUTPUT_SRC_PRE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(priv_stacks_output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}) + add_custom_target(${PRIV_STACKS_OUTPUT_SRC_T} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}") @@ -819,25 +855,29 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) # We need precise control of where generated text/data ends up in the final # kernel image. Disable function/data sections and use objcopy to move # generated data into special section names - add_library(priv_stacks_output_lib STATIC + add_library(${PRIV_STACKS_OUTPUT_LIB} STATIC ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} ) # Turn off -ffunction-sections, etc. - # NB: Using a library instead of target_compile_options(priv_stacks_output_lib + # NB: Using a library instead of + # target_compile_options(${PRIV_STACKS_OUTPUT_LIB} # [...]) because a library's options have precedence - add_library(priv_stacks_output_lib_interface INTERFACE) + add_library(${PRIV_STACKS_OUTPUT_LIB_INTERFACE} INTERFACE) foreach(incl ${include_dir_in_interface}) - target_include_directories(priv_stacks_output_lib_interface INTERFACE ${incl}) + target_include_directories(${PRIV_STACKS_OUTPUT_LIB_INTERFACE} INTERFACE ${incl}) endforeach() foreach(incl ${sys_include_dir_in_interface}) - target_include_directories(priv_stacks_output_lib_interface SYSTEM INTERFACE ${incl}) + target_include_directories(${PRIV_STACKS_OUTPUT_LIB_INTERFACE} SYSTEM INTERFACE ${incl}) endforeach() - target_link_libraries(priv_stacks_output_lib priv_stacks_output_lib_interface) + target_link_libraries(${PRIV_STACKS_OUTPUT_LIB} + ${PRIV_STACKS_OUTPUT_LIB_INTERFACE}) + - set(PRIV_STACKS_OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/priv_stacks_output_lib.dir/${PRIV_STACKS_OUTPUT_OBJ}) + set(PRIV_STACKS_OUTPUT_OBJ_PATH + ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PRIV_STACKS_OUTPUT_LIB}.dir/${PRIV_STACKS_OUTPUT_OBJ}) set(obj_copy_cmd "") set(obj_copy_sections_rename @@ -855,23 +895,25 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} ${obj_copy_cmd} - DEPENDS priv_stacks_output_lib + DEPENDS ${PRIV_STACKS_OUTPUT_LIB} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(priv_stacks_output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}) + add_custom_target(${PRIV_STACKS_OUTPUT_OBJ_RENAMED_T} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}) - add_library(priv_stacks_output_obj_renamed_lib STATIC IMPORTED GLOBAL) + add_library(${PRIV_STACKS_OUTPUT_OBJ_RENAMED_LIB} STATIC IMPORTED GLOBAL) set_property( - TARGET priv_stacks_output_obj_renamed_lib + TARGET ${PRIV_STACKS_OUTPUT_OBJ_RENAMED_LIB} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} ) add_dependencies( - priv_stacks_output_obj_renamed_lib - priv_stacks_output_obj_renamed + ${PRIV_STACKS_OUTPUT_OBJ_RENAMED_LIB} + ${PRIV_STACKS_OUTPUT_OBJ_RENAMED_T} ) - set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES priv_stacks_output_obj_renamed_lib) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES + ${PRIV_STACKS_OUTPUT_OBJ_RENAMED_LIB}) endif() # Warning: most of this gperf code is duplicated above for @@ -886,6 +928,13 @@ if(CONFIG_USERSPACE) set(OUTPUT_OBJ kobject_hash.c.obj) set(OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) + set(OUTPUT_SRC_PRE_T ${IMAGE}output_src_pre) + set(OBJ_LIST_T ${IMAGE}obj_list) + set(OUTPUT_SRC_T ${IMAGE}output_src) + set(OUTPUT_LIB ${IMAGE}output_lib) + set(OUTPUT_LIB_INTERFACE ${IMAGE}output_lib_interface) + set(OUTPUT_OBJ_RENAMED_T ${IMAGE}output_obj_renamed) + set(OUTPUT_OBJ_RENAMED_LIB ${IMAGE}output_obj_renamed_lib) # Essentially what we are doing here is extracting some information # out of the nearly finished elf file, generating the source code # for a hash table based on that information, and then compiling and @@ -906,7 +955,7 @@ if(CONFIG_USERSPACE) DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) + add_custom_target(${OBJ_LIST_T} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) # Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a # perfect hashtable based on OBJ_LIST @@ -916,10 +965,10 @@ if(CONFIG_USERSPACE) ${GPERF} --output-file ${OUTPUT_SRC_PRE} ${OBJ_LIST} - DEPENDS obj_list ${OBJ_LIST} + DEPENDS ${OBJ_LIST_T} ${OBJ_LIST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) + add_custom_target(${OUTPUT_SRC_PRE_T} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) # For our purposes the code/data generated by gperf is not optimal. # @@ -935,15 +984,15 @@ if(CONFIG_USERSPACE) -o ${OUTPUT_SRC} -p "struct _k_object" $<$:--verbose> - DEPENDS output_src_pre ${OUTPUT_SRC_PRE} + DEPENDS ${OUTPUT_SRC_PRE_T} ${OUTPUT_SRC_PRE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) + add_custom_target(${OUTPUT_SRC_T} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) # We need precise control of where generated text/data ends up in the final # kernel image. Disable function/data sections and use objcopy to move # generated data into special section names - add_library(output_lib STATIC + add_library(${OUTPUT_LIB} STATIC ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC} ) @@ -954,21 +1003,21 @@ if(CONFIG_USERSPACE) PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}") # Turn off -ffunction-sections, etc. - # NB: Using a library instead of target_compile_options(output_lib + # NB: Using a library instead of target_compile_options(${OUTPUT_LIB} # [...]) because a library's options have precedence - add_library(output_lib_interface INTERFACE) + add_library(${OUTPUT_LIB_INTERFACE} INTERFACE) - target_link_libraries(output_lib output_lib_interface) + target_link_libraries(${OUTPUT_LIB} ${OUTPUT_LIB_INTERFACE}) foreach(incl ${include_dir_in_interface}) - target_include_directories(output_lib_interface INTERFACE ${incl}) + target_include_directories(${OUTPUT_LIB_INTERFACE} INTERFACE ${incl}) endforeach() foreach(incl ${sys_include_dir_in_interface}) - target_include_directories(output_lib_interface SYSTEM INTERFACE ${incl}) + target_include_directories(${OUTPUT_LIB_INTERFACE} SYSTEM INTERFACE ${incl}) endforeach() - set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ}) + set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${OUTPUT_LIB}.dir/${OUTPUT_OBJ}) set(obj_copy_cmd "") set(obj_copy_sections_rename @@ -985,28 +1034,29 @@ if(CONFIG_USERSPACE) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} ${obj_copy_cmd} - DEPENDS output_lib + DEPENDS ${OUTPUT_LIB} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) + add_custom_target(${OUTPUT_OBJ_RENAMED_T} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) - add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL) + add_library(${OUTPUT_OBJ_RENAMED_LIB} STATIC IMPORTED GLOBAL) set_property( - TARGET output_obj_renamed_lib + TARGET ${OUTPUT_OBJ_RENAMED_LIB} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} ) add_dependencies( - output_obj_renamed_lib - output_obj_renamed + ${OUTPUT_OBJ_RENAMED_LIB} + ${OUTPUT_OBJ_RENAMED_T} ) - set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES + ${OUTPUT_OBJ_RENAMED_LIB}) endif() # Read global variables into local variables -get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) -get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) +get_target_property(GKOF ${ZEPHYR_TARGET} GENERATED_KERNEL_OBJECT_FILES) +get_target_property(GKSF ${ZEPHYR_TARGET} GENERATED_KERNEL_SOURCE_FILES) get_property(CSTD GLOBAL PROPERTY CSTD) @@ -1054,7 +1104,7 @@ if(CONFIG_USERSPACE) ${NEWLIB_PART} ${MBEDTLS_PART} $<$:--verbose> DEPENDS - kernel + ${KERNEL_LIBRARY} ${ZEPHYR_LIBS_PROPERTY} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ COMMENT "Generating app_smem_unaligned linker section" @@ -1103,7 +1153,7 @@ if(CONFIG_USERSPACE) ${NEWLIB_PART} ${MBEDTLS_PART} $<$:--verbose> DEPENDS - kernel + ${KERNEL_LIBRARY} ${ZEPHYR_LIBS_PROPERTY} app_smem_unaligned_prebuilt WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ @@ -1122,29 +1172,29 @@ if(CONFIG_USERSPACE AND CONFIG_ARM) ) add_custom_target( - linker_priv_stacks_script + ${IMAGE}linker_priv_stacks_script DEPENDS linker_priv_stacks.cmd ) set_property(TARGET - linker_priv_stacks_script + ${IMAGE}linker_priv_stacks_script PROPERTY INCLUDE_DIRECTORIES ${ZEPHYR_INCLUDE_DIRS} ) - set(PRIV_STACK_LIB priv_stacks_output_obj_renamed_lib) - add_executable( priv_stacks_prebuilt misc/empty_file.c) + set(PRIV_STACK_LIB ${IMAGE}priv_stacks_output_obj_renamed_lib) + add_executable( ${PRIV_STACKS_PREBUILT} misc/empty_file.c) toolchain_ld_link_elf( - TARGET_ELF priv_stacks_prebuilt + TARGET_ELF ${PRIV_STACKS_PREBUILT} OUTPUT_MAP ${PROJECT_BINARY_DIR}/priv_stacks_prebuilt.map LIBRARIES_PRE_SCRIPT "" LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd LIBRARIES_POST_SCRIPT "" DEPENDENCIES ${CODE_RELOCATION_DEP} ) - set_property(TARGET priv_stacks_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd) - add_dependencies( priv_stacks_prebuilt linker_priv_stacks_script ${OFFSETS_LIB}) + set_property(TARGET ${PRIV_STACKS_PREBUILT} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd) + add_dependencies( ${PRIV_STACKS_PREBUILT} ${IMAGE}linker_priv_stacks_script ${OFFSETS_LIB}) endif() # FIXME: Is there any way to get rid of empty_file.c? @@ -1179,7 +1229,7 @@ else() ${OFFSETS_H_TARGET} ) - set(LINKER_PASS_FINAL_SCRIPT_TARGET linker_pass_final_script_target) + set(LINKER_PASS_FINAL_SCRIPT_TARGET ${IMAGE}linker_pass_final_script_target) add_custom_target( ${LINKER_PASS_FINAL_SCRIPT_TARGET} DEPENDS @@ -1405,25 +1455,15 @@ if(CONFIG_BUILD_OUTPUT_EXE) ) endif() -get_property(extra_post_build_commands - GLOBAL PROPERTY - extra_post_build_commands - ) - -list(APPEND - post_build_commands - ${extra_post_build_commands} - ) - -get_property(extra_post_build_byproducts - GLOBAL PROPERTY - extra_post_build_byproducts - ) +get_target_property(extra_post_build_commands ${ZEPHYR_TARGET} extra_post_build_commands) +if(extra_post_build_commands) + list(APPEND post_build_commands ${extra_post_build_commands}) +endif() -list(APPEND - post_build_byproducts - ${extra_post_build_byproducts} - ) +get_target_property(extra_post_build_byproducts ${ZEPHYR_TARGET} extra_post_build_byproducts) +if(extra_post_build_byproducts) + list(APPEND post_build_byproducts ${extra_post_build_byproducts}) +endif() # Add post_build_commands to post-process the final .elf file produced by # either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable @@ -1434,14 +1474,15 @@ add_custom_command( ${post_build_commands} BYPRODUCTS ${post_build_byproducts} - COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}" + COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${${IMAGE}BOARD}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # NB: COMMENT only works for some CMake-Generators ) -# To populate with hex files to merge, do the following: -# set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list}) -# Note that the zephyr.hex file will not be included automatically. -get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) + +# Note that the zephyr.hex file is not automatically added to +# HEX_FILES_TO_MERGE. +get_target_property(HEX_FILES_TO_MERGE ${ZEPHYR_TARGET} HEX_FILES_TO_MERGE) if(HEX_FILES_TO_MERGE) # Merge in out-of-tree hex files. set(MERGED_HEX_NAME merged.hex) @@ -1456,14 +1497,15 @@ if(HEX_FILES_TO_MERGE) DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf} ) - add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME}) - list(APPEND FLASH_DEPS mergehex) + set(mergehex_target ${IMAGE}mergehex) + add_custom_target(${mergehex_target} ALL DEPENDS ${MERGED_HEX_NAME}) + list(APPEND FLASH_DEPS ${mergehex_target}) endif() if(EMU_PLATFORM) include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) else() - add_custom_target(run + add_custom_target(${IMAGE}run COMMAND ${CMAKE_COMMAND} -E echo "===================================================" @@ -1473,7 +1515,6 @@ else() endif() add_subdirectory(cmake/flash) -add_subdirectory(cmake/usage) add_subdirectory(cmake/reports) if(NOT CONFIG_TEST) @@ -1489,7 +1530,7 @@ endif() if(CONFIG_BOARD_DEPRECATED) message(WARNING " - WARNING: The board '${BOARD}' is deprecated and will be + WARNING: The board '${${IMAGE}BOARD}' is deprecated and will be removed in version ${CONFIG_BOARD_DEPRECATED}" ) endif() diff --git a/arch/arm/core/cortex_m/tz/CMakeLists.txt b/arch/arm/core/cortex_m/tz/CMakeLists.txt index 04c398adb8a747..589ae181067de9 100644 --- a/arch/arm/core/cortex_m/tz/CMakeLists.txt +++ b/arch/arm/core/cortex_m/tz/CMakeLists.txt @@ -20,9 +20,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 + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY extra_post_build_byproducts ${CMAKE_BINARY_DIR}/${CONFIG_ARM_ENTRY_VENEERS_LIB_NAME} ) endif() diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index df88a9df85fdee..dc62b8be3c5db2 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -17,7 +17,7 @@ zephyr_compile_options( # @Intent: Obtain compiler specific flags for no freestanding compilation toolchain_cc_no_freestanding_options() -zephyr_include_directories(${BOARD_DIR}) +zephyr_include_directories(${${IMAGE}BOARD_DIR}) if (CONFIG_COVERAGE) toolchain_cc_coverage() diff --git a/arch/riscv/CMakeLists.txt b/arch/riscv/CMakeLists.txt index e8065f777470ff..b6a9dfa5c62bdc 100644 --- a/arch/riscv/CMakeLists.txt +++ b/arch/riscv/CMakeLists.txt @@ -3,7 +3,8 @@ add_subdirectory(core) if(CONFIG_64BIT) -set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf64-littleriscv) +set(output_format elf64-littleriscv) else() -set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-littleriscv) +set(output_format elf32-littleriscv) endif() +set_target_properties(${ZEPHYR_TARGET} PROPERTIES PROPERTY_OUTPUT_FORMAT ${output_format}) diff --git a/arch/x86/ia32.cmake b/arch/x86/ia32.cmake index a14acdcc61b0a6..ba3e085375e56c 100644 --- a/arch/x86/ia32.cmake +++ b/arch/x86/ia32.cmake @@ -1,16 +1,16 @@ # Copyright (c) 2019 Intel Corp. # 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) -if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS) +if(CONFIG_SIZE_OPTIMIZATIONS) zephyr_cc_option(-mpreferred-stack-boundary=2) else() zephyr_compile_definitions(PERF_OPT) endif() -set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "i386") -set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-i386") +define_property(TARGET PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ") + +set_target_properties(${ZEPHYR_TARGET} PROPERTIES PROPERTY_OUTPUT_ARCH "i386" + PROPERTY_OUTPUT_FORMAT "elf32-i386") if(CMAKE_C_COMPILER_ID STREQUAL "Clang") zephyr_compile_options(-Qunused-arguments) @@ -31,8 +31,6 @@ endif() set(GENIDT ${ZEPHYR_BASE}/arch/x86/gen_idt.py) -define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ") - # Use gen_idt.py and objcopy to generate irq_int_vector_map.o, # irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE} set(gen_idt_output_files @@ -40,8 +38,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} ) @@ -62,8 +61,8 @@ add_custom_command( # Must be last so that soc/ can override default exception handlers add_subdirectory(core) -get_property(OUTPUT_ARCH GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH) -get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) +get_target_property(OUTPUT_ARCH ${ZEPHYR_TARGET} PROPERTY_OUTPUT_ARCH) +get_target_property(OUTPUT_FORMAT ${ZEPHYR_TARGET} PROPERTY_OUTPUT_FORMAT) # Convert the .bin file argument to a .o file, create a wrapper # library for the .o file, and register the library as a generated @@ -82,16 +81,16 @@ 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(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY 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_GDT_DYNAMIC) # Use gen_gdt.py and objcopy to generate gdt.o from from the elf @@ -99,8 +98,9 @@ if(CONFIG_GDT_DYNAMIC) # way. # # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o + set(gdt_bin_target ${IMAGE}gdt_bin) add_custom_target( - gdt_bin_target + ${gdt_bin_target} DEPENDS gdt.bin ) @@ -116,5 +116,5 @@ if(CONFIG_GDT_DYNAMIC) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_bin_file_to_the_next_link(gdt_bin_target gdt) + add_bin_file_to_the_next_link(${gdt_bin_target} gdt) endif() diff --git a/arch/xtensa/CMakeLists.txt b/arch/xtensa/CMakeLists.txt index 133d74331d8e66..f3d0443be2e7f8 100644 --- a/arch/xtensa/CMakeLists.txt +++ b/arch/xtensa/CMakeLists.txt @@ -1,4 +1,4 @@ # SPDX-License-Identifier: Apache-2.0 -set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-xtensa-le) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES PROPERTY_OUTPUT_FORMAT elf32-xtensa-le) add_subdirectory(core) diff --git a/boards/CMakeLists.txt b/boards/CMakeLists.txt index 943e52667e2763..15e9e280307789 100644 --- a/boards/CMakeLists.txt +++ b/boards/CMakeLists.txt @@ -3,12 +3,12 @@ # To avoid a lot of empty CMakeLists.txt files we assume it is not an # error if it is missing -if(EXISTS ${BOARD_DIR}/CMakeLists.txt) +if(EXISTS ${${IMAGE}BOARD_DIR}/CMakeLists.txt) if(USING_OUT_OF_TREE_BOARD) - set(build_dir boards/${ARCH}/${BOARD}) + set(build_dir boards/${ARCH}/${${IMAGE}BOARD}) else() unset(build_dir) endif() - add_subdirectory(${BOARD_DIR} ${build_dir}) + add_subdirectory(${${IMAGE}BOARD_DIR} ${build_dir}) endif() diff --git a/boards/arm/lpcxpresso54114/board.cmake b/boards/arm/lpcxpresso54114/board.cmake index dcedd71f11aaf7..0522bbaae605fd 100644 --- a/boards/arm/lpcxpresso54114/board.cmake +++ b/boards/arm/lpcxpresso54114/board.cmake @@ -4,6 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 # +message(STATUS "============================ HELLO FOR ${BOARD}") + set_ifndef(LPCLINK_FW jlink) if(LPCLINK_FW STREQUAL jlink) diff --git a/boards/arm/mps2_an385/board.cmake b/boards/arm/mps2_an385/board.cmake index 0ae7ec0e7a25f0..83933621908361 100644 --- a/boards/arm/mps2_an385/board.cmake +++ b/boards/arm/mps2_an385/board.cmake @@ -2,9 +2,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} cortex-m3) -set(QEMU_FLAGS_${ARCH} - -cpu ${QEMU_CPU_TYPE_${ARCH}} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} cortex-m3) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} + -cpu cortex-m3 -machine mps2-an385 -nographic -vga none diff --git a/boards/arm/mps2_an521/board.cmake b/boards/arm/mps2_an521/board.cmake index 015028a7e7a1b7..5625006fa6d7aa 100644 --- a/boards/arm/mps2_an521/board.cmake +++ b/boards/arm/mps2_an521/board.cmake @@ -2,9 +2,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} cortex-m33) -set(QEMU_FLAGS_${ARCH} - -cpu ${QEMU_CPU_TYPE_${ARCH}} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} cortex-m33) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} + -cpu cortex-m33 -machine mps2-an521 -nographic -m 16 diff --git a/boards/arm/qemu_cortex_m0/board.cmake b/boards/arm/qemu_cortex_m0/board.cmake index 5591c1405646cc..8e62d030450e9b 100644 --- a/boards/arm/qemu_cortex_m0/board.cmake +++ b/boards/arm/qemu_cortex_m0/board.cmake @@ -5,9 +5,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} cortex-m0) -set(QEMU_FLAGS_${ARCH} - -cpu ${QEMU_CPU_TYPE_${ARCH}} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} cortex-m0) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} + -cpu cortex-m0 -machine microbit -nographic -vga none diff --git a/boards/arm/qemu_cortex_m3/board.cmake b/boards/arm/qemu_cortex_m3/board.cmake index 4c2231a7dbf263..0ee2729ac2f81a 100644 --- a/boards/arm/qemu_cortex_m3/board.cmake +++ b/boards/arm/qemu_cortex_m3/board.cmake @@ -2,9 +2,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} cortex-m3) -set(QEMU_FLAGS_${ARCH} - -cpu ${QEMU_CPU_TYPE_${ARCH}} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} cortex-m3) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} + -cpu cortex-m3 -machine lm3s6965evb -nographic -vga none diff --git a/boards/arm/qemu_cortex_r5/board.cmake b/boards/arm/qemu_cortex_r5/board.cmake index d87553cf65c338..a5a1491537db68 100644 --- a/boards/arm/qemu_cortex_r5/board.cmake +++ b/boards/arm/qemu_cortex_r5/board.cmake @@ -5,8 +5,8 @@ set(EMU_PLATFORM qemu) set(QEMU_ARCH aarch64) -set(QEMU_CPU_TYPE_${ARCH} cortex-r5) -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} cortex-r5) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -nographic -machine xlnx-zcu102 -global xlnx,zynqmp.boot-cpu="rpu-cpu[0]" @@ -14,7 +14,7 @@ set(QEMU_FLAGS_${ARCH} ) set(QEMU_KERNEL_OPTION - "-device;loader,file=$,cpu-num=4" + "-device;loader,file=$,cpu-num=4" ) board_set_debugger_ifnset(qemu) diff --git a/boards/nios2/qemu_nios2/board.cmake b/boards/nios2/qemu_nios2/board.cmake index 02828cbe2e6027..3c131f14ad6073 100644 --- a/boards/nios2/qemu_nios2/board.cmake +++ b/boards/nios2/qemu_nios2/board.cmake @@ -2,9 +2,8 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} nios2) - -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} nios2) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -machine altera_10m50_zephyr -nographic ) diff --git a/boards/riscv/hifive1/board.cmake b/boards/riscv/hifive1/board.cmake index 9c7c650a9947ac..1b0ff622f96d64 100644 --- a/boards/riscv/hifive1/board.cmake +++ b/boards/riscv/hifive1/board.cmake @@ -2,9 +2,8 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} riscv32) - -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} riscv32) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -nographic -machine sifive_e ) diff --git a/boards/riscv/qemu_riscv32/board.cmake b/boards/riscv/qemu_riscv32/board.cmake index 56a403a439772c..ef049a6dd89963 100644 --- a/boards/riscv/qemu_riscv32/board.cmake +++ b/boards/riscv/qemu_riscv32/board.cmake @@ -2,10 +2,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_binary_suffix riscv32) -set(QEMU_CPU_TYPE_${ARCH} riscv32) - -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_binary_suffix riscv32) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} riscv32) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -nographic -machine sifive_e ) diff --git a/boards/riscv/qemu_riscv64/board.cmake b/boards/riscv/qemu_riscv64/board.cmake index 02826cfe494191..7cfd42395cb45e 100644 --- a/boards/riscv/qemu_riscv64/board.cmake +++ b/boards/riscv/qemu_riscv64/board.cmake @@ -2,10 +2,9 @@ set(EMU_PLATFORM qemu) -set(QEMU_binary_suffix riscv64) -set(QEMU_CPU_TYPE_${ARCH} riscv64) - -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_binary_suffix riscv64) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} riscv64) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -nographic -machine sifive_e ) diff --git a/boards/x86/qemu_x86/board.cmake b/boards/x86/qemu_x86/board.cmake index f9e9c6c4397c11..2432c4e02660ad 100644 --- a/boards/x86/qemu_x86/board.cmake +++ b/boards/x86/qemu_x86/board.cmake @@ -7,13 +7,17 @@ if(NOT CONFIG_REBOOT) endif() if(CONFIG_X86_LONGMODE) - set(QEMU_binary_suffix x86_64) + set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_binary_suffix x86_64) +endif() + +if(CONFIG_X86_LONGMODE) set(QEMU_CPU_TYPE_${ARCH} qemu64,+x2apic) else() set(QEMU_CPU_TYPE_${ARCH} qemu32,+nx,+pae) endif() -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} ${QEMU_CPU_TYPE_${ARCH}}) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -m 9 -cpu ${QEMU_CPU_TYPE_${ARCH}} -device isa-debug-exit,iobase=0xf4,iosize=0x04 diff --git a/boards/x86_64/qemu_x86_64/board.cmake b/boards/x86_64/qemu_x86_64/board.cmake index 59c62118ebbddd..eba6eb4f31ce4a 100644 --- a/boards/x86_64/qemu_x86_64/board.cmake +++ b/boards/x86_64/qemu_x86_64/board.cmake @@ -1,4 +1,4 @@ # SPDX-License-Identifier: Apache-2.0 set(EMU_PLATFORM qemu) -set(QEMU_FLAGS_${ARCH} -nographic) +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_FLAGS_${ARCH} -nographic) diff --git a/boards/xtensa/intel_s1000_crb/CMakeLists.txt b/boards/xtensa/intel_s1000_crb/CMakeLists.txt index aa04cf71208c05..983e51caac184d 100644 --- a/boards/xtensa/intel_s1000_crb/CMakeLists.txt +++ b/boards/xtensa/intel_s1000_crb/CMakeLists.txt @@ -5,8 +5,8 @@ if(CONFIG_PINMUX_INTEL_S1000) zephyr_library_sources(pinmux.c) endif() -set_property(GLOBAL APPEND PROPERTY extra_post_build_commands - COMMAND ${PYTHON_EXECUTABLE} ${BOARD_DIR}/support/create_board_img.py +set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY extra_post_build_commands + COMMAND ${PYTHON_EXECUTABLE} ${${IMAGE}BOARD_DIR}/support/create_board_img.py -i ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin -o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}_${BOARD}.bin -l $ diff --git a/boards/xtensa/qemu_xtensa/board.cmake b/boards/xtensa/qemu_xtensa/board.cmake index 822cdb1e2bd400..30dc5b7f1920aa 100644 --- a/boards/xtensa/qemu_xtensa/board.cmake +++ b/boards/xtensa/qemu_xtensa/board.cmake @@ -2,9 +2,8 @@ set(EMU_PLATFORM qemu) -set(QEMU_CPU_TYPE_${ARCH} sample_controller) - -set(QEMU_FLAGS_${ARCH} +set_target_properties(${ZEPHYR_TARGET} PROPERTIES QEMU_CPU_TYPE_${ARCH} sample_controller) +set_property(TARGET ${ZEPHYR_TARGET} PROPERTY QEMU_FLAGS_${ARCH} -machine sim -semihosting -nographic -cpu sample_controller ) diff --git a/cmake/Kconfig.template.build_strategy b/cmake/Kconfig.template.build_strategy new file mode 100644 index 00000000000000..0c8696b9bdf3fa --- /dev/null +++ b/cmake/Kconfig.template.build_strategy @@ -0,0 +1,19 @@ +# +# Copyright (c) 2019 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +choice + prompt "build strategy" + default $(image)_BUILD_STRATEGY_FROM_SOURCE + +config $(image)_BUILD_STRATEGY_SKIP_BUILD + # Mandatory option when being built through 'zephyr_add_image' + bool "Skip building" + +config $(image)_BUILD_STRATEGY_FROM_SOURCE + # Mandatory option when being built through 'zephyr_add_image' + bool "Build from source" + +endchoice diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 604fba339f5da5..759767229052c7 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -28,42 +28,38 @@ cmake_policy(SET CMP0002 NEW) # CMP0079: "target_link_libraries() allows use with targets in other directories" cmake_policy(SET CMP0079 OLD) -define_property(GLOBAL PROPERTY ZEPHYR_LIBS - BRIEF_DOCS "Global list of all Zephyr CMake libs that should be linked in" - FULL_DOCS "Global list of all Zephyr CMake libs that should be linked in. -zephyr_library() appends libs to this list.") -set_property(GLOBAL PROPERTY ZEPHYR_LIBS "") - -define_property(GLOBAL PROPERTY ZEPHYR_INTERFACE_LIBS - BRIEF_DOCS "Global list of all Zephyr interface libs that should be linked in." - FULL_DOCS "Global list of all Zephyr interface libs that should be linked in. -zephyr_interface_library_named() appends libs to this list.") -set_property(GLOBAL PROPERTY ZEPHYR_INTERFACE_LIBS "") - -define_property(GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES - BRIEF_DOCS "Object files that are generated after Zephyr has been linked once." - FULL_DOCS "\ -Object files that are generated after Zephyr has been linked once.\ -May include mmu tables, etc." - ) -set_property(GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES "") +get_property(IMAGE GLOBAL PROPERTY IMAGE) -define_property(GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES - BRIEF_DOCS "Source files that are generated after Zephyr has been linked once." - FULL_DOCS "\ -Source files that are generated after Zephyr has been linked once.\ -May include isr_tables.c etc." - ) -set_property(GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES "") +if(IMAGE) + set(FIRST_BOILERPLATE_EXECUTION 0) +else() + set(FIRST_BOILERPLATE_EXECUTION 1) +endif() + +if (NOT FIRST_BOILERPLATE_EXECUTION) + # Clear the Kconfig namespace of the other image. + # Since the CMake context of each subsequent image is loaded by "add_subdirectory" + # the Kconfig namespace is automatically restored by CMake. + get_cmake_property(names VARIABLES) + foreach (name ${names}) + if("${name}" MATCHES "^CONFIG_") + # When a variable starts with 'CONFIG_' it is assumed to be a + # Kconfig symbol. + unset(${name}) + endif() + endforeach() +endif(NOT FIRST_BOILERPLATE_EXECUTION) + +set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(APPLICATION_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Application Source Directory") -set(APPLICATION_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Application Binary Directory") +message(STATUS "Using application from '${APPLICATION_SOURCE_DIR}'") set(__build_dir ${CMAKE_CURRENT_BINARY_DIR}/zephyr) set(PROJECT_BINARY_DIR ${__build_dir}) -add_custom_target(code_data_relocation_target) +add_custom_target(${IMAGE}code_data_relocation_target) # CMake's 'project' concept has proven to not be very useful for Zephyr # due in part to how Zephyr is organized and in part to it not fitting well @@ -94,93 +90,145 @@ include(CheckCXXCompilerFlag) include(${ZEPHYR_BASE}/cmake/extensions.cmake) include(${ZEPHYR_BASE}/cmake/version.cmake) # depends on hex.cmake -# -# Find tools -# - -include(${ZEPHYR_BASE}/cmake/python.cmake) -include(${ZEPHYR_BASE}/cmake/git.cmake) # depends on version.cmake -include(${ZEPHYR_BASE}/cmake/ccache.cmake) - if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) message(FATAL_ERROR "Source directory equals build directory.\ In-source builds are not supported.\ Please specify a build directory, e.g. cmake -Bbuild -H.") endif() -add_custom_target( - pristine - COMMAND ${CMAKE_COMMAND} -P ${ZEPHYR_BASE}/cmake/pristine.cmake - # Equivalent to rm -rf build/* +if(FIRST_BOILERPLATE_EXECUTION) + # + # Find tools + # + + include(${ZEPHYR_BASE}/cmake/python.cmake) + include(${ZEPHYR_BASE}/cmake/git.cmake) # depends on version.cmake + include(${ZEPHYR_BASE}/cmake/ccache.cmake) + + add_custom_target( + pristine + COMMAND ${CMAKE_COMMAND} -P ${ZEPHYR_BASE}/cmake/pristine.cmake + # Equivalent to rm -rf build/* ) -# Dummy add to generate files. -zephyr_linker_sources(SECTIONS) + # 'BOARD_ROOT' is a prioritized list of directories where boards may + # be found. It always includes ${ZEPHYR_BASE} at the lowest priority. + list(APPEND BOARD_ROOT ${ZEPHYR_BASE}) +endif(FIRST_BOILERPLATE_EXECUTION) -# The BOARD can be set by 3 sources. Through environment variables, -# through the cmake CLI, and through CMakeLists.txt. +# Zephyr's linker scripts are the result of running the C preprocessor +# on per-architecture files. These files can include various sources from +# around the zephyr tree using the zephyr_linker_sources() mechanism. +# This helper is used to set up these files. +zephyr_init_linker_sources() + +# The ${IMAGE}BOARD can be set by 3 sources. Through environment +# variables, through the cmake CLI, and through CMakeLists.txt. # # CLI has the highest precedence, then comes environment variables, # and then finally CMakeLists.txt. # # A user can ignore all the precedence rules if he simply always uses -# the same source. E.g. always specifies -DBOARD= on the command line, -# always has an environment variable set, or always has a set(BOARD +# the same source. E.g. always specifies -D${IMAGE}BOARD= on the command line, +# always has an environment variable set, or always has a set(${IMAGE}BOARD # foo) line in his CMakeLists.txt and avoids mixing sources. # -# The selected BOARD can be accessed through the variable 'BOARD'. +# The selected board can be accessed through the variable '${IMAGE}BOARD'. # Read out the cached board value if present -get_property(cached_board_value CACHE BOARD PROPERTY VALUE) +get_property(cached_board_value CACHE ${IMAGE}BOARD PROPERTY VALUE) -# There are actually 4 sources, the three user input sources, and the -# previously used value (CACHED_BOARD). The previously used value has -# precedence, and if we detect that the user is trying to change the -# value we give him a warning about needing to clean the build -# directory to be able to change boards. +# There are actually 4 sources, the three user input sources, and +# the previously used value (${IMAGE}CACHED_BOARD). The previously +# used value has precedence, and if we detect that the user is +# trying to change the value we give him a warning about needing to +# clean the build directory to be able to change boards. set(board_cli_argument ${cached_board_value}) # Either new or old -if(board_cli_argument STREQUAL CACHED_BOARD) +if(board_cli_argument STREQUAL ${IMAGE}CACHED_BOARD) # We already have a CACHED_BOARD so there is no new input on the CLI unset(board_cli_argument) endif() -set(board_app_cmake_lists ${BOARD}) -if(cached_board_value STREQUAL BOARD) - # The app build scripts did not set a default, The BOARD we are - # reading is the cached value from the CLI +set(board_app_cmake_lists ${${IMAGE}BOARD}) +if(cached_board_value STREQUAL ${IMAGE}BOARD) + # The app build scripts did not set a default, The ${IMAGE}BOARD + # we are reading is the cached value from the CLI unset(board_app_cmake_lists) endif() -if(CACHED_BOARD) +if(${IMAGE}CACHED_BOARD) # Warn the user if it looks like he is trying to change the board # without cleaning first if(board_cli_argument) - if(NOT (CACHED_BOARD STREQUAL board_cli_argument)) + if(NOT (${IMAGE}CACHED_BOARD STREQUAL board_cli_argument)) message(WARNING "The build directory must be cleaned pristinely when changing boards") # TODO: Support changing boards without requiring a clean build endif() endif() - set(BOARD ${CACHED_BOARD}) + set(${IMAGE}BOARD ${${IMAGE}CACHED_BOARD}) elseif(board_cli_argument) - set(BOARD ${board_cli_argument}) + set(${IMAGE}BOARD ${board_cli_argument}) -elseif(DEFINED ENV{BOARD}) - set(BOARD $ENV{BOARD}) +elseif(DEFINED ENV{${IMAGE}BOARD}) + set(${IMAGE}BOARD $ENV{${IMAGE}BOARD}) elseif(board_app_cmake_lists) - set(BOARD ${board_app_cmake_lists}) + set(${IMAGE}BOARD ${board_app_cmake_lists}) -else() +elseif(FIRST_BOILERPLATE_EXECUTION) message(FATAL_ERROR "BOARD is not being defined on the CMake command-line in the environment or by the app.") +else() + # Default to using the same board as the toplevel image + set(${IMAGE}BOARD ${BOARD}) endif() -assert(BOARD "BOARD not set") -message(STATUS "Selected BOARD ${BOARD}") +assert(${IMAGE}BOARD "BOARD not set") +message(STATUS "Selected ${IMAGE}BOARD ${${IMAGE}BOARD}") # Store the selected board in the cache -set(CACHED_BOARD ${BOARD} CACHE STRING "Selected board") +set(${IMAGE}CACHED_BOARD ${${IMAGE}BOARD} CACHE STRING "Selected board") + +if(NOT ARCH_ROOT) + set(ARCH_DIR ${ZEPHYR_BASE}/arch) +else() + set(ARCH_DIR ${ARCH_ROOT}/arch) +endif() + +if(NOT SOC_ROOT) + set(SOC_DIR ${ZEPHYR_BASE}/soc) +else() + set(SOC_DIR ${SOC_ROOT}/soc) +endif() + +# Prevent CMake from testing the toolchain +set(CMAKE_C_COMPILER_FORCED 1) +set(CMAKE_CXX_COMPILER_FORCED 1) + +if(FIRST_BOILERPLATE_EXECUTION) + include(${ZEPHYR_BASE}/cmake/host-tools.cmake) + + string(REPLACE ";" " " BOARD_ROOT_SPACE_SEPARATED "${BOARD_ROOT}") + string(REPLACE ";" " " SHIELD_LIST_SPACE_SEPARATED "${SHIELD_LIST}") + + # NB: The reason it is 'usage' and not help is that CMake already + # defines a target 'help' + add_custom_target( + usage + ${CMAKE_COMMAND} + -DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED} + -DSHIELD_LIST_SPACE_SEPARATED=${SHIELD_LIST_SPACE_SEPARATED} + -P ${ZEPHYR_BASE}/cmake/usage/usage.cmake + ) + + include(${ZEPHYR_BASE}/cmake/zephyr_module.cmake) + + if(NOT DEFINED USER_CACHE_DIR) + find_appropriate_cache_directory(USER_CACHE_DIR) + endif() + message(STATUS "Cache files will be written to: ${USER_CACHE_DIR}") +endif(FIRST_BOILERPLATE_EXECUTION) # The SHIELD can be set by 3 sources. Through environment variables, # through the cmake CLI, and through CMakeLists.txt. @@ -194,9 +242,12 @@ set(CACHED_BOARD ${BOARD} CACHE STRING "Selected board") # foo) line in his CMakeLists.txt and avoids mixing sources. # # The selected SHIELD can be accessed through the variable 'SHIELD'. +# +# To specify a SHIELD specifically for an image, prefix with the image +# name. E.g. -Dmcuboot_SHIELD= on the command line. # Read out the cached shield value if present -get_property(cached_shield_value CACHE SHIELD PROPERTY VALUE) +get_property(cached_shield_value CACHE ${IMAGE}SHIELD PROPERTY VALUE) # There are actually 4 sources, the three user input sources, and the # previously used value (CACHED_SHIELD). The previously used value has @@ -205,76 +256,62 @@ get_property(cached_shield_value CACHE SHIELD PROPERTY VALUE) # directory to be able to change shields. set(shield_cli_argument ${cached_shield_value}) # Either new or old -if(shield_cli_argument STREQUAL CACHED_SHIELD) +if(shield_cli_argument STREQUAL ${IMAGE}CACHED_SHIELD) # We already have a CACHED_SHIELD so there is no new input on the CLI unset(shield_cli_argument) endif() -set(shield_app_cmake_lists ${SHIELD}) -if(cached_shield_value STREQUAL SHIELD) +set(shield_app_cmake_lists ${${IMAGE}SHIELD}) +if(cached_shield_value STREQUAL ${IMAGE}SHIELD) # The app build scripts did not set a default, The SHIELD we are # reading is the cached value from the CLI unset(shield_app_cmake_lists) endif() -if(CACHED_SHIELD) - # Warn the user if it looks like he is trying to change the shield +if(${IMAGE}CACHED_SHIELD) + # Warn the user if it looks like she is trying to change the shield # without cleaning first if(shield_cli_argument) - if(NOT (CACHED_SHIELD STREQUAL shield_cli_argument)) + if(NOT (${IMAGE}CACHED_SHIELD STREQUAL shield_cli_argument)) message(WARNING "The build directory must be cleaned pristinely when changing shields") # TODO: Support changing shields without requiring a clean build endif() endif() - set(SHIELD ${CACHED_SHIELD}) + set(${IMAGE}SHIELD ${${IMAGE}CACHED_SHIELD}) elseif(shield_cli_argument) - set(SHIELD ${shield_cli_argument}) + set(${IMAGE}SHIELD ${shield_cli_argument}) -elseif(DEFINED ENV{SHIELD}) - set(SHIELD $ENV{SHIELD}) +elseif(DEFINED ENV{${IMAGE}SHIELD}) + set(${IMAGE}SHIELD $ENV{${IMAGE}SHIELD}) elseif(shield_app_cmake_lists) - set(SHIELD ${shield_app_cmake_lists}) + set(${IMAGE}SHIELD ${shield_app_cmake_lists}) endif() # Store the selected shield in the cache -set(CACHED_SHIELD ${SHIELD} CACHE STRING "Selected shield") +set(${IMAGE}CACHED_SHIELD ${${IMAGE}SHIELD} CACHE STRING "Selected shield") -# 'BOARD_ROOT' is a prioritized list of directories where boards may -# be found. It always includes ${ZEPHYR_BASE} at the lowest priority. -list(APPEND BOARD_ROOT ${ZEPHYR_BASE}) - -if(NOT SOC_ROOT) - set(SOC_DIR ${ZEPHYR_BASE}/soc) -else() - set(SOC_DIR ${SOC_ROOT}/soc) -endif() - -if(NOT ARCH_ROOT) - set(ARCH_DIR ${ZEPHYR_BASE}/arch) -else() - set(ARCH_DIR ${ARCH_ROOT}/arch) -endif() - -# Use BOARD to search for a '_defconfig' file. +# Use ${IMAGE}BOARD to search for a '_defconfig' file. # e.g. zephyr/boards/arm/96b_carbon_nrf51/96b_carbon_nrf51_defconfig. # When found, use that path to infer the ARCH we are building for. foreach(root ${BOARD_ROOT}) # NB: find_path will return immediately if the output variable is - # already set - find_path(BOARD_DIR - NAMES ${BOARD}_defconfig + # already set this because it will set the output variable in the + # CACHE as well. + find_path(${IMAGE}BOARD_DIR + NAMES ${${IMAGE}BOARD}_defconfig PATHS ${root}/boards/*/* NO_DEFAULT_PATH ) - if(BOARD_DIR AND NOT (${root} STREQUAL ${ZEPHYR_BASE})) + + if(${IMAGE}BOARD_DIR AND NOT (${root} STREQUAL ${ZEPHYR_BASE})) set(USING_OUT_OF_TREE_BOARD 1) endif() set(shield_dir ${root}/boards/shields) - if(DEFINED SHIELD) - string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}") + if(DEFINED ${IMAGE}SHIELD) + string(REPLACE " " ";" SHIELD_AS_LIST "${${IMAGE}SHIELD}") endif() # Match the .overlay files in the shield directories to make sure we are # finding shields, e.g. x_nucleo_iks01a1/x_nucleo_iks01a1.overlay @@ -287,14 +324,18 @@ foreach(root ${BOARD_ROOT}) # x_nucleo_iks01a1/x_nucleo_iks01a1.overlay;x_nucleo_iks01a2/x_nucleo_iks01a2.overlay # we construct a list of shield names by extracting file name and # removing the extension. + unset(SHIELD_LIST) foreach(shield_path ${shields_refs_list}) get_filename_component(shield ${shield_path} NAME_WE) list(APPEND SHIELD_LIST ${shield}) endforeach() - if(DEFINED SHIELD) + unset(shield_dts_files) + unset(shield_dts_fixups) + unset(NOT_FOUND_SHIELD_LIST) + if(DEFINED ${IMAGE}SHIELD) foreach(s ${SHIELD_AS_LIST}) - list(REMOVE_ITEM SHIELD ${s}) + list(REMOVE_ITEM ${IMAGE}SHIELD ${s}) list(FIND SHIELD_LIST ${s} _idx) if (NOT _idx EQUAL -1) list(GET shields_refs_list ${_idx} s_path) @@ -360,53 +401,73 @@ foreach(root ${BOARD_ROOT}) endif() endforeach() endif() + + if(DEFINED ${IMAGE}SHIELD AND DEFINED NOT_FOUND_SHIELD_LIST) + foreach (s ${NOT_FOUND_SHIELD_LIST}) + message("No shield named '${s}' found") + endforeach() + print_usage() + unset(${IMAGE}CACHED_SHIELD CACHE) + message(FATAL_ERROR "Invalid usage") + endif() endforeach() -if(NOT BOARD_DIR) - message("No board named '${BOARD}' found") +if(NOT ${IMAGE}BOARD_DIR) + message("No board named '${${IMAGE}BOARD}' found") print_usage() - unset(CACHED_BOARD CACHE) + unset(${IMAGE}CACHED_BOARD CACHE) message(FATAL_ERROR "Invalid usage") endif() -if(DEFINED SHIELD AND DEFINED NOT_FOUND_SHIELD_LIST) - foreach (s ${NOT_FOUND_SHIELD_LIST}) - message("No shield named '${s}' found") - endforeach() - print_usage() - unset(CACHED_SHIELD CACHE) - message(FATAL_ERROR "Invalid usage") -endif() +get_filename_component(BOARD_ARCH_DIR ${${IMAGE}BOARD_DIR} DIRECTORY) +get_filename_component(BOARD_FAMILY ${${IMAGE}BOARD_DIR} NAME) -get_filename_component(BOARD_ARCH_DIR ${BOARD_DIR} DIRECTORY) -get_filename_component(BOARD_FAMILY ${BOARD_DIR} NAME) -get_filename_component(ARCH ${BOARD_ARCH_DIR} NAME) +get_filename_component(ARCH ${BOARD_ARCH_DIR} NAME) + +# DTS should be close to kconfig because CONFIG_ variables from +# kconfig and dts should be available at the same time. +# +# The DT system uses a C preprocessor for it's code generation needs. +# This creates an awkward chicken-and-egg problem, because we don't +# always know exactly which toolchain the user needs until we know +# more about the target, e.g. after DT and Kconfig. +# +# To resolve this we find "some" C toolchain, configure it generically +# with the minimal amount of configuration needed to have it +# preprocess DT sources, and then, after we have finished processing +# both DT and Kconfig we complete the target-specific configuration, +# and possibly change the toolchain. + +# Populate USER_CACHE_DIR with a directory that user applications may +# write cache files to. +include(${ZEPHYR_BASE}/cmake/generic_toolchain.cmake) -if(CONF_FILE) - # CONF_FILE has either been specified on the cmake CLI or is already - # in the CMakeCache.txt. This has precedence over the environment - # variable CONF_FILE and the default prj.conf -elseif(DEFINED ENV{CONF_FILE}) - set(CONF_FILE $ENV{CONF_FILE}) +if(${IMAGE}CONF_FILE) + # ${IMAGE}CONF_FILE has either been specified on the cmake CLI or is already + # in the CMakeCache.txt. This has precedence over the environment + # variable ${IMAGE}CONF_FILE and the default prj.conf +elseif(DEFINED ENV{${IMAGE}CONF_FILE}) + set(${IMAGE}CONF_FILE $ENV{${IMAGE}CONF_FILE}) elseif(COMMAND set_conf_file) message(WARNING "'set_conf_file' is deprecated, it will be removed in a future release.") set_conf_file() +elseif(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${${IMAGE}BOARD}.conf) + set(${IMAGE}CONF_FILE ${APPLICATION_SOURCE_DIR}/prj_${${IMAGE}BOARD}.conf) -elseif(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf) - set(CONF_FILE ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf) - -elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) - set(CONF_FILE ${APPLICATION_SOURCE_DIR}/prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) +elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${${IMAGE}BOARD}.conf) + set(${IMAGE}CONF_FILE ${APPLICATION_SOURCE_DIR}/prj.conf ${APPLICATION_SOURCE_DIR}/boards/${${IMAGE}BOARD}.conf) elseif(EXISTS ${APPLICATION_SOURCE_DIR}/prj.conf) - set(CONF_FILE ${APPLICATION_SOURCE_DIR}/prj.conf) + set(${IMAGE}CONF_FILE ${APPLICATION_SOURCE_DIR}/prj.conf) endif() -set(CONF_FILE ${CONF_FILE} CACHE STRING "If desired, you can build the application using\ +set(${IMAGE}CONF_FILE ${${IMAGE}CONF_FILE} CACHE STRING "If desired, you can build the application using\ the configuration settings specified in an alternate .conf file using this parameter. \ These settings will override the settings in the application’s .config file or its default .conf file.\ -Multiple files may be listed, e.g. CONF_FILE=\"prj1.conf prj2.conf\"") +Multiple files may be listed, e.g. CONF_FILE=\"prj1.conf prj2.conf\". \ +To specify an alternate .conf file for a specific image, prefix \"CONF_FILE\" \ +with the image name. For instance \"mcuboot_CONF_FILE\".") if(ZEPHYR_EXTRA_MODULES) # ZEPHYR_EXTRA_MODULES has either been specified on the cmake CLI or is @@ -416,47 +477,28 @@ elseif(DEFINED ENV{ZEPHYR_EXTRA_MODULES}) set(ZEPHYR_EXTRA_MODULES $ENV{ZEPHYR_EXTRA_MODULES}) endif() -if(DTC_OVERLAY_FILE) - # DTC_OVERLAY_FILE has either been specified on the cmake CLI or is already - # in the CMakeCache.txt. This has precedence over the environment - # variable DTC_OVERLAY_FILE -elseif(DEFINED ENV{DTC_OVERLAY_FILE}) - set(DTC_OVERLAY_FILE $ENV{DTC_OVERLAY_FILE}) -elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.overlay) - set(DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.overlay) -elseif(EXISTS ${APPLICATION_SOURCE_DIR}/${BOARD}.overlay) - set(DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/${BOARD}.overlay) +if(${IMAGE}DTC_OVERLAY_FILE) + # DTC_OVERLAY_FILE has either been specified on the cmake CLI or is + # already in the CMakeCache.txt. This has precedence over the + # environment variable DTC_OVERLAY_FILE +elseif(DEFINED ENV{${IMAGE}DTC_OVERLAY_FILE}) + set(${IMAGE}DTC_OVERLAY_FILE $ENV{${IMAGE}DTC_OVERLAY_FILE}) +elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${${IMAGE}BOARD}.overlay) + set(${IMAGE}DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/boards/${${IMAGE}BOARD}.overlay) +elseif(EXISTS ${APPLICATION_SOURCE_DIR}/${${IMAGE}BOARD}.overlay) + set(${IMAGE}DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/${${IMAGE}BOARD}.overlay) elseif(EXISTS ${APPLICATION_SOURCE_DIR}/app.overlay) - set(DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/app.overlay) + set(${IMAGE}DTC_OVERLAY_FILE ${APPLICATION_SOURCE_DIR}/app.overlay) endif() -set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} CACHE STRING "If desired, you can \ +set(${IMAGE}DTC_OVERLAY_FILE ${${IMAGE}DTC_OVERLAY_FILE} CACHE STRING "If desired, you can \ build the application using the DT configuration settings specified in an \ alternate .overlay file using this parameter. These settings will override the \ settings in the board's .dts file. Multiple files may be listed, e.g. \ -DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\"") - -# Prevent CMake from testing the toolchain -set(CMAKE_C_COMPILER_FORCED 1) -set(CMAKE_CXX_COMPILER_FORCED 1) - -include(${ZEPHYR_BASE}/cmake/host-tools.cmake) +DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\". To specify an alternate +.overlay file for a specific image, prefix \"DTC_OVERLAY_FILE\" with the image name. \ +For instance \"mcuboot_DTC_OVERLAY_FILE\".") -# DTS should be close to kconfig because CONFIG_ variables from -# kconfig and dts should be available at the same time. -# -# The DT system uses a C preprocessor for it's code generation needs. -# This creates an awkward chicken-and-egg problem, because we don't -# always know exactly which toolchain the user needs until we know -# more about the target, e.g. after DT and Kconfig. -# -# To resolve this we find "some" C toolchain, configure it generically -# with the minimal amount of configuration needed to have it -# preprocess DT sources, and then, after we have finished processing -# both DT and Kconfig we complete the target-specific configuration, -# and possibly change the toolchain. -include(${ZEPHYR_BASE}/cmake/zephyr_module.cmake) -include(${ZEPHYR_BASE}/cmake/generic_toolchain.cmake) include(${ZEPHYR_BASE}/cmake/dts.cmake) include(${ZEPHYR_BASE}/cmake/kconfig.cmake) @@ -493,44 +535,32 @@ set(KERNEL_EXE_NAME ${KERNEL_NAME}.exe) set(KERNEL_STAT_NAME ${KERNEL_NAME}.stat) set(KERNEL_STRIP_NAME ${KERNEL_NAME}.strip) -# Populate USER_CACHE_DIR with a directory that user applications may -# write cache files to. -if(NOT DEFINED USER_CACHE_DIR) - find_appropriate_cache_directory(USER_CACHE_DIR) -endif() -message(STATUS "Cache files will be written to: ${USER_CACHE_DIR}") +# ZEPHYR_TARGET is available for setting properties on that are +# "global" to the build (i.e. apply to targets from the Zephyr +# repository, modules, etc.). Use "TARGET ${ZEPHYR_TARGET}" instead of +# "GLOBAL" when defining or accessing such properties. +# +# (We create and use "target" rather than +# "logical_target_for_zephyr_elf" as the latter is not bound until +# fairly late in generation. The indirection through a variable lets +# us change the decision of what target to use easily without having +# to introduce wrappers around get_property() and set_property() in +# extensions.cmake.) +set(ZEPHYR_TARGET ${IMAGE}target) -include(${BOARD_DIR}/board.cmake OPTIONAL) +add_custom_target(${ZEPHYR_TARGET}) -# If we are using a suitable ethernet driver inside qemu, then these options -# must be set, otherwise a zephyr instance cannot receive any network packets. -# The Qemu supported ethernet driver should define CONFIG_ETH_NIC_MODEL -# string that tells what nic model Qemu should use. -if(CONFIG_QEMU_TARGET) - if(CONFIG_NET_QEMU_ETHERNET) - if(CONFIG_ETH_NIC_MODEL) - list(APPEND QEMU_FLAGS_${ARCH} - -nic tap,model=${CONFIG_ETH_NIC_MODEL},script=no,downscript=no,ifname=zeth - ) - else() - message(FATAL_ERROR " - No Qemu ethernet driver configured! - Enable Qemu supported ethernet driver like e1000 at drivers/ethernet" - ) - endif() - else() - list(APPEND QEMU_FLAGS_${ARCH} - -net none - ) - endif() -endif() +include(${BOARD_DIR}/board.cmake OPTIONAL) # "app" is a CMake library containing all the application code and is # modified by the entry point ${APPLICATION_SOURCE_DIR}/CMakeLists.txt # that was specified when cmake was called. zephyr_library_named(app) -set_property(TARGET app PROPERTY ARCHIVE_OUTPUT_DIRECTORY app) +set_property(TARGET ${IMAGE}app PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${IMAGE}app) + +include(${${IMAGE}BOARD_DIR}/board.cmake OPTIONAL) +# Add the main Zephyr build system file. add_subdirectory(${ZEPHYR_BASE} ${__build_dir}) # Link 'app' with the Zephyr interface libraries. @@ -540,17 +570,35 @@ add_subdirectory(${ZEPHYR_BASE} ${__build_dir}) # done after 'add_subdirectory(${ZEPHYR_BASE} ${__build_dir})' # because interface libraries are defined while processing that # subdirectory. -get_property(ZEPHYR_INTERFACE_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_INTERFACE_LIBS) +get_target_property(ZEPHYR_INTERFACE_LIBS_PROPERTY ${ZEPHYR_TARGET} ZEPHYR_INTERFACE_LIBS) foreach(boilerplate_lib ${ZEPHYR_INTERFACE_LIBS_PROPERTY}) # Linking 'app' with 'boilerplate_lib' causes 'app' to inherit the INTERFACE # properties of 'boilerplate_lib'. The most common property is 'include # directories', but it is also possible to have defines and compiler # flags in the interface of a library. - # - string(TOUPPER ${boilerplate_lib} boilerplate_lib_upper_case) # Support lowercase lib names + + # 'boilerplate_lib' is formatted as '0_mbedtls' (for instance). But + # the Kconfig options are formatted as + # 'CONFIG_APP_LINK_WITH_MBEDTLS'. So we need to strip the '0_' and + # convert to upper case. + + # Match the non-image'ified library name. E.g. '1_mylib' -> 'mylib'. + set(image_regex "^${IMAGE}(.*)") + string(REGEX MATCH + ${image_regex} + unused_out_var + ${boilerplate_lib} + ) + if(CMAKE_MATCH_1) + set(boilerplate_lib_without_image ${CMAKE_MATCH_1}) + else() + message(FATAL_ERROR "Internal error. Expected '${boilerplate_lib}' to match '${image_regex}'") + endif() + + string(TOUPPER ${boilerplate_lib_without_image} boilerplate_lib_upper_case) # Support lowercase lib names target_link_libraries_ifdef( CONFIG_APP_LINK_WITH_${boilerplate_lib_upper_case} - app + ${IMAGE}app PUBLIC ${boilerplate_lib} ) diff --git a/cmake/dts.cmake b/cmake/dts.cmake index 3c4919b98c0ac2..b56ed948503a9d 100644 --- a/cmake/dts.cmake +++ b/cmake/dts.cmake @@ -16,37 +16,37 @@ set(GENERATED_DTS_BOARD_UNFIXED_H ${PROJECT_BINARY_DIR}/include/generated/genera set(GENERATED_DTS_BOARD_CONF ${PROJECT_BINARY_DIR}/include/generated/generated_dts_board.conf) set(DTS_POST_CPP ${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.tmp) -set_ifndef(DTS_SOURCE ${BOARD_DIR}/${BOARD}.dts) -set_ifndef(DTS_COMMON_OVERLAYS ${ZEPHYR_BASE}/dts/common/common.dts) +set_ifndef(${IMAGE}DTS_SOURCE ${${IMAGE}BOARD_DIR}/${${IMAGE}BOARD}.dts) +set_ifndef(${IMAGE}DTS_COMMON_OVERLAYS ${ZEPHYR_BASE}/dts/common/common.dts) -# 'DTS_ROOT' is a list of directories where a directory tree with DT +# '${IMAGE}DTS_ROOT' is a list of directories where a directory tree with DT # files may be found. It always includes the application directory, # the board directory, and ${ZEPHYR_BASE}. list(APPEND - DTS_ROOT + ${IMAGE}DTS_ROOT ${APPLICATION_SOURCE_DIR} ${BOARD_DIR} ${ZEPHYR_BASE} ) set(dts_files - ${DTS_SOURCE} - ${DTS_COMMON_OVERLAYS} + ${${IMAGE}DTS_SOURCE} + ${${IMAGE}DTS_COMMON_OVERLAYS} ${shield_dts_files} ) # TODO: What to do about non-posix platforms where NOT CONFIG_HAS_DTS (xtensa)? # Drop support for NOT CONFIG_HAS_DTS perhaps? -if(EXISTS ${DTS_SOURCE}) +if(EXISTS ${${IMAGE}DTS_SOURCE}) set(SUPPORTS_DTS 1) else() set(SUPPORTS_DTS 0) endif() if(SUPPORTS_DTS) - if(DTC_OVERLAY_FILE) + if(${IMAGE}DTC_OVERLAY_FILE) # Convert from space-separated files into file list - string(REPLACE " " ";" DTC_OVERLAY_FILE_AS_LIST ${DTC_OVERLAY_FILE}) + string(REPLACE " " ";" DTC_OVERLAY_FILE_AS_LIST ${${IMAGE}DTC_OVERLAY_FILE}) list(APPEND dts_files ${DTC_OVERLAY_FILE_AS_LIST} @@ -74,7 +74,8 @@ if(SUPPORTS_DTS) math(EXPR i "${i}+1") endforeach() - foreach(dts_root ${DTS_ROOT}) + unset(DTS_ROOT_SYSTEM_INCLUDE_DIRS) + foreach(dts_root ${${IMAGE}DTS_ROOT}) foreach(dts_root_path include dts/common @@ -91,7 +92,8 @@ if(SUPPORTS_DTS) endforeach() endforeach() - foreach(dts_root ${DTS_ROOT}) + unset(DTS_ROOT_BINDINGS) + foreach(dts_root ${${IMAGE}DTS_ROOT}) set(full_path ${dts_root}/dts/bindings) if(EXISTS ${full_path}) list(APPEND @@ -120,7 +122,7 @@ if(SUPPORTS_DTS) -D__DTS__ -P -E ${ZEPHYR_BASE}/misc/empty_file.c - -o ${BOARD}.dts.pre.tmp + -o ${${IMAGE}BOARD}.dts.pre.tmp WORKING_DIRECTORY ${PROJECT_BINARY_DIR} RESULT_VARIABLE ret ) @@ -143,13 +145,13 @@ if(SUPPORTS_DTS) execute_process( COMMAND ${DTC} -O dts - -o ${BOARD}.dts_compiled + -o ${${IMAGE}BOARD}.dts_compiled -b 0 -E unit_address_vs_reg ${DTC_NO_WARN_UNIT_ADDR} ${DTC_WARN_UNIT_ADDR_IF_ENABLED} ${EXTRA_DTC_FLAGS} # User settable - ${BOARD}.dts.pre.tmp + ${${IMAGE}BOARD}.dts.pre.tmp WORKING_DIRECTORY ${PROJECT_BINARY_DIR} RESULT_VARIABLE ret ) @@ -162,7 +164,7 @@ if(SUPPORTS_DTS) # set(CMD_NEW_EXTRACT ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/dts/gen_defines.py - --dts ${BOARD}.dts.pre.tmp + --dts ${${IMAGE}BOARD}.dts.pre.tmp --bindings-dirs ${DTS_ROOT_BINDINGS} --conf-out ${GENERATED_DTS_BOARD_CONF} --header-out ${GENERATED_DTS_BOARD_UNFIXED_H} @@ -184,7 +186,7 @@ if(SUPPORTS_DTS) set(CMD_EXTRACT_DTS_INCLUDES ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/dts/extract_dts_includes.py --deprecated-only - --dts ${BOARD}.dts_compiled + --dts ${${IMAGE}BOARD}.dts_compiled --yaml ${DTS_ROOT_BINDINGS} --include ${GENERATED_DTS_BOARD_UNFIXED_H}.deprecated --old-alias-names diff --git a/cmake/emu/nsim.cmake b/cmake/emu/nsim.cmake index 2f6d2c7a3c046e..6fef083d3bf273 100644 --- a/cmake/emu/nsim.cmake +++ b/cmake/emu/nsim.cmake @@ -17,7 +17,7 @@ add_custom_target(run COMMAND ${NSIM} -propsfile - ${BOARD_DIR}/support/${NSIM_PROPS} + ${${IMAGE}BOARD_DIR}/support/${NSIM_PROPS} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME} DEPENDS ${logical_target_for_zephyr_elf} WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} @@ -28,7 +28,7 @@ add_custom_target(debugserver COMMAND ${NSIM} -propsfile - ${BOARD_DIR}/support/${NSIM_PROPS} + ${${IMAGE}BOARD_DIR}/support/${NSIM_PROPS} -gdb -port=3333 DEPENDS ${logical_target_for_zephyr_elf} WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} diff --git a/cmake/emu/qemu.cmake b/cmake/emu/qemu.cmake index b576a288fe4ce8..b68ca6be27a6ac 100644 --- a/cmake/emu/qemu.cmake +++ b/cmake/emu/qemu.cmake @@ -1,11 +1,37 @@ # SPDX-License-Identifier: Apache-2.0 -if("${ARCH}" STREQUAL "x86") - set_ifndef(QEMU_binary_suffix i386) +# If we are using a suitable ethernet driver inside qemu, then these options +# must be set, otherwise a zephyr instance cannot receive any network packets. +# The Qemu supported ethernet driver should define CONFIG_ETH_NIC_MODEL +# string that tells what nic model Qemu should use. +if(CONFIG_QEMU_TARGET) + if(CONFIG_NET_QEMU_ETHERNET) + if(CONFIG_ETH_NIC_MODEL) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY QEMU_FLAGS_${ARCH} + -nic tap,model=${CONFIG_ETH_NIC_MODEL},script=no,downscript=no,ifname=zeth + ) + else() + message(FATAL_ERROR " + No Qemu ethernet driver configured! + Enable Qemu supported ethernet driver like e1000 at drivers/ethernet" + ) + endif() + else() + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY QEMU_FLAGS_${ARCH} + -net none + ) + endif() +endif() + +get_target_property(QEMU_binary_suffix ${ZEPHYR_TARGET} QEMU_binary_suffix) +if(QEMU_binary_suffix) + # Do nothing +elseif("${ARCH}" STREQUAL "x86") + set(QEMU_binary_suffix i386) elseif(DEFINED QEMU_ARCH) - set_ifndef(QEMU_binary_suffix ${QEMU_ARCH}) + set(QEMU_binary_suffix ${QEMU_ARCH}) else() - set_ifndef(QEMU_binary_suffix ${ARCH}) + set(QEMU_binary_suffix ${ARCH}) endif() set(qemu_alternate_path $ENV{QEMU_BIN_PATH}) @@ -276,13 +302,15 @@ elseif(NOT DEFINED QEMU_KERNEL_OPTION) set(QEMU_KERNEL_OPTION "-kernel;$") endif() +get_target_property(qemu_flags_arch ${ZEPHYR_TARGET} QEMU_FLAGS_${ARCH}) +get_target_property(qemu_cpu_type_arch ${ZEPHYR_TARGET} QEMU_CPU_TYPE_${ARCH}) foreach(target ${qemu_targets}) add_custom_target(${target} ${PRE_QEMU_COMMANDS} ${PRE_QEMU_COMMANDS_FOR_${target}} COMMAND ${QEMU} - ${QEMU_FLAGS_${ARCH}} + ${qemu_flags_arch} ${QEMU_FLAGS} ${QEMU_EXTRA_FLAGS} ${MORE_FLAGS_FOR_${target}} @@ -290,7 +318,7 @@ foreach(target ${qemu_targets}) ${QEMU_KERNEL_OPTION} DEPENDS ${logical_target_for_zephyr_elf} WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} - COMMENT "${QEMU_PIPE_COMMENT}[QEMU] CPU: ${QEMU_CPU_TYPE_${ARCH}}" + COMMENT "${QEMU_PIPE_COMMENT}[QEMU] CPU: ${qemu_cpu_type_arch}" USES_TERMINAL ) if(DEFINED QEMU_KERNEL_FILE) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index cbb640ca15841e..dac0a614385061 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -68,7 +68,7 @@ function(zephyr_sources) if(IS_DIRECTORY ${arg}) message(FATAL_ERROR "zephyr_sources() was called on a directory") endif() - target_sources(zephyr PRIVATE ${arg}) + target_sources(${IMAGE}zephyr PRIVATE ${arg}) endforeach() endfunction() @@ -80,7 +80,7 @@ function(zephyr_include_directories) else() set(path ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) endif() - target_include_directories(zephyr_interface INTERFACE ${path}) + target_include_directories(${IMAGE}zephyr_interface INTERFACE ${path}) endforeach() endfunction() @@ -92,42 +92,95 @@ function(zephyr_system_include_directories) else() set(path ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) endif() - target_include_directories(zephyr_interface SYSTEM INTERFACE ${path}) + target_include_directories(${IMAGE}zephyr_interface SYSTEM INTERFACE ${path}) endforeach() endfunction() # https://cmake.org/cmake/help/latest/command/target_compile_definitions.html function(zephyr_compile_definitions) - target_compile_definitions(zephyr_interface INTERFACE ${ARGV}) + target_compile_definitions(${IMAGE}zephyr_interface INTERFACE ${ARGV}) endfunction() # https://cmake.org/cmake/help/latest/command/target_compile_options.html function(zephyr_compile_options) - target_compile_options(zephyr_interface INTERFACE ${ARGV}) + target_compile_options(${IMAGE}zephyr_interface INTERFACE ${ARGV}) endfunction() # https://cmake.org/cmake/help/latest/command/target_link_libraries.html function(zephyr_link_libraries) - target_link_libraries(zephyr_interface INTERFACE ${ARGV}) + target_link_libraries(${IMAGE}zephyr_interface INTERFACE ${ARGV}) endfunction() # See this file section 3.1. target_cc_option function(zephyr_cc_option) foreach(arg ${ARGV}) - target_cc_option(zephyr_interface INTERFACE ${arg}) + target_cc_option(${IMAGE}zephyr_interface INTERFACE ${arg}) endforeach() endfunction() +# Add a new image which is built with a new configuration. Examples of +# use include asymmetric multi-processing, bootloaders, and +# secure/non-secure partitions in a TrustZone environment. For more +# documentation see "Building and Configuring multiple images" from +# "Application Development". +# +# The argument 'name' is an input parameter and denotes the image name. +# +# The argument 'build_image' is an output parameter and is set to '1' +# when the image should be built. +function(zephyr_add_image name build_image) + set(${build_image} 0 PARENT_SCOPE) + string(TOUPPER ${name} UPNAME) + + # Make sure we haven't already added this image, adding the same + # image twice is a mistake and is not supported. + get_property( + IMAGES + GLOBAL PROPERTY + IMAGES + ) + list(FIND IMAGES ${name}_ out_var) # 'out_var' is '-1' if not found + if(NOT (${out_var} EQUAL -1)) + message(FATAL_ERROR "zephyr_add_image() was invoked twice with the parameter 'name='${name}''") + endif() + + # Maintain a global list of images as property, and a mirror in the cache. + set_property(GLOBAL APPEND PROPERTY IMAGES ${name}_) + get_property(IMAGES GLOBAL PROPERTY IMAGES) + list(APPEND IMAGE_LIST ${name}) + set(ZEPHYR_IMAGES ${IMAGE_LIST} CACHE STRING "List of zephyr image names" FORCE) + + if (CONFIG_${UPNAME}_BUILD_STRATEGY_SKIP_BUILD) + message("Skipping building of ${name}") + set(${name}_ZEPHYR_BUILD_STRATEGY SKIP_BUILD CACHE STRING + "Build strategy for image ${name}" FORCE) + else() + # Build normally. + + # Set the active IMAGE + set_property(GLOBAL PROPERTY IMAGE ${name}_) + + # Signal that the image should be built by setting build_image + set(${build_image} 1 PARENT_SCOPE) + + # Cache the build strategy. + set(${name}_ZEPHYR_BUILD_STRATEGY DEFAULT CACHE STRING + "Build strategy for image ${name}" FORCE) + endif() + +endfunction() + + function(zephyr_cc_option_fallback option1 option2) - target_cc_option_fallback(zephyr_interface INTERFACE ${option1} ${option2}) + target_cc_option_fallback(${IMAGE}zephyr_interface INTERFACE ${option1} ${option2}) endfunction() function(zephyr_ld_options) - target_ld_options(zephyr_interface INTERFACE ${ARGV}) + target_ld_options(${IMAGE}zephyr_interface INTERFACE ${ARGV}) endfunction() # Getter functions for extracting build information from -# zephyr_interface. Returning lists, and strings is supported, as is +# ${IMAGE}zephyr_interface. Returning lists, and strings is supported, as is # requesting specific categories of build information (defines, # includes, options). # @@ -195,7 +248,7 @@ function(zephyr_get_compile_options_for_lang_as_string lang i) endfunction() function(zephyr_get_include_directories_for_lang lang i) - get_property_and_add_prefix(flags zephyr_interface INTERFACE_INCLUDE_DIRECTORIES + get_property_and_add_prefix(flags ${IMAGE}zephyr_interface INTERFACE_INCLUDE_DIRECTORIES "-I" ${ARGN} ) @@ -206,7 +259,7 @@ function(zephyr_get_include_directories_for_lang lang i) endfunction() function(zephyr_get_system_include_directories_for_lang lang i) - get_property_and_add_prefix(flags zephyr_interface INTERFACE_SYSTEM_INCLUDE_DIRECTORIES + get_property_and_add_prefix(flags ${IMAGE}zephyr_interface INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "-isystem" ${ARGN} ) @@ -217,7 +270,7 @@ function(zephyr_get_system_include_directories_for_lang lang i) endfunction() function(zephyr_get_compile_definitions_for_lang lang i) - get_property_and_add_prefix(flags zephyr_interface INTERFACE_COMPILE_DEFINITIONS + get_property_and_add_prefix(flags ${IMAGE}zephyr_interface INTERFACE_COMPILE_DEFINITIONS "-D" ${ARGN} ) @@ -228,7 +281,7 @@ function(zephyr_get_compile_definitions_for_lang lang i) endfunction() function(zephyr_get_compile_options_for_lang lang i) - get_property(flags TARGET zephyr_interface PROPERTY INTERFACE_COMPILE_OPTIONS) + get_property(flags TARGET ${IMAGE}zephyr_interface PROPERTY INTERFACE_COMPILE_OPTIONS) process_flags(${lang} flags output_list) @@ -367,17 +420,17 @@ endmacro() macro(zephyr_library_named name) # This is a macro because we need add_library() to be executed # within the scope of the caller. - set(ZEPHYR_CURRENT_LIBRARY ${name}) - add_library(${name} STATIC "") + set(ZEPHYR_CURRENT_LIBRARY ${IMAGE}${name}) + add_library(${ZEPHYR_CURRENT_LIBRARY} STATIC "") - zephyr_append_cmake_library(${name}) + zephyr_append_cmake_library(${ZEPHYR_CURRENT_LIBRARY}) - target_link_libraries(${name} PUBLIC zephyr_interface) + target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PUBLIC ${IMAGE}zephyr_interface) endmacro() function(zephyr_link_interface interface) - target_link_libraries(${interface} INTERFACE zephyr_interface) + target_link_libraries(${interface} INTERFACE ${IMAGE}zephyr_interface) endfunction() # @@ -407,8 +460,8 @@ function(zephyr_library_compile_options item) # library and link with it to obtain the flags. # # Linking with a dummy interface library will place flags later on - # the command line than the the flags from zephyr_interface because - # zephyr_interface will be the first interface library that flags + # the command line than the the flags from ${IMAGE}zephyr_interface because + # ${IMAGE}zephyr_interface will be the first interface library that flags # are taken from. string(MD5 uniqueness ${item}) @@ -441,7 +494,7 @@ endfunction() # constructor but must called explicitly on CMake libraries that do # not use a zephyr library constructor. function(zephyr_append_cmake_library library) - set_property(GLOBAL APPEND PROPERTY ZEPHYR_LIBS ${library}) + set_property(TARGET "${ZEPHYR_TARGET}" APPEND PROPERTY ZEPHYR_LIBS ${library}) endfunction() # Add the imported library 'library_name', located at 'library_path' to the @@ -481,8 +534,8 @@ endfunction() # This API has a constructor like the zephyr_library API has, but it # does not have wrappers over the other cmake target functions. macro(zephyr_interface_library_named name) - add_library(${name} INTERFACE) - set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS ${name}) + add_library(${IMAGE}${name} INTERFACE) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY ZEPHYR_INTERFACE_LIBS ${IMAGE}${name}) endmacro() # 1.3 generate_inc_* @@ -574,10 +627,10 @@ endfunction() # runner. function(board_set_runner type runner) _board_check_runner_type(${type}) - if (DEFINED BOARD_${type}_RUNNER) - message(STATUS "overriding ${type} runner ${BOARD_${type}_RUNNER}; it's now ${runner}") + if (DEFINED ${IMAGE}BOARD_${type}_RUNNER) + message(STATUS "overriding ${type} runner ${${IMAGE}BOARD_${type}_RUNNER}; it's now ${runner}") endif() - set(BOARD_${type}_RUNNER ${runner} PARENT_SCOPE) + set(${IMAGE}BOARD_${type}_RUNNER ${runner} PARENT_SCOPE) endfunction() # This macro is like board_set_runner(), but will only make a change @@ -589,7 +642,7 @@ macro(board_set_runner_ifnset type runner) # This is a macro because set_ifndef() works at parent scope. # If this were a function, that would be this function's scope, # which wouldn't work. - set_ifndef(BOARD_${type}_RUNNER ${runner}) + set_ifndef(${IMAGE}BOARD_${type}_RUNNER ${runner}) endmacro() # A convenience macro for board_set_runner(FLASH ${runner}). @@ -637,7 +690,7 @@ endmacro() function(board_runner_args runner) string(MAKE_C_IDENTIFIER ${runner} runner_id) # Note the "_EXPLICIT_" here, and see below. - set_property(GLOBAL APPEND PROPERTY BOARD_RUNNER_ARGS_EXPLICIT_${runner_id} ${ARGN}) + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY BOARD_RUNNER_ARGS_EXPLICIT_${runner_id} ${ARGN}) endfunction() # This function is intended for internal use by @@ -666,10 +719,10 @@ function(board_finalize_runner_args runner) # Retrieve the list of explicitly set arguments. string(MAKE_C_IDENTIFIER ${runner} runner_id) - get_property(explicit GLOBAL PROPERTY "BOARD_RUNNER_ARGS_EXPLICIT_${runner_id}") + get_target_property(explicit "${ZEPHYR_TARGET}" "BOARD_RUNNER_ARGS_EXPLICIT_${runner_id}") # Note no _EXPLICIT_ here. This property contains the final list. - set_property(GLOBAL APPEND PROPERTY BOARD_RUNNER_ARGS_${runner_id} + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY BOARD_RUNNER_ARGS_${runner_id} # Default arguments from the common runner file come first. ${ARGN} # Arguments explicitly given with board_runner_args() come @@ -677,8 +730,8 @@ function(board_finalize_runner_args runner) ${explicit} ) - # Add the finalized runner to the global property list. - set_property(GLOBAL APPEND PROPERTY ZEPHYR_RUNNERS ${runner}) + # Add the finalized runner to the list in the ZEPHYR_RUNNERS property. + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY ZEPHYR_RUNNERS ${runner}) endfunction() # 1.5. Misc. @@ -841,8 +894,9 @@ endfunction() # Friendly reminder: Beware of the different ways the location counter ('.') # behaves inside vs. outside section definitions. function(zephyr_linker_sources location) - # Set up the paths to the destination files. These files are #included inside - # the global linker.ld. + # Set up the paths to the destination files. These files are + # #included inside the global linker.ld. Keep these settings in sync + # with zephyr_init_linker_sources(). set(snippet_base "${__build_dir}/include/generated") set(sections_path "${snippet_base}/snippets-sections.ld") set(ram_sections_path "${snippet_base}/snippets-ram-sections.ld") @@ -850,17 +904,6 @@ function(zephyr_linker_sources location) set(rwdata_path "${snippet_base}/snippets-rwdata.ld") set(rodata_path "${snippet_base}/snippets-rodata.ld") - # Clear destination files if this is the first time the function is called. - get_property(cleared GLOBAL PROPERTY snippet_files_cleared) - if (NOT DEFINED cleared) - file(WRITE ${sections_path} "") - file(WRITE ${ram_sections_path} "") - file(WRITE ${noinit_path} "") - file(WRITE ${rwdata_path} "") - file(WRITE ${rodata_path} "") - set_property(GLOBAL PROPERTY snippet_files_cleared true) - endif() - # Choose destination file, based on the argument. if ("${location}" STREQUAL "SECTIONS") set(snippet_path "${sections_path}") @@ -896,11 +939,26 @@ function(zephyr_linker_sources location) endforeach() endfunction(zephyr_linker_sources) +# Private helper to initialize zephyr_linker_sources() +function(zephyr_init_linker_sources) + set(snippet_base "${__build_dir}/include/generated") + set(sections_path "${snippet_base}/snippets-sections.ld") + set(ram_sections_path "${snippet_base}/snippets-ram-sections.ld") + set(noinit_path "${snippet_base}/snippets-noinit.ld") + set(rwdata_path "${snippet_base}/snippets-rwdata.ld") + set(rodata_path "${snippet_base}/snippets-rodata.ld") + + file(WRITE ${sections_path} "") + file(WRITE ${ram_sections_path} "") + file(WRITE ${noinit_path} "") + file(WRITE ${rwdata_path} "") + file(WRITE ${rodata_path} "") +endfunction() # Helper function for CONFIG_CODE_DATA_RELOCATION # Call this function with 2 arguments file and then memory location function(zephyr_code_relocate file location) - set_property(TARGET code_data_relocation_target + set_property(TARGET ${IMAGE}code_data_relocation_target APPEND PROPERTY COMPILE_DEFINITIONS "${location}:${CMAKE_CURRENT_SOURCE_DIR}/${file}") endfunction() @@ -1168,7 +1226,7 @@ endfunction() function(zephyr_link_interface_ifdef feature_toggle interface) if(${${feature_toggle}}) - target_link_libraries(${interface} INTERFACE zephyr_interface) + target_link_libraries(${interface} INTERFACE ${IMAGE}zephyr_interface) endif() endfunction() diff --git a/cmake/flash/CMakeLists.txt b/cmake/flash/CMakeLists.txt index 05edc8ddf826b2..a5859d5a82f0e8 100644 --- a/cmake/flash/CMakeLists.txt +++ b/cmake/flash/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -get_property(RUNNERS GLOBAL PROPERTY ZEPHYR_RUNNERS) +get_target_property(RUNNERS ${ZEPHYR_TARGET} ZEPHYR_RUNNERS) # Enable verbose output, if requested. if(CMAKE_VERBOSE_MAKEFILE) @@ -17,39 +17,41 @@ endif() # Everything is marked with FORCE so that re-running CMake updates the # configuration if the board files change. if(RUNNERS) - set(ZEPHYR_RUNNERS ${RUNNERS} CACHE INTERNAL "Available runners") + set(${IMAGE}ZEPHYR_RUNNERS ${RUNNERS} CACHE INTERNAL "Runners available for image") # Runner configuration. This is provided to all runners, and is # distinct from the free-form arguments provided by e.g. # board_runner_args(). # # Always applicable: - set(ZEPHYR_RUNNER_CONFIG_BOARD_DIR "${BOARD_DIR}" + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_BOARD_DIR "${${IMAGE}BOARD_DIR}" CACHE STRING "Board definition directory" FORCE) - set(ZEPHYR_RUNNER_CONFIG_KERNEL_ELF "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}" + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_KERNEL_ELF "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}" CACHE STRING "Path to kernel image in ELF format" FORCE) - get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) + + get_target_property(HEX_FILES_TO_MERGE ${ZEPHYR_TARGET} HEX_FILES_TO_MERGE) if(HEX_FILES_TO_MERGE) - set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${MERGED_HEX_NAME}" + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${MERGED_HEX_NAME}" CACHE STRING "Path to merged image in Intel Hex format" FORCE) else() - set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}" - CACHE STRING "Path to kernel image in Intel Hex format" FORCE) + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}" + CACHE STRING "Path to merged image in Intel Hex format" FORCE) endif() - set(ZEPHYR_RUNNER_CONFIG_KERNEL_BIN "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}" + + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_KERNEL_BIN "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}" CACHE STRING "Path to kernel image as raw binary" FORCE) # Not always applicable, but so often needed that they're provided # by default: (TODO: clean this up) if(DEFINED CMAKE_GDB) - set(ZEPHYR_RUNNER_CONFIG_GDB "${CMAKE_GDB}" + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_GDB "${CMAKE_GDB}" CACHE STRING "Path to GDB binary, if applicable" FORCE) endif() - if(DEFINED OPENOCD) - set(ZEPHYR_RUNNER_CONFIG_OPENOCD "${OPENOCD}" + if(DEFINED ${IMAGE}OPENOCD) + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_OPENOCD "${OPENOCD}" CACHE STRING "Path to openocd binary, if applicable" FORCE) endif() - if(DEFINED OPENOCD_DEFAULT_PATH) - set(ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH "${OPENOCD_DEFAULT_PATH}" + if(DEFINED ${IMAGE}OPENOCD_DEFAULT_PATH) + set(${IMAGE}ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH "${OPENOCD_DEFAULT_PATH}" CACHE STRING "Path to add to openocd search path, if applicable" FORCE) endif() @@ -58,17 +60,17 @@ if(RUNNERS) foreach(runner ${RUNNERS}) string(MAKE_C_IDENTIFIER ${runner} runner_id) # E.g. args = BOARD_RUNNER_ARGS_openocd, BOARD_RUNNER_ARGS_dfu_util, etc. - get_property(runner_args GLOBAL PROPERTY "BOARD_RUNNER_ARGS_${runner_id}") - set(ZEPHYR_RUNNER_ARGS_${runner_id} ${runner_args} CACHE STRING + get_target_property(runner_args ${ZEPHYR_TARGET} "BOARD_RUNNER_ARGS_${runner_id}") + set(${IMAGE}ZEPHYR_RUNNER_ARGS_${runner_id} ${runner_args} CACHE STRING "Runner-specific arguments for ${runner}" FORCE) endforeach() endif() -if(BOARD_FLASH_RUNNER) - set(ZEPHYR_BOARD_FLASH_RUNNER ${BOARD_FLASH_RUNNER} CACHE STRING +if(${IMAGE}BOARD_FLASH_RUNNER) + set(${IMAGE}ZEPHYR_BOARD_FLASH_RUNNER ${${IMAGE}BOARD_FLASH_RUNNER} CACHE STRING "Default runner for flashing binaries" FORCE) endif() -if(BOARD_DEBUG_RUNNER) - set(ZEPHYR_BOARD_DEBUG_RUNNER ${BOARD_DEBUG_RUNNER} CACHE STRING +if(${IMAGE}BOARD_DEBUG_RUNNER) + set(${IMAGE}ZEPHYR_BOARD_DEBUG_RUNNER ${${IMAGE}BOARD_DEBUG_RUNNER} CACHE STRING "Default runner for debugging" FORCE) endif() @@ -95,22 +97,26 @@ endif(WEST) foreach(target flash debug debugserver attach) if(target STREQUAL flash) - set(comment "Flashing ${BOARD}") + set(comment "Flashing ${${IMAGE}BOARD}") elseif(target STREQUAL debug) - set(comment "Debugging ${BOARD}") + set(comment "Debugging ${${IMAGE}BOARD}") elseif(target STREQUAL debugserver) - set(comment "Debugging ${BOARD}") + set(comment "Debugging ${${IMAGE}BOARD}") if(EMU_PLATFORM) # cmake/qemu/CMakeLists.txt will add a debugserver target for # emulation platforms, so we don't add one here continue() endif() elseif(target STREQUAL attach) - set(comment "Debugging ${BOARD}") + set(comment "Debugging ${${IMAGE}BOARD}") endif() list(APPEND FLASH_DEPS ${logical_target_for_zephyr_elf}) + if(DEFINED IMAGE) + set(FLASH_IMAGE_ARG --image ${IMAGE}) + endif() + # We pass --skip-rebuild here because the DEPENDS value ensures the # build is already up to date before west is run. if(WEST_FLASH) @@ -120,11 +126,12 @@ foreach(target flash debug debugserver attach) ${RUNNER_VERBOSE} ${target} --skip-rebuild + ${FLASH_IMAGE_ARG} DEPENDS ${FLASH_DEPS} - WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) - add_custom_target(${target} + add_custom_target(${IMAGE}${target} COMMAND ${cmd} COMMENT @@ -132,14 +139,14 @@ foreach(target flash debug debugserver attach) USES_TERMINAL ) elseif(WEST) - add_custom_target(${target} + add_custom_target(${IMAGE}${target} COMMAND ${CMAKE_COMMAND} -E echo \"West version found in path does not support '${CMAKE_MAKE_PROGRAM} ${target}', ensure west is installed and not only the bootstrapper. run 'west init' to fetch west.\" USES_TERMINAL ) else() - add_custom_target(${target} + add_custom_target(${IMAGE}${target} COMMAND ${CMAKE_COMMAND} -E echo \"West was not found in path. To support '${CMAKE_MAKE_PROGRAM} ${target}', please install west bootstrapper with: 'pip install west --user', and thereafter 'west init'.\" diff --git a/cmake/generic_toolchain.cmake b/cmake/generic_toolchain.cmake index c579ea76dc1299..703aa80f054a06 100644 --- a/cmake/generic_toolchain.cmake +++ b/cmake/generic_toolchain.cmake @@ -60,6 +60,10 @@ if(${ARCH} STREQUAL "posix") endif() endif() +# Clear variables that should only be set by the toolchain and/or compiler +unset(LIB_INCLUDE_DIR) +unset(TOOLCHAIN_LIBS) + # Configure the toolchain based on what SDK/toolchain is in use. include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/generic.cmake) diff --git a/cmake/ide/eclipse_cdt4_generator_amendment.cmake b/cmake/ide/eclipse_cdt4_generator_amendment.cmake index 1bad729118e377..9179e4e4b77ab8 100644 --- a/cmake/ide/eclipse_cdt4_generator_amendment.cmake +++ b/cmake/ide/eclipse_cdt4_generator_amendment.cmake @@ -92,8 +92,8 @@ set(OUTPUT_FILE ${CMAKE_BINARY_DIR}/zephyr/include/generated/cmake_intdef.h) file(WRITE ${OUTPUT_FILE} "/* Generated by eclipse_cd4_generator_amendment.cmake */\n") file(APPEND ${OUTPUT_FILE} "/* The header contains the defines collected from the */\n") file(APPEND ${OUTPUT_FILE} "/* INTERFACE_COMPILE_DEFINITIONS target property */\n") -file(APPEND ${OUTPUT_FILE} "/* corresponding to zephyr_interface */\n") -get_target_property(_int_comp_def zephyr_interface INTERFACE_COMPILE_DEFINITIONS) +file(APPEND ${OUTPUT_FILE} "/* corresponding to ${IMAGE}zephyr_interface */\n") +get_target_property(_int_comp_def ${IMAGE}zephyr_interface INTERFACE_COMPILE_DEFINITIONS) foreach( d ${_int_comp_def} ) string(REGEX MATCH "([A-Za-z_][A-Za-z0-9_]*) *=* *(.*) *$" _dummy "${d}") file(APPEND ${OUTPUT_FILE} "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}\n") diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index 22a09a73590c81..1b8a550ad4a3c4 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -5,21 +5,22 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/generated) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config) -if(KCONFIG_ROOT) +if(${IMAGE}KCONFIG_ROOT) # KCONFIG_ROOT has either been specified as a CMake variable or is # already in the CMakeCache.txt. This has precedence. + set(KCONFIG_ROOT ${${IMAGE}KCONFIG_ROOT}) elseif(EXISTS ${APPLICATION_SOURCE_DIR}/Kconfig) set(KCONFIG_ROOT ${APPLICATION_SOURCE_DIR}/Kconfig) else() set(KCONFIG_ROOT ${ZEPHYR_BASE}/Kconfig) endif() -set(BOARD_DEFCONFIG ${BOARD_DIR}/${BOARD}_defconfig) +set(BOARD_DEFCONFIG ${${IMAGE}BOARD_DIR}/${${IMAGE}BOARD}_defconfig) set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config) set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt) -if(CONF_FILE) -string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE}") +if(${IMAGE}CONF_FILE) +string(REPLACE " " ";" ${IMAGE}CONF_FILE_AS_LIST "${${IMAGE}CONF_FILE}") endif() if(OVERLAY_CONFIG) @@ -40,7 +41,7 @@ set(ENV{PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}) # Set environment variables so that Kconfig can prune Kconfig source # files for other architectures set(ENV{ARCH} ${ARCH}) -set(ENV{BOARD_DIR} ${BOARD_DIR}) +set(ENV{BOARD_DIR} ${${IMAGE}BOARD_DIR}) set(ENV{SOC_DIR} ${SOC_DIR}) set(ENV{CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}) set(ENV{ARCH_DIR} ${ARCH_DIR}) @@ -71,7 +72,7 @@ foreach(kconfig_target ${EXTRA_KCONFIG_TARGETS} ) add_custom_target( - ${kconfig_target} + ${IMAGE}${kconfig_target} ${CMAKE_COMMAND} -E env PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} srctree=${ZEPHYR_BASE} @@ -126,7 +127,7 @@ list(SORT config_files) set( merge_config_files ${BOARD_DEFCONFIG} - ${CONF_FILE_AS_LIST} + ${${IMAGE}CONF_FILE_AS_LIST} ${shield_conf_files} ${OVERLAY_CONFIG_AS_LIST} ${EXTRA_KCONFIG_OPTIONS_FILE} @@ -203,7 +204,7 @@ execute_process( ${merge_fragments} WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR} # The working directory is set to the app dir such that the user - # can use relative paths in CONF_FILE, e.g. CONF_FILE=nrf5.conf + # can use relative paths in ${IMAGE}CONF_FILE, e.g. CONF_FILE=nrf5.conf RESULT_VARIABLE ret ) if(NOT "${ret}" STREQUAL "0") @@ -222,7 +223,7 @@ foreach(kconfig_input set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig_input}) endforeach() -add_custom_target(config-sanitycheck DEPENDS ${DOTCONFIG}) +add_custom_target(${IMAGE}config-sanitycheck DEPENDS ${DOTCONFIG}) # Remove the CLI Kconfig symbols from the namespace and # CMakeCache.txt. If the symbols end up in DOTCONFIG they will be diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index d3f63e474af763..5e6f04c44ac5c6 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -27,8 +27,8 @@ macro(configure_linker_script linker_script_gen linker_pass_define) endif() zephyr_get_include_directories_for_lang(C current_includes) - get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME) - get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES) + file(RELATIVE_PATH base_name ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + get_target_property(current_defines ${ZEPHYR_TARGET} PROPERTY_LINKER_SCRIPT_DEFINES) add_custom_command( OUTPUT ${linker_script_gen} @@ -90,7 +90,7 @@ function(toolchain_ld_link_elf) ${LINKERFLAGPREFIX},--whole-archive ${ZEPHYR_LIBS_PROPERTY} ${LINKERFLAGPREFIX},--no-whole-archive - kernel + ${KERNEL_LIBRARY} $ ${LIB_INCLUDE_DIR} -L${PROJECT_BINARY_DIR} diff --git a/cmake/linker/ld/target_base.cmake b/cmake/linker/ld/target_base.cmake index a96c6d637c989f..9d3ce31f824559 100644 --- a/cmake/linker/ld/target_base.cmake +++ b/cmake/linker/ld/target_base.cmake @@ -4,8 +4,8 @@ macro(toolchain_ld_base) - if(NOT PROPERTY_LINKER_SCRIPT_DEFINES) - set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) + if(NOT ${IMAGE}PROPERTY_LINKER_SCRIPT_DEFINES) + set_target_properties(${ZEPHYR_TARGET} PROPERTIES PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) endif() # TOOLCHAIN_LD_FLAGS comes from compiler/gcc/target.cmake diff --git a/cmake/linker/ld/target_relocation.cmake b/cmake/linker/ld/target_relocation.cmake index 076209a3ab26fb..e6093402f72bb0 100644 --- a/cmake/linker/ld/target_relocation.cmake +++ b/cmake/linker/ld/target_relocation.cmake @@ -17,14 +17,14 @@ macro(toolchain_ld_relocation) ${ZEPHYR_BASE}/scripts/gen_relocate_app.py $<$:--verbose> -d ${APPLICATION_BINARY_DIR} - -i '$' + -i '$' -o ${MEM_RELOCATION_LD} -s ${MEM_RELOCATION_SRAM_DATA_LD} -b ${MEM_RELOCATION_SRAM_BSS_LD} -c ${MEM_RELOCATION_CODE} - DEPENDS app kernel ${ZEPHYR_LIBS_PROPERTY} + DEPENDS ${KERNEL_LIBRARY} ${ZEPHYR_LIBS_PROPERTY} ) - add_library(code_relocation_source_lib STATIC ${MEM_RELOCATION_CODE}) - target_link_libraries(code_relocation_source_lib zephyr_interface) + add_library(${IMAGE}code_relocation_source_lib STATIC ${MEM_RELOCATION_CODE}) + target_link_libraries(${IMAGE}code_relocation_source_lib ${IMAGE}zephyr_interface) endmacro() diff --git a/cmake/reports/CMakeLists.txt b/cmake/reports/CMakeLists.txt index 7c2140dc828fa5..8adedcd401de89 100644 --- a/cmake/reports/CMakeLists.txt +++ b/cmake/reports/CMakeLists.txt @@ -5,7 +5,7 @@ set(flag_for_rom_report -F) foreach(report ram_report rom_report) add_custom_target( - ${report} + ${IMAGE}${report} ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/footprint/size_report ${flag_for_${report}} diff --git a/cmake/target_toolchain.cmake b/cmake/target_toolchain.cmake index a117538d608070..2378ac947a6375 100644 --- a/cmake/target_toolchain.cmake +++ b/cmake/target_toolchain.cmake @@ -38,9 +38,12 @@ endif() # The 'generic' compiler and the 'target' compiler might be different, # so we unset the 'generic' one and thereby force the 'target' to -# re-set it. -unset(CMAKE_C_COMPILER) -unset(CMAKE_C_COMPILER CACHE) +# re-set it. This is only needed for the first boilerplate execution as +# the remaining boilerplate executions will use the same C compiler. +if (FIRST_BOILERPLATE_EXECUTION) + unset(CMAKE_C_COMPILER) + unset(CMAKE_C_COMPILER CACHE) +endif() # A toolchain consist of a compiler and a linker. # In Zephyr, toolchains require a port under cmake/toolchain/. diff --git a/cmake/usage/CMakeLists.txt b/cmake/usage/CMakeLists.txt deleted file mode 100644 index 5b042a47fe4f2b..00000000000000 --- a/cmake/usage/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -string(REPLACE ";" " " BOARD_ROOT_SPACE_SEPARATED "${BOARD_ROOT}") -string(REPLACE ";" " " SHIELD_LIST_SPACE_SEPARATED "${SHIELD_LIST}") - -add_custom_target( - usage - ${CMAKE_COMMAND} - -DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED} - -DSHIELD_LIST_SPACE_SEPARATED=${SHIELD_LIST_SPACE_SEPARATED} - -P ${CMAKE_CURRENT_SOURCE_DIR}/usage.cmake - ) - -# NB: The reason it is 'usage' and not help is that CMake already -# defines a target 'help' diff --git a/doc/application/index.rst b/doc/application/index.rst index 10dc979c9f47c3..4d68dcb9479736 100644 --- a/doc/application/index.rst +++ b/doc/application/index.rst @@ -746,12 +746,12 @@ is optional. The binding directory contains bindings and the other directories contain files that can be included from DT sources. Once the directory structure is in place, you can use it by specifying -its location through the ``DTS_ROOT`` CMake Cache variable: +its location through the ``DTS_ROOT`` CMake Cache variable: .. zephyr-app-commands:: :tool: all :board: - :gen-args: -DDTS_ROOT= + :gen-args: -DDTS_ROOT= :goals: build :compact: @@ -1163,7 +1163,7 @@ For example: .. code-block:: cmake - set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE + set_property(TARGET ${ZEPHYR_TARGET} APPEND PROPERTY HEX_FILES_TO_MERGE ${app_bootloader_hex} ${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME} ${app_provision_hex}) @@ -1552,6 +1552,153 @@ After running the preprocessor, the final device tree used in the build is created by running the device tree compiler, ``dtc``, on the preprocessor output. +Building and Configuring multiple images +**************************************** + +When firmware updates and bootloaders are involved in an embedded +application, the final firmware that is flashed onto the device will +usually be multiple executables that chain-load, or boot, the next +executable. This section describes how to build and configure such a +Zephyr application. + +When and why to use multiple images +=================================== + +An executable goes by other names depending on context, for example: +image, or elf file. (From now on we will use the name image, short for +"executable program image".) An image consists of pieces of code and +data that go by image-unique names recorded in a single symbol table. +The symbol table exists as metadata in an .elf or .exe file and is not +included when converted to a hex file for device flashing. Object +files also consist of symbols, code, and data, but object files are +not images, because unlike object files, images have had their code +and data placed at addresses by a linker. In the end it is the linker +that creates images. If confused, and you want to determine if you +have zero, one, or more images, count the number of times the linker +has been run. + +From this definition it follows that using two images can give you two +opportunities. Firstly, it allows you to run the linker multiple +times, and in this process parition the final firmware into several +regions, as is often desired by bootloaders. And secondly, since there +will be multiple symbol tables, it allows the same symbol name to +exist multiple times in the final firmware. This again is useful for +bootloader images, as they often need to have their own fixed copies +of the same libraries that the application image is using. + +Enabling and configuring multiple images +======================================== + +Images are organized in a tree of parent-child relationships. Meaning, +a parent image needs and enables, through Kconfig, one or more child +images. The simplest and most common organization is a single +application image that enables a single bootloader image. + +When a parent image enables a child image through Kconfig, both images +will be configured when CMake is run. During the building of the +parent image, depending on the configuration of the parent image, the +child image will either be built from source or ignored. + +Configuring child images is done with the same mechanisms as for the +parent images: through CMake variables, Kconfig input fragments, and +modifying the .config file in the build directory. For instance, +one could run ``west build -- -Dmcuboot_CONF_FILE=prj_a.conf +-DCONF_FILE=app_prj.conf`` to change the CONF_FILE for the mcuboot +image and the parent image. As seen in CONF_FILE, all CMake Cache +variables that are image-specific are given a prefix to disambiguate +them. To simplify the configuration of single-image builds, the toplevel +image has the empty string as its prefix. + +The same prefix convention is used to disambiguate targets. This means +that, for instance, to run menuconfig one would invoke the +``menuconfig`` target to configure the toplevel image and +``mcuboot_menuconfig`` to configure the MCUBoot child image. + +Defining new child images +========================= + +This section describes how to take an existing parent image and turn +it into a child image that can be enabled. A parent image typically +consists of source code, Kconfig fragments, and build script code. The +source code and Kconfig fragments can be re-used as-is, but several +changes to the build scripts are necessary. + +As mentioned earlier, each target needs a prefix to avoid aliasing +issues between images. This includes the library target 'app', so any +references to 'app' would need to be changed to '${IMAGE}app'. Or, +even better, one would use the zephyr_library\_ API instead of the +target\_* API to indirectly modify '${IMAGE}app'. + +After the application build scripts have been ported, we can write some +build scripts, as shown below, to connect the build scripts of the +parent and child. This code should be placed somewhere in-tree that is +conditional on a Kconfig option for having the parent image use the +child image. + +.. code-block:: cmake + + set(child_image_name mcuboot) + zephyr_add_image(${child_image_name} require_build) + + set(build_directory ${CMAKE_CURRENT_BINARY_DIR}/mcuboot + set(child_image_application_directory ${MCUBOOT_BASE}/boot/zephyr) + + if(${require_build}) + add_subdirectory(${child_image_application_directory} ${build_directory}) + endif() + +In the above code 'zephyr_add_image' registers the child image as +present in the build, and 'add_subdirectory' actually executes the +child's build scripts. Note that in addition to the child image's +application build scripts being executed, most of the core build +scripts are executed for a second time as well, but now with a +different Kconfig configuration and possibly DeviceTree settings. + +Some Kconfig options must be added to allow the parent image to choose +how to include the child image. For now the image can either be built +or not built, but more options will come. The options can be added by +sourcing a template file like so: + +..code-block:: Kconfig + image = MCUBOOT + source "cmake/Kconfig.template.build_strategy" + +This will result in Kconfig that is equivalent to the snippet below: + +..code-block:: Kconfig + choice + prompt "build strategy" + default MCUBOOT_BUILD_STRATEGY_FROM_SOURCE + + config MCUBOOT_BUILD_STRATEGY_SKIP_BUILD + # Mandatory option when being built through 'zephyr_add_image' + bool "Skip building" + + config MCUBOOT_BUILD_STRATEGY_FROM_SOURCE + # Mandatory option when being built through 'zephyr_add_image' + bool "Build from source" + + endchoice + +Preventing accidental sharing between images +============================================ + +In a multi-image build, images share the same CMake namespace, which +allows closer integration between images but also creates the risk of +images accidentally corrupting each other. In this section, we give +strategies for preventing this corruption. + +Everything image-specific that also exists at generation time, meaning +targets, global properties, and CMake Cache variables, must be +image-prefixed. Being image-specific means that their value could be +different from image to image. For instance, the location of Python is +not image-specific and therefore the Cache variable PYTHON_EXECUTABLE +does not need to be image-prefixed. + +If a CMake variable is always initialized before being dereferenced, +and is not a Cache variable, then it does not to be image-prefixed +even if it is image-specific. + Application-Specific Code ************************* diff --git a/drivers/crypto/CMakeLists.txt b/drivers/crypto/CMakeLists.txt index 7a4e922c2f2ffa..05b32e21eb06db 100644 --- a/drivers/crypto/CMakeLists.txt +++ b/drivers/crypto/CMakeLists.txt @@ -4,4 +4,4 @@ zephyr_library() zephyr_library_sources_ifdef(CONFIG_CRYPTO_TINYCRYPT_SHIM crypto_tc_shim.c) zephyr_library_sources_ifdef(CONFIG_CRYPTO_ATAES132A crypto_ataes132a.c) zephyr_library_sources_ifdef(CONFIG_CRYPTO_MBEDTLS_SHIM crypto_mtls_shim.c) -zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 7d8e8585b11f2f..0d81a9889c7f68 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -2,7 +2,7 @@ # kernel is a normal CMake library and not a zephyr_library because it # should not be --whole-archive'd -add_library(kernel +add_library(${KERNEL_LIBRARY} device.c errno.c fatal.c @@ -29,16 +29,16 @@ add_library(kernel # Kernel files has the macro __ZEPHYR_SUPERVISOR__ set so that it # optimizes the code when userspace is enabled. set_target_properties( - kernel + ${KERNEL_LIBRARY} PROPERTIES COMPILE_DEFINITIONS __ZEPHYR_SUPERVISOR__ ) -target_sources_ifdef(CONFIG_STACK_CANARIES kernel PRIVATE compiler_stack_protect.c) -target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS kernel PRIVATE timeout.c timer.c) -target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c) -target_sources_if_kconfig( kernel PRIVATE poll.c) +target_sources_ifdef(CONFIG_STACK_CANARIES ${KERNEL_LIBRARY} PRIVATE compiler_stack_protect.c) +target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS ${KERNEL_LIBRARY} PRIVATE timeout.c timer.c) +target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C ${KERNEL_LIBRARY} PRIVATE atomic_c.c) +target_sources_if_kconfig( ${KERNEL_LIBRARY} PRIVATE poll.c) # The last 2 files inside the target_sources_ifdef should be # userspace_handler.c and userspace.c. If not the linker would complain. @@ -46,7 +46,7 @@ target_sources_if_kconfig( kernel PRIVATE poll.c) # above these 2 files. target_sources_ifdef( CONFIG_USERSPACE - kernel PRIVATE + ${KERNEL_LIBRARY} PRIVATE futex.c mem_domain.c userspace_handler.c @@ -54,6 +54,6 @@ target_sources_ifdef( ) -add_dependencies(kernel ${OFFSETS_H_TARGET}) +add_dependencies(${KERNEL_LIBRARY} ${OFFSETS_H_TARGET}) -target_link_libraries(kernel zephyr_interface) +target_link_libraries(${KERNEL_LIBRARY} ${IMAGE}zephyr_interface) diff --git a/lib/cmsis_rtos_v1/CMakeLists.txt b/lib/cmsis_rtos_v1/CMakeLists.txt index b3c31c66d68a0d..8da21de6d94bf0 100644 --- a/lib/cmsis_rtos_v1/CMakeLists.txt +++ b/lib/cmsis_rtos_v1/CMakeLists.txt @@ -1,9 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 -add_library(CMSIS INTERFACE) +add_library(${IMAGE}CMSIS INTERFACE) -target_include_directories(CMSIS INTERFACE ${PROJECT_SOURCE_DIR}/include/cmsis_rtos_v1) +target_include_directories(${IMAGE}CMSIS INTERFACE ${ZEPHYR_BASE}/include/cmsis_rtos_v1) zephyr_library() zephyr_library_sources_ifdef( @@ -20,4 +20,4 @@ zephyr_library_sources_ifdef( cmsis_signal.c ) -zephyr_library_link_libraries(CMSIS) +zephyr_library_link_libraries(${IMAGE}CMSIS) diff --git a/lib/cmsis_rtos_v2/CMakeLists.txt b/lib/cmsis_rtos_v2/CMakeLists.txt index 5327dad9b5d8cf..15dcfd0c9676a8 100644 --- a/lib/cmsis_rtos_v2/CMakeLists.txt +++ b/lib/cmsis_rtos_v2/CMakeLists.txt @@ -1,9 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 -add_library(CMSIS INTERFACE) +add_library(${IMAGE}CMSIS INTERFACE) -target_include_directories(CMSIS INTERFACE ${PROJECT_SOURCE_DIR}/include/cmsis_rtos_v2) +target_include_directories(${IMAGE}CMSIS INTERFACE ${ZEPHYR_BASE}/include/cmsis_rtos_v2) zephyr_library() zephyr_library_sources_ifdef( @@ -19,4 +19,4 @@ zephyr_library_sources_ifdef( thread_flags.c ) -zephyr_library_link_libraries(CMSIS) +zephyr_library_link_libraries(${IMAGE}CMSIS) diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index 5d44cf8a792521..ffde31e920e7f0 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -2,9 +2,10 @@ zephyr_interface_library_named(posix_subsys) +set(posix_subsys ${IMAGE}posix_subsys) if(CONFIG_POSIX_API) - target_include_directories(posix_subsys INTERFACE ${ZEPHYR_BASE}/include/posix) + target_include_directories(${posix_subsys} INTERFACE ${ZEPHYR_BASE}/include/posix) endif() zephyr_library() @@ -23,4 +24,4 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC pthread_key.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c) zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) -zephyr_library_link_libraries(posix_subsys) +zephyr_library_link_libraries(${posix_subsys}) diff --git a/samples/subsys/ipc/ipm_mcux/CMakeLists.txt b/samples/subsys/ipc/ipm_mcux/CMakeLists.txt index 4b7fb8118848f0..e69eec0277e42c 100644 --- a/samples/subsys/ipc/ipm_mcux/CMakeLists.txt +++ b/samples/subsys/ipc/ipm_mcux/CMakeLists.txt @@ -24,4 +24,4 @@ ExternalProject_Add( project(ipm_mcux) target_sources(app PRIVATE src/main_master.c) -add_dependencies(core_m0_inc_target ipm_mcux_remote) +add_dependencies(${IMAGE}core_m0_inc_target ipm_mcux_remote) diff --git a/samples/subsys/ipc/openamp/CMakeLists.txt b/samples/subsys/ipc/openamp/CMakeLists.txt index fe0456425bc519..df702c08e48004 100644 --- a/samples/subsys/ipc/openamp/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.13.1) # set(BOARD lpcxpresso54114_m4) +list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_LIST_DIR}/remote) + include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(openamp) @@ -16,15 +18,4 @@ enable_language(C ASM) target_sources(app PRIVATE src/main.c) -include(ExternalProject) - -ExternalProject_Add( - openamp_remote - SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote - INSTALL_COMMAND "" # This particular build system has no install command - BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" - # NB: Do we need to pass on more CMake variables? -) -add_dependencies(core_m0_inc_target openamp_remote) - target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/samples/subsys/ipc/openamp/Kconfig b/samples/subsys/ipc/openamp/Kconfig new file mode 100644 index 00000000000000..a314dc567bc88e --- /dev/null +++ b/samples/subsys/ipc/openamp/Kconfig @@ -0,0 +1,12 @@ +# +# Copyright (c) 2019 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +mainmenu "OpenAMP sample application" + +image = REMOTE +source "cmake/Kconfig.template.build_strategy" + +source "Kconfig.zephyr" diff --git a/samples/subsys/ipc/openamp/prj.conf b/samples/subsys/ipc/openamp/prj.conf index a9b5cad7d290b8..bcd035c8776daf 100644 --- a/samples/subsys/ipc/openamp/prj.conf +++ b/samples/subsys/ipc/openamp/prj.conf @@ -2,7 +2,7 @@ CONFIG_PRINTK=y CONFIG_IPM=y CONFIG_IPM_MCUX=y CONFIG_SLAVE_CORE_MCUX=y -CONFIG_SLAVE_IMAGE_MCUX="${ZEPHYR_BINARY_DIR}/../openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" +CONFIG_SLAVE_IMAGE_MCUX="${CMAKE_BINARY_DIR}/remote/zephyr/zephyr.bin" CONFIG_TIMESLICE_SIZE=1 CONFIG_MAIN_STACK_SIZE=2048 CONFIG_HEAP_MEM_POOL_SIZE=4096 diff --git a/samples/subsys/ipc/openamp/remote/CMakeLists.txt b/samples/subsys/ipc/openamp/remote/CMakeLists.txt index a6cc307808dece..2afdce327be55e 100644 --- a/samples/subsys/ipc/openamp/remote/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/remote/CMakeLists.txt @@ -12,5 +12,5 @@ if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m0")) message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m0") endif() -target_sources(app PRIVATE src/main.c) -target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) +zephyr_library_sources(src/main.c) +zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/samples/subsys/ipc/openamp/remote/zephyr/CMakeLists.txt b/samples/subsys/ipc/openamp/remote/zephyr/CMakeLists.txt new file mode 100644 index 00000000000000..d10f9b713200f6 --- /dev/null +++ b/samples/subsys/ipc/openamp/remote/zephyr/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(FIRST_BOILERPLATE_EXECUTION) + zephyr_add_image(remote output_variable) + + if(output_variable) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/.. ${CMAKE_BINARY_DIR}/remote) + endif() +endif() diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/CMakeLists.txt b/samples/subsys/mgmt/mcumgr/smp_svr/CMakeLists.txt index 42d6cd4257f480..4f8026ccf70f0b 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/CMakeLists.txt +++ b/samples/subsys/mgmt/mcumgr/smp_svr/CMakeLists.txt @@ -16,4 +16,4 @@ target_sources(app PRIVATE src/main.c ) -zephyr_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS NFFS) +zephyr_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS ${IMAGE}NFFS) diff --git a/scripts/west_commands/completion/west-completion.bash b/scripts/west_commands/completion/west-completion.bash index b434396b4e5f86..7b0e5bb03f43cf 100644 --- a/scripts/west_commands/completion/west-completion.bash +++ b/scripts/west_commands/completion/west-completion.bash @@ -694,6 +694,7 @@ __comp_west_runner_cmd() local runner_args_opts=" --build-dir -d --cmake-cache -c + --image -i --runner -r --board-dir --elf-file diff --git a/scripts/west_commands/run_common.py b/scripts/west_commands/run_common.py index 92fce6ec67a616..83b5ef44e4ca82 100644 --- a/scripts/west_commands/run_common.py +++ b/scripts/west_commands/run_common.py @@ -76,9 +76,10 @@ def add_parser_common(parser_adder, command): formatter_class=argparse.RawDescriptionHelpFormatter, help=command.help, description=command.description) + command_verb = "flash" if command == "flash" else "debug" - # Remember to update scripts/west-completion.bash if you add or remove - # flags + # Update scripts/west_commands/completion/west-completion.bash if + # you add or remove flags. parser.add_argument('-H', '--context', action='store_true', help='''Rebuild application and print context-sensitive @@ -99,6 +100,10 @@ def add_parser_common(parser_adder, command): If this is a relative path, it is assumed relative to the build directory. An absolute path can also be given instead.'''.format(cmake.DEFAULT_CACHE)) + group.add_argument('-i', '--image', default='', + help='''In a multi-image build, specifies the name + of the IMAGE to {}. If not given, the main image + is used.'''.format(command_verb)) group.add_argument('-r', '--runner', help='''If given, overrides any cached {} runner.'''.format(command.name)) @@ -122,8 +127,6 @@ def add_parser_common(parser_adder, command): # This is how we detect if the user provided them or not when # overriding values from the cached configuration. - command_verb = "flash" if command == "flash" else "debug" - group.add_argument('--board-dir', help='Zephyr board directory') group.add_argument('--elf-file', @@ -197,9 +200,12 @@ def dump_traceback(): traceback.print_exc(file=f) log.inf("An exception trace has been saved in", name) -def do_run_common(command, args, runner_args, cached_runner_var): +def do_run_common(command, args, runner_args, runner_var_sfx, image_pfx = ''): + image = args.image + image_pfx = image + '_' if image else '' + if args.context: - _dump_context(command, args, runner_args, cached_runner_var) + _dump_context(command, args, runner_args, runner_var_sfx, image_pfx) return command_name = command.name @@ -220,35 +226,65 @@ def do_run_common(command, args, runner_args, cached_runner_var): # Runner creation, phase 1. # - # Get the default runner name from the cache, allowing a command - # line override. Get the ZephyrBinaryRunner class by name, and - # make sure it supports the command. + # Get the ZephyrBinaryRunner class from command line arguments and + # CMake cache, and make sure it supports the command. cache_file = path.join(build_dir, args.cmake_cache or cmake.DEFAULT_CACHE) try: cache = cmake.CMakeCache(cache_file) except FileNotFoundError: log.die('no CMake cache found (expected one at {})'.format(cache_file)) - board = cache['CACHED_BOARD'] - available = cache.get_list('ZEPHYR_RUNNERS') + + + if image: # the default '' works as-is in a single or multi-image build. + images = cache.get_list('ZEPHYR_IMAGES') + if images is None: + log.die('image {} specified, but this is not a multi-image build'. + format(image)) + elif args.image not in images: + log.die('invalid sub-image {}; choose from: {}'. + format(args.image, ', '.join(images))) + + board_var = image_pfx + 'CACHED_BOARD' + board = cache.get(board_var) + if board is None: + log.die("Can't look up board in", cache_file, '(variable', board_var, + 'is unset)') + + image_runner_var = image_pfx + 'ZEPHYR_RUNNERS' + available = cache.get_list(image_runner_var) if not available: - log.wrn('No cached runners are available in', cache_file) - runner = args.runner or cache.get(cached_runner_var) + log.wrn('No runners are configured for', board, 'in', cache_file, + '(check variable {}); this may not work'.format( + image_runner_var)) + cached_runner_var = image_pfx + runner_var_sfx + runner = args.runner or cache.get(cached_runner_var) if runner is None: log.die('No', command_name, 'runner available for board', board, '({} is not in the cache).'.format(cached_runner_var), "Check your board's documentation for instructions.") - + log.inf('BOARD:', board) _banner('west {}: using runner {}'.format(command_name, runner)) if runner not in available: - log.wrn('Runner {} is not configured for use with {}, ' + log.wrn('Runner {} is not configured for use with board {}; ' 'this may not work'.format(runner, board)) + runner_cls = get_runner_cls(runner) if command_name not in runner_cls.capabilities().commands: log.die('Runner {} does not support command {}'.format( runner, command_name)) + # Sanity check a multi-image build configuration. + if image: + strategy = cache[image_pfx + 'ZEPHYR_BUILD_STRATEGY'] + # TODO: support hex file management once we have a uniform + # runner argument strategy for specifying the file to flash. + if strategy != 'DEFAULT': + log.die("Can't flash image {}:".format(image), + 'no-default build strategy', strategy, + 'is not yet supported') + # Runner creation, phase 2. # # At this point, the common options above are already parsed in @@ -261,7 +297,7 @@ def do_run_common(command, args, runner_args, cached_runner_var): logger = logging.getLogger('runners') logger.setLevel(LOG_LEVEL) logger.addHandler(WestLogHandler()) - cfg = cached_runner_config(build_dir, cache) + cfg = cached_runner_config(build_dir, cache, image_pfx) _override_config_from_namespace(cfg, args) # Runner creation, phase 3. @@ -274,7 +310,8 @@ def do_run_common(command, args, runner_args, cached_runner_var): # RunnerConfig and parsed arguments. cached_runner_args = cache.get_list( - 'ZEPHYR_RUNNER_ARGS_{}'.format(cmake.make_c_identifier(runner))) + image_pfx + 'ZEPHYR_RUNNER_ARGS_{}'. + format(cmake.make_c_identifier(runner))) assert isinstance(runner_args, list), runner_args # If the user passed -- to force the parent argument parser to stop # parsing, it will show up here, and needs to be filtered out. @@ -301,7 +338,7 @@ def do_run_common(command, args, runner_args, cached_runner_var): # Context-specific help # -def _dump_context(command, args, runner_args, cached_runner_var): +def _dump_context(command, args, runner_args, cached_runner_var, image_pfx): build_dir = _build_dir(args, die_if_none=False) # Try to figure out the CMake cache file based on the build @@ -350,18 +387,18 @@ def _dump_context(command, args, runner_args, cached_runner_var): if args.runner: # Just information on one runner was requested. - _dump_one_runner_info(cache, args, build_dir, INDENT) + _dump_one_runner_info(cache, args, build_dir, INDENT, image_pfx) return - board = cache['CACHED_BOARD'] + board = cache[image_pfx + 'CACHED_BOARD'] all_cls = {cls.name(): cls for cls in ZephyrBinaryRunner.get_runners() if command.name in cls.capabilities().commands} - available = [r for r in cache.get_list('ZEPHYR_RUNNERS') if r in all_cls] + available = [r for r in cache.get_list(image_pfx + 'ZEPHYR_RUNNERS') if r in all_cls] available_cls = {r: all_cls[r] for r in available if r in all_cls} default_runner = cache.get(cached_runner_var) - cfg = cached_runner_config(build_dir, cache) + cfg = cached_runner_config(build_dir, cache, image_pfx) log.inf('All Zephyr runners which support {}:'.format(command.name), colorize=True) @@ -403,7 +440,7 @@ def _dump_context(command, args, runner_args, cached_runner_var): log.inf('Runner-specific information:', colorize=True) for runner in available: log.inf('{}{}:'.format(INDENT, runner), colorize=True) - _dump_runner_cached_opts(cache, runner, INDENT * 2, INDENT * 3) + _dump_runner_cached_opts(cache, runner, INDENT * 2, INDENT * 3, image_pfx) _dump_runner_caps(available_cls[runner], INDENT * 2) if len(available) > 1: @@ -423,7 +460,7 @@ def _dump_no_context_info(command, args): colorize=True) -def _dump_one_runner_info(cache, args, build_dir, indent): +def _dump_one_runner_info(cache, args, build_dir, indent, image_pfx): runner = args.runner cls = get_runner_cls(runner) @@ -432,13 +469,13 @@ def _dump_one_runner_info(cache, args, build_dir, indent): _dump_runner_caps(cls, '') return - available = runner in cache.get_list('ZEPHYR_RUNNERS') - cfg = cached_runner_config(build_dir, cache) + available = runner in cache.get_list(image_pfx + 'ZEPHYR_RUNNERS') + cfg = cached_runner_config(build_dir, cache, image_pfx) log.inf('Build directory:', colorize=True) log.inf(INDENT + build_dir) log.inf('Board:', colorize=True) - log.inf(INDENT + cache['CACHED_BOARD']) + log.inf(INDENT + cache[image_pfx + 'CACHED_BOARD']) log.inf('CMake cache:', colorize=True) log.inf(INDENT + cache.cache_file) log.inf(runner, 'is available:', 'yes' if available else 'no', @@ -446,7 +483,7 @@ def _dump_one_runner_info(cache, args, build_dir, indent): _dump_runner_opt_help(runner, cls) _dump_runner_config(cfg, '', indent) if available: - _dump_runner_cached_opts(cache, runner, '', indent) + _dump_runner_cached_opts(cache, runner, '', indent, image_pfx) _dump_runner_caps(cls, '') if not available: log.wrn('Runner', runner, 'is not configured in this build.') @@ -488,8 +525,8 @@ def _dump_runner_config(cfg, initial_indent, subsequent_indent): log.inf('{}--{}={}'.format(subsequent_indent, var, getattr(cfg, var))) -def _dump_runner_cached_opts(cache, runner, initial_indent, subsequent_indent): - runner_args = _get_runner_args(cache, runner) +def _dump_runner_cached_opts(cache, runner, initial_indent, subsequent_indent, image_pfx = ''): + runner_args = _get_runner_args(cache, runner, image_pfx) if not runner_args: return @@ -499,7 +536,7 @@ def _dump_runner_cached_opts(cache, runner, initial_indent, subsequent_indent): log.inf('{}{}'.format(subsequent_indent, arg)) -def _get_runner_args(cache, runner): +def _get_runner_args(cache, runner, pfx = ''): runner_ident = cmake.make_c_identifier(runner) args_var = 'ZEPHYR_RUNNER_ARGS_{}'.format(runner_ident) - return cache.get_list(args_var) + return cache.get_list(pfx + args_var) diff --git a/scripts/west_commands/zephyr_ext_common.py b/scripts/west_commands/zephyr_ext_common.py index fa6dcde0be9a43..e1879bb101f2e5 100644 --- a/scripts/west_commands/zephyr_ext_common.py +++ b/scripts/west_commands/zephyr_ext_common.py @@ -37,16 +37,15 @@ def check_force(self, cond, msg): log.err(msg) log.die('refusing to proceed without --force due to above error') - -def cached_runner_config(build_dir, cache): +def cached_runner_config(build_dir, cache, pfx=''): '''Parse the RunnerConfig from a build directory and CMake Cache.''' - board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR'] - elf_file = cache.get('ZEPHYR_RUNNER_CONFIG_KERNEL_ELF') - hex_file = cache.get('ZEPHYR_RUNNER_CONFIG_KERNEL_HEX') - bin_file = cache.get('ZEPHYR_RUNNER_CONFIG_KERNEL_BIN') - gdb = cache.get('ZEPHYR_RUNNER_CONFIG_GDB') - openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD') - openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH') + board_dir = cache[ pfx + 'ZEPHYR_RUNNER_CONFIG_BOARD_DIR'] + elf_file = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_KERNEL_ELF') + hex_file = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_KERNEL_HEX') + bin_file = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_KERNEL_BIN') + gdb = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_GDB') + openocd = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_OPENOCD') + openocd_search = cache.get(pfx + 'ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH') return RunnerConfig(build_dir, board_dir, elf_file, hex_file, bin_file, diff --git a/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt b/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt index 2347dcb3a0c961..39d46859484760 100644 --- a/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt +++ b/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt @@ -18,5 +18,5 @@ if (CONFIG_SLAVE_CORE_MCUX) generate_inc_file_for_gen_target(${ZEPHYR_CURRENT_LIBRARY} ${core_m0_image} ${gen_dir}/core-m0.inc - core_m0_inc_target) + ${IMAGE}core_m0_inc_target) endif() diff --git a/subsys/bluetooth/CMakeLists.txt b/subsys/bluetooth/CMakeLists.txt index 4cac45c2e0c019..0b21a45b4596e2 100644 --- a/subsys/bluetooth/CMakeLists.txt +++ b/subsys/bluetooth/CMakeLists.txt @@ -1,8 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 +add_library(${IMAGE}subsys__bluetooth INTERFACE) -add_library(subsys__bluetooth INTERFACE) -target_include_directories(subsys__bluetooth INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${IMAGE}subsys__bluetooth INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(common) add_subdirectory_ifdef(CONFIG_BT_HCI host) diff --git a/subsys/bluetooth/common/CMakeLists.txt b/subsys/bluetooth/common/CMakeLists.txt index 059a0d6ab1255e..a0d6656219e8d9 100644 --- a/subsys/bluetooth/common/CMakeLists.txt +++ b/subsys/bluetooth/common/CMakeLists.txt @@ -7,4 +7,4 @@ zephyr_library_sources(log.c) zephyr_library_sources_ifdef(CONFIG_BT_RPA rpa.c) -zephyr_library_link_libraries(subsys__bluetooth) +zephyr_library_link_libraries(${IMAGE}subsys__bluetooth) diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index 764ccadab66122..557808e15f6e7f 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -172,4 +172,4 @@ zephyr_library_compile_options_ifdef( ${OPTIMIZE_FOR_SPEED_FLAG} ) -zephyr_library_link_libraries(subsys__bluetooth) +zephyr_library_link_libraries(${IMAGE}subsys__bluetooth) diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index 5edfb9491b8726..ce915889da9b76 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -zephyr_library_link_libraries(subsys__bluetooth) +zephyr_library_link_libraries(${IMAGE}subsys__bluetooth) zephyr_library_sources_ifdef(CONFIG_BT_HCI_RAW hci_raw.c) zephyr_library_sources_ifdef(CONFIG_BT_DEBUG_MONITOR monitor.c) diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 72f5adcbdf2907..a419c71659ad88 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -zephyr_library_link_libraries(subsys__bluetooth) +zephyr_library_link_libraries(${IMAGE}subsys__bluetooth) zephyr_library_sources_ifdef(CONFIG_BT_MESH main.c diff --git a/subsys/fs/CMakeLists.txt b/subsys/fs/CMakeLists.txt index 54af259b33fbc5..1fda919772fff4 100644 --- a/subsys/fs/CMakeLists.txt +++ b/subsys/fs/CMakeLists.txt @@ -15,7 +15,7 @@ if(CONFIG_FILE_SYSTEM) target_link_libraries_ifdef(CONFIG_FAT_FILESYSTEM_ELM FS INTERFACE ELMFAT) target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS FS INTERFACE LITTLEFS) - target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS FS INTERFACE NFFS) + target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS FS INTERFACE ${IMAGE}NFFS) endif() add_subdirectory_ifdef(CONFIG_FCB ./fcb) diff --git a/subsys/jwt/CMakeLists.txt b/subsys/jwt/CMakeLists.txt index ef59560a5e5e8b..b465b4eafa812c 100644 --- a/subsys/jwt/CMakeLists.txt +++ b/subsys/jwt/CMakeLists.txt @@ -2,4 +2,4 @@ zephyr_library() zephyr_library_sources(jwt.c) -zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) diff --git a/subsys/net/ip/CMakeLists.txt b/subsys/net/ip/CMakeLists.txt index 43d08204fdf8a6..4d3b8037721913 100644 --- a/subsys/net/ip/CMakeLists.txt +++ b/subsys/net/ip/CMakeLists.txt @@ -46,5 +46,5 @@ if(CONFIG_NET_SHELL) zephyr_library_sources(net_shell.c) zephyr_library_include_directories(. ${ZEPHYR_BASE}/subsys/net/l2) zephyr_library_include_directories(. ${ZEPHYR_BASE}/subsys/net/lib) -zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) endif() diff --git a/subsys/net/lib/lwm2m/CMakeLists.txt b/subsys/net/lib/lwm2m/CMakeLists.txt index ea864540318632..38db54cc32e224 100644 --- a/subsys/net/lib/lwm2m/CMakeLists.txt +++ b/subsys/net/lib/lwm2m/CMakeLists.txt @@ -61,4 +61,4 @@ zephyr_library_sources_ifdef(CONFIG_LWM2M_IPSO_PUSH_BUTTON ipso_push_button.c ) -zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) diff --git a/subsys/net/lib/sockets/CMakeLists.txt b/subsys/net/lib/sockets/CMakeLists.txt index f3500b7c9db6f9..d57d3da7062a70 100644 --- a/subsys/net/lib/sockets/CMakeLists.txt +++ b/subsys/net/lib/sockets/CMakeLists.txt @@ -21,4 +21,4 @@ if(CONFIG_NET_SOCKETS_NET_MGMT) zephyr_include_directories(${ZEPHYR_BASE}/subsys/net/ip) endif() -zephyr_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) diff --git a/subsys/net/lib/websocket/CMakeLists.txt b/subsys/net/lib/websocket/CMakeLists.txt index aed4e4708c7a7f..819a20ae232b61 100644 --- a/subsys/net/lib/websocket/CMakeLists.txt +++ b/subsys/net/lib/websocket/CMakeLists.txt @@ -7,4 +7,4 @@ zephyr_library_sources( websocket.c ) -zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS ${IMAGE}mbedTLS) diff --git a/west.yml b/west.yml index 25d8890834d356..a1443c778a37a3 100644 --- a/west.yml +++ b/west.yml @@ -71,7 +71,7 @@ manifest: revision: d4708d0a432e95f51bdc712591ba5295b751140c path: modules/lib/gui/lvgl - name: mbedtls - revision: bbcb1b14285ac1b694d8c7e47c2f139c80b7fc4c + revision: pull/5/head path: modules/crypto/mbedtls - name: mcumgr revision: 84934959d2d1722a23b7e7e200191ae4a6f96168 @@ -80,7 +80,7 @@ manifest: revision: 30b7efa827b04d2e47840716b0372737fe7d6c92 path: tools/net-tools - name: nffs - revision: bc62a2fa9d98ddb5d633c932ea199bc68e10f194 + revision: pull/1/head path: modules/fs/nffs - name: hal_nxp revision: 97265a5396edc6a9de5f2fb643d505f37064e606