From 152607008266991591d743b1b81100b3d9062e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Mon, 14 Jan 2019 16:31:02 +0100 Subject: [PATCH] cmake: Use a variable for 'zephyr_prebuilt' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is an effort underway to make most of the Zephyr build script's reentrant. Meaning, the build scripts can be executed multiple times during the same CMake invocation. Reentrancy enables several use-cases, the motivating one is the ability to build several Zephyr executables, or images, for instance a bootloader and an application. For build scripts to be reentrant they cannot be directly referencing global variables, like target names, but must instead reference variables, which can vary from entry to entry. Therefore, in this patch, we replace global targets with variables. Signed-off-by: Sebastian Bøe --- CMakeLists.txt | 31 ++++++++++++++++--------------- arch/x86/CMakeLists.txt | 26 +++++++++++++------------- arch/x86_64/core/CMakeLists.txt | 2 +- doc/kernel/other/interrupts.rst | 11 ++++++----- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 354b9a66926..c3d7985d8e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ check_c_compiler_flag("" toolchain_is_ok) assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.") set(CMAKE_EXECUTABLE_SUFFIX .elf) +set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_prebuilt) if(NOT PROPERTY_LINKER_SCRIPT_DEFINES) set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) @@ -841,7 +842,7 @@ if(CONFIG_GEN_ISR_TABLES) list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) endif() - # isr_tables.c is generated from zephyr_prebuilt by + # isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by # gen_isr_tables.py add_custom_command( OUTPUT isr_tables.c @@ -849,17 +850,17 @@ if(CONFIG_GEN_ISR_TABLES) -I ${OUTPUT_FORMAT} -O binary --only-section=.intList - $ + $ isrList.bin COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py --output-source isr_tables.c - --kernel $ + --kernel $ --intlist isrList.bin $<$:--big-endian> $<$:--debug> ${GEN_ISR_TABLE_EXTRA_ARG} - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} ) set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) endif() @@ -921,7 +922,7 @@ if(CONFIG_ARM AND CONFIG_USERSPACE) # elf file. # Use the script GEN_PRIV_STACKS to scan the kernel binary's - # (zephyr_prebuilt) DWARF information to produce a table of kernel + # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel # objects (PRIV_STACKS) which we will then pass to gperf add_custom_command( OUTPUT ${PRIV_STACKS} @@ -1040,17 +1041,17 @@ if(CONFIG_USERSPACE) # elf file. # Use the script GEN_KOBJ_LIST to scan the kernel binary's - # (zephyr_prebuilt) DWARF information to produce a table of kernel + # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel # objects (OBJ_LIST) which we will then pass to gperf add_custom_command( OUTPUT ${OBJ_LIST} COMMAND ${PYTHON_EXECUTABLE} ${GEN_KOBJ_LIST} - --kernel $ + --kernel $ --gperf-output ${OBJ_LIST} $<$:--verbose> - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) @@ -1262,10 +1263,10 @@ endif() endif() # FIXME: Is there any way to get rid of empty_file.c? -add_executable( zephyr_prebuilt misc/empty_file.c) -target_link_libraries(zephyr_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk} ${CODE_RELOCATION_DEP}) -set_property(TARGET zephyr_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) -add_dependencies( zephyr_prebuilt ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_script offsets) +add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c) +target_link_libraries(${ZEPHYR_PREBUILT_EXECUTABLE} ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk} ${CODE_RELOCATION_DEP}) +set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) +add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_script offsets) if(GKOF OR GKSF) @@ -1284,7 +1285,7 @@ if(GKOF OR GKSF) DEPENDS ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} ${CODE_RELOCATION_DEP} - zephyr_prebuilt + ${ZEPHYR_PREBUILT_EXECUTABLE} linker_pass_final.cmd offsets_h ) @@ -1299,7 +1300,7 @@ if(GKOF OR GKSF) set_property(TARGET kernel_elf PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) add_dependencies( kernel_elf ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_pass_final_script) else() - set(logical_target_for_zephyr_elf zephyr_prebuilt) + set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE}) # Use the prebuilt elf as the final elf since we don't have a # generation stage. endif() @@ -1410,7 +1411,7 @@ if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) zephyr_check_compiler_flag(C "" ${check}) set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS}) - target_link_libraries_ifdef(${check} zephyr_prebuilt ${option}) + target_link_libraries_ifdef(${check} ${ZEPHYR_PREBUILT_EXECUTABLE} ${option}) endif() if(EMU_PLATFORM) diff --git a/arch/x86/CMakeLists.txt b/arch/x86/CMakeLists.txt index 364c2fb91de..c8d2f71af00 100644 --- a/arch/x86/CMakeLists.txt +++ b/arch/x86/CMakeLists.txt @@ -44,7 +44,7 @@ set(GENIDT ${ZEPHYR_BASE}/scripts/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 +# irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE} set(gen_idt_output_files ${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin ${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin @@ -60,12 +60,12 @@ add_custom_command( COMMAND ${PYTHON_EXECUTABLE} ${GENIDT} - --kernel $ + --kernel $ --output-idt staticIdt.bin --vector-map irq_int_vector_map.bin --output-vectors-alloc irq_vectors_alloc.bin ${GENIDT_EXTRA_ARGS} - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) @@ -137,10 +137,10 @@ set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES irq_vectors_al if(CONFIG_X86_MMU) # Use gen_mmu.py and objcopy to generate mmu_tables.o from from the - # elf file zephyr_prebuilt, creating the temp files mmu_tables.bin + # elf file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp files mmu_tables.bin # and mmulist.bin along the way. # - # zephyr_prebuilt.elf -> mmulist.bin -> mmu_tables.bin -> mmu_tables.o + # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> mmulist.bin -> mmu_tables.bin -> mmu_tables.o add_custom_command( OUTPUT mmulist.bin COMMAND @@ -148,9 +148,9 @@ if(CONFIG_X86_MMU) -I ${OUTPUT_FORMAT} -O binary -j mmulist - $ + $ mmulist.bin - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_command( @@ -159,12 +159,12 @@ if(CONFIG_X86_MMU) ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_mmu_x86.py -i mmulist.bin - -k $ + -k $ -o mmu_tables.bin $<$:-v> WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS mmulist.bin - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} ) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mmu_tables.o @@ -189,19 +189,19 @@ endif() if(CONFIG_GDT_DYNAMIC) # Use gen_gdt.py and objcopy to generate gdt.o from from the elf - # file zephyr_prebuilt, creating the temp file gdt.bin along the + # file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the # way. # - # zephyr_prebuilt.elf -> gdt.bin -> gdt.o + # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o add_custom_command( OUTPUT gdt.bin COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_gdt.py - --kernel $ + --kernel $ --output-gdt gdt.bin $<$:--verbose> - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_command( diff --git a/arch/x86_64/core/CMakeLists.txt b/arch/x86_64/core/CMakeLists.txt index 93ce5cbf2ed..9c779afd574 100644 --- a/arch/x86_64/core/CMakeLists.txt +++ b/arch/x86_64/core/CMakeLists.txt @@ -61,7 +61,7 @@ set(qkernel_file ${CMAKE_BINARY_DIR}/zephyr-qemu.elf) add_custom_target(qemu_kernel_target DEPENDS ${qkernel_file}) add_custom_command( OUTPUT ${qkernel_file} - DEPENDS zephyr_prebuilt + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_BINARY_DIR}/zephyr/zephyr.elf ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.bin COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qemuinc.c ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_C_COMPILER} -m32 -c ${CMAKE_CURRENT_BINARY_DIR}/qemuinc.c -o ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.o diff --git a/doc/kernel/other/interrupts.rst b/doc/kernel/other/interrupts.rst index 80358e9f90f..564910d8d7b 100644 --- a/doc/kernel/other/interrupts.rst +++ b/doc/kernel/other/interrupts.rst @@ -308,8 +308,8 @@ struct _isr_list which is placed in a special .intList section: }; Zephyr is built in two phases; the first phase of the build produces -zephyr_prebuilt.elf which contains all the entries in the .intList section -preceded by a header: +``${ZEPHYR_PREBUILT_EXECUTABLE}``.elf which contains all the entries in +the .intList section preceded by a header: .. code-block:: c @@ -322,9 +322,10 @@ preceded by a header: }; This data consisting of the header and instances of struct _isr_list inside -zephyr_prebuilt.elf is then used by the gen_isr_tables.py script to generate a -C file defining a vector table and software ISR table that are then compiled -and linked into the final application. +``${ZEPHYR_PREBUILT_EXECUTABLE}``.elf is then used by the +gen_isr_tables.py script to generate a C file defining a vector table and +software ISR table that are then compiled and linked into the final +application. The priority level of any interrupt is not encoded in these tables, instead :c:macro:`IRQ_CONNECT` also has a runtime component which programs the desired