Skip to content

Commit

Permalink
init_priorities: Fix for native_simulator based targets
Browse files Browse the repository at this point in the history
Fix the init_prioties related cmake targets so they also
work with native_simulator based build targets.
Mostly this consists of pointing to the right file
(final build result instead of intermediate elf library)
and setting the dependency to that final build result.

Note that for the native_simulator based targets
the init priorities check can only be run on build
if we are building the final image (not just a partial
prelinked library),
and we are not assembling several images together
into one executable.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar authored and fabiobaltieri committed Nov 27, 2023
1 parent c3940cb commit 9bb708e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
35 changes: 23 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,6 @@ if(CONFIG_BUILD_OUTPUT_EXE)
post_build_byproducts
${KERNEL_EXE_NAME}
)
set(BYPRODUCT_KERNEL_EXE_NAME "${PROJECT_BINARY_DIR}/${KERNEL_EXE_NAME}" CACHE FILEPATH "Kernel exe file" FORCE)
else()
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(MAKE "${CMAKE_MAKE_PROGRAM}" CACHE FILEPATH "cmake defined make")
Expand All @@ -1768,6 +1767,7 @@ if(CONFIG_BUILD_OUTPUT_EXE)
BYPRODUCTS ${KERNEL_EXE_NAME}
)
endif()
set(BYPRODUCT_KERNEL_EXE_NAME "${PROJECT_BINARY_DIR}/${KERNEL_EXE_NAME}" CACHE FILEPATH "Kernel exe file" FORCE)
endif()

if(CONFIG_BUILD_OUTPUT_INFO_HEADER)
Expand All @@ -1784,21 +1784,32 @@ if(CONFIG_BUILD_OUTPUT_INFO_HEADER)
)
endif()

if(CONFIG_CHECK_INIT_PRIORITIES)
list(APPEND
post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/check_init_priorities.py
--elf-file=${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME}
if(NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang")
set(check_init_priorities_input
$<IF:$<TARGET_EXISTS:native_runner_executable>,${BYPRODUCT_KERNEL_EXE_NAME},${BYPRODUCT_KERNEL_ELF_NAME}>
)
set(check_init_priorities_command
${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/check_init_priorities.py
--elf-file=${check_init_priorities_input}
)
set(check_init_priorities_dependencies
${logical_target_for_zephyr_elf}
$<$<TARGET_EXISTS:native_runner_executable>:native_runner_executable>
)

if(CONFIG_CHECK_INIT_PRIORITIES)
add_custom_target(
check_init_priorities
ALL
COMMAND ${check_init_priorities_command}
DEPENDS ${check_init_priorities_dependencies}
)
endif()
endif()

if(NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang")
add_custom_target(
initlevels
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/check_init_priorities.py
--elf-file=${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME}
--initlevels
DEPENDS ${logical_target_for_zephyr_elf}
COMMAND ${check_init_priorities_command} --initlevels
DEPENDS ${check_init_priorities_dependencies}
USES_TERMINAL
)
endif()
Expand Down
4 changes: 3 additions & 1 deletion Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,9 @@ config BUILD_OUTPUT_STRIP_PATHS
config CHECK_INIT_PRIORITIES
bool "Build time initialization priorities check"
default y
depends on !NATIVE_LIBRARY
# If we are building a native_simulator target, we can only check the init priorities
# if we are building the final output but we are not assembling several images together
depends on !(NATIVE_LIBRARY && (!BUILD_OUTPUT_EXE || NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS != ""))
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "armclang"
help
Check the build for initialization priority issues by comparing the
Expand Down

0 comments on commit 9bb708e

Please sign in to comment.