2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-12-19 16:27:55 +01:00
|
|
|
# *DOCUMENTATION*
|
|
|
|
#
|
|
|
|
# Note that this is *NOT* the top-level CMakeLists.txt. That's in the
|
|
|
|
# application. See the Application Development Primer documentation
|
|
|
|
# for details.
|
|
|
|
#
|
|
|
|
# To see a list of typical targets execute "make usage"
|
|
|
|
# More info can be located in ./README.rst
|
|
|
|
# Comments in this file are targeted only to the developer, do not
|
|
|
|
# expect to learn how to build the kernel reading this file.
|
|
|
|
|
2018-06-04 11:47:45 +02:00
|
|
|
if(NOT DEFINED ZEPHYR_BINARY_DIR)
|
2019-06-18 20:45:40 +02:00
|
|
|
message(FATAL_ERROR "A user error has occurred.
|
2018-06-04 11:47:45 +02:00
|
|
|
cmake was invoked with '${CMAKE_CURRENT_LIST_DIR}' specified as the source directory,
|
|
|
|
but it must be invoked with an application source directory,
|
|
|
|
such as '${CMAKE_CURRENT_LIST_DIR}/samples/hello_world'.
|
|
|
|
Debug variables:
|
|
|
|
CMAKE_CACHEFILE_DIR: ${CMAKE_CACHEFILE_DIR}
|
|
|
|
")
|
|
|
|
endif()
|
|
|
|
|
2019-06-01 00:37:40 +02:00
|
|
|
|
|
|
|
# See https://gitlab.kitware.com/cmake/cmake/issues/16228
|
|
|
|
# and https://cmake.org/pipermail/cmake/2019-May/thread.html#69496
|
|
|
|
if(NOT ZEPHYR_BASE STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
message(WARNING "ZEPHYR_BASE doesn't match CMAKE_CURRENT_SOURCE_DIR
|
|
|
|
ZEPHYR_BASE = ${ZEPHYR_BASE}
|
|
|
|
PWD = $ENV{PWD}
|
|
|
|
CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
You may be using a mix of symbolic links and real paths which causes \
|
|
|
|
subtle and hard to debug CMake issues.")
|
|
|
|
endif()
|
|
|
|
# For Zephyr more specifically this breaks (at least)
|
|
|
|
# -fmacro-prefix-map=${ZEPHYR_BASE}=
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-06-14 01:15:44 +02:00
|
|
|
# In some cases the "final" things are not used at all and "_prebuilt"
|
|
|
|
# is the last station. See "logical_target_for_zephyr_elf" below for
|
|
|
|
# details.
|
2017-10-27 15:43:34 +02:00
|
|
|
set(CMAKE_EXECUTABLE_SUFFIX .elf)
|
2021-10-20 12:19:28 +02:00
|
|
|
|
|
|
|
# Zephyr build system will use a dynamic number of linking stages based on build
|
|
|
|
# configuration.
|
|
|
|
#
|
|
|
|
# Currently up to three linking stages may be executed:
|
|
|
|
# zephyr_pre0: First linking stage
|
|
|
|
# zephyr_pre1: Second linking stage
|
|
|
|
# zephyr_final: Final linking stage
|
|
|
|
#
|
|
|
|
# There will at minimum be a single linking stage.
|
|
|
|
# When only a single linking stage is required, the `zephyr_pre0` will be mapped
|
|
|
|
# into the `zephyr_final` target.
|
|
|
|
#
|
|
|
|
# Multiple linking stages are required in the following cases:
|
2023-06-14 14:30:41 +02:00
|
|
|
# - device dependencies structs must be generated (CONFIG_DEVICE_DEPS=y)
|
2021-10-20 12:19:28 +02:00
|
|
|
# - ISR tables must be generated (CONFIG_GEN_ISR_TABLES=y)
|
|
|
|
# - Kernel objects hash tables (CONFIG_USERSPACE=y)
|
|
|
|
# - Application memory partitions (CONFIG_USERSPACE=y)
|
|
|
|
#
|
|
|
|
# Some generators require that memory locations has been fixed, thus those are
|
|
|
|
# placed at the second linking stage.
|
|
|
|
#
|
|
|
|
# When all three linking stages are active, then the following properties applies:
|
|
|
|
# - zephyr_pre0: linker sections may resize / addresses may relocate
|
|
|
|
# - zephyr_pre1: All linker section sizes are fixed, addresses cannot change
|
|
|
|
# - zephyr_final: Final image.
|
|
|
|
#
|
|
|
|
set(ZEPHYR_CURRENT_LINKER_PASS 0)
|
|
|
|
set(ZEPHYR_CURRENT_LINKER_CMD linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}.cmd)
|
|
|
|
set(ZEPHYR_LINK_STAGE_EXECUTABLE zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS})
|
|
|
|
|
|
|
|
# ZEPHYR_PREBUILT_EXECUTABLE is used outside of this file, therefore keep the
|
|
|
|
# existing variable to allow slowly cleanup of linking stage handling.
|
|
|
|
# Three stage linking active: pre0 -> pre1 -> final, this will correspond to `pre1`
|
|
|
|
# Two stage linking active: pre0 -> final, this will correspond to `pre0`
|
2023-06-14 14:30:41 +02:00
|
|
|
if(CONFIG_USERSPACE OR CONFIG_DEVICE_DEPS)
|
2021-10-20 12:19:28 +02:00
|
|
|
set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_pre1)
|
|
|
|
else()
|
|
|
|
set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_pre0)
|
|
|
|
endif()
|
|
|
|
set(ZEPHYR_FINAL_EXECUTABLE zephyr_final)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-04-29 16:57:37 +02:00
|
|
|
# Set some phony targets to collect dependencies
|
2019-01-14 16:39:33 +01:00
|
|
|
set(OFFSETS_H_TARGET offsets_h)
|
|
|
|
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)
|
2020-03-16 20:48:00 +01:00
|
|
|
set(PARSE_SYSCALLS_TARGET parse_syscalls_target)
|
2019-01-14 16:39:33 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ")
|
2018-12-19 10:40:57 +01:00
|
|
|
set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) # BFD format
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2023-05-25 20:41:48 +02:00
|
|
|
# Contains the list of files with syscall function prototypes.
|
|
|
|
add_library(syscalls_interface INTERFACE)
|
|
|
|
set(syscalls_file_list_output
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_file_list.txt)
|
|
|
|
|
2018-12-19 10:40:57 +01:00
|
|
|
# "zephyr_interface" is a source-less library that encapsulates all the global
|
2017-10-27 15:43:34 +02:00
|
|
|
# compiler options needed by all source files. All zephyr libraries,
|
|
|
|
# including the library named "zephyr" link with this library to
|
|
|
|
# obtain these flags.
|
2018-12-19 10:40:57 +01:00
|
|
|
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#interface-libraries
|
2017-10-27 15:43:34 +02:00
|
|
|
add_library(zephyr_interface INTERFACE)
|
|
|
|
|
2018-12-19 10:40:57 +01:00
|
|
|
# "zephyr" is a catch-all CMake library for source files that can be
|
2017-10-27 15:43:34 +02:00
|
|
|
# built purely with the include paths, defines, and other compiler
|
|
|
|
# flags that come with zephyr_interface.
|
|
|
|
zephyr_library_named(zephyr)
|
|
|
|
|
|
|
|
zephyr_include_directories(
|
|
|
|
include
|
|
|
|
${PROJECT_BINARY_DIR}/include/generated
|
|
|
|
${USERINCLUDE}
|
|
|
|
${STDINCLUDE}
|
|
|
|
)
|
|
|
|
|
2021-06-10 15:38:20 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/linker_script/${ARCH}/linker.cmake OPTIONAL)
|
|
|
|
|
2022-09-14 22:23:15 +02:00
|
|
|
zephyr_include_directories(${SOC_FULL_DIR})
|
2019-01-25 10:14:13 +01:00
|
|
|
|
2022-08-22 16:45:23 +02:00
|
|
|
# Don't inherit compiler flags from the environment
|
|
|
|
foreach(var AFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS)
|
|
|
|
if(DEFINED ENV{${var}})
|
|
|
|
message(WARNING "The environment variable '${var}' was set to $ENV{${var}}, "
|
|
|
|
"but Zephyr ignores flags from the environment. Use 'cmake "
|
|
|
|
"-DEXTRA_${var}=$ENV{${var}}' instead."
|
|
|
|
)
|
|
|
|
unset(ENV{${var}})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
zephyr_compile_definitions(
|
|
|
|
KERNEL
|
|
|
|
__ZEPHYR__=1
|
2018-01-03 18:26:19 +01:00
|
|
|
)
|
|
|
|
|
2022-03-29 21:52:59 +02:00
|
|
|
# Ensure that include/zephyr/toolchain.h includes toolchain/other.h for all off-tree toolchains
|
2021-07-16 11:50:40 +02:00
|
|
|
if(TOOLCHAIN_USE_CUSTOM)
|
|
|
|
zephyr_compile_definitions(__TOOLCHAIN_CUSTOM__)
|
|
|
|
endif()
|
|
|
|
|
2022-08-10 20:06:46 +02:00
|
|
|
# @Intent: Set compiler specific flag for disabling strict aliasing rule
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_strict_aliasing>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_strict_aliasing>>)
|
|
|
|
|
2022-12-22 12:46:04 +01:00
|
|
|
# Extra warnings options for twister run
|
|
|
|
if (CONFIG_COMPILER_WARNINGS_AS_ERRORS)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warnings_as_errors>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,warnings_as_errors>>)
|
|
|
|
zephyr_link_libraries($<TARGET_PROPERTY:linker,warnings_as_errors>)
|
|
|
|
endif()
|
|
|
|
|
2019-01-10 12:07:51 +01:00
|
|
|
# @Intent: Set compiler flags to enable buffer overflow checks in libc functions
|
2022-04-27 04:24:11 +02:00
|
|
|
# @details:
|
|
|
|
# Kconfig.zephyr "Detect buffer overflows in libc calls" is a kconfig choice,
|
|
|
|
# ensuring at most *one* of CONFIG_FORTIFY_SOURCE_{COMPILE_TIME,RUN_TIME} is
|
|
|
|
# set. Refer to Kconfig.zephyr for selection logic and description of these
|
|
|
|
# choices. Toolchains set both of the security_fortify_{compile_time,run_time}
|
|
|
|
# properties and the Kconfig settings are used here to select between those.
|
|
|
|
#
|
|
|
|
if(CONFIG_FORTIFY_SOURCE_RUN_TIME)
|
|
|
|
zephyr_compile_definitions($<TARGET_PROPERTY:compiler,security_fortify_run_time> )
|
|
|
|
elseif(CONFIG_FORTIFY_SOURCE_COMPILE_TIME)
|
|
|
|
zephyr_compile_definitions($<TARGET_PROPERTY:compiler,security_fortify_compile_time> )
|
|
|
|
endif()
|
2019-01-10 12:07:51 +01:00
|
|
|
|
|
|
|
# @Intent: Set compiler flags to detect general stack overflows across all functions
|
|
|
|
if(CONFIG_STACK_CANARIES)
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries>)
|
2018-01-03 18:26:19 +01:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-01-30 10:12:30 +01:00
|
|
|
# @Intent: Obtain compiler optimizations flags and store in variables
|
|
|
|
# @details:
|
|
|
|
# Kconfig.zephyr "Optimization level" is a kconfig choice, ensuring
|
|
|
|
# only *one* of CONFIG_{NO,DEBUG,SPEED,SIZE}_OPTIMIZATIONS is set.
|
|
|
|
# Refer to Kconfig.zephyr for selection logic and description of these choices.
|
|
|
|
# toolchain_cc_optimize_*() macros must provide the mapping from these kconfigs
|
|
|
|
# to compiler flags. Each macro will store the flags in a CMake variable, whose
|
|
|
|
# name is passed as argument (somewhat like by reference).
|
2017-10-27 15:43:34 +02:00
|
|
|
#
|
2019-01-30 10:12:30 +01:00
|
|
|
# If the user wants to tweak the optimizations, there are two ways:
|
|
|
|
# 1) Using EXTRA_CFLAGS which is applied regardless of kconfig choice, or
|
|
|
|
# 2) Rely on override support being implemented by your toolchain_cc_optimize_*()
|
2017-10-27 15:43:34 +02:00
|
|
|
#
|
2020-08-18 14:47:53 +02:00
|
|
|
get_property(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG TARGET compiler PROPERTY no_optimization)
|
|
|
|
get_property(OPTIMIZE_FOR_DEBUG_FLAG TARGET compiler PROPERTY optimization_debug)
|
|
|
|
get_property(OPTIMIZE_FOR_SPEED_FLAG TARGET compiler PROPERTY optimization_speed)
|
|
|
|
get_property(OPTIMIZE_FOR_SIZE_FLAG TARGET compiler PROPERTY optimization_size)
|
2018-01-24 10:40:32 +01:00
|
|
|
|
2019-01-30 10:12:30 +01:00
|
|
|
# From kconfig choice, pick the actual OPTIMIZATION_FLAG to use.
|
|
|
|
# Kconfig choice ensures only one of these CONFIG_*_OPTIMIZATIONS is set.
|
2018-01-22 15:35:54 +01:00
|
|
|
if(CONFIG_NO_OPTIMIZATIONS)
|
2018-01-24 10:40:32 +01:00
|
|
|
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG})
|
|
|
|
elseif(CONFIG_DEBUG_OPTIMIZATIONS)
|
2017-10-27 15:43:34 +02:00
|
|
|
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG})
|
2018-06-16 23:40:04 +02:00
|
|
|
elseif(CONFIG_SPEED_OPTIMIZATIONS)
|
|
|
|
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SPEED_FLAG})
|
2018-01-24 10:40:32 +01:00
|
|
|
elseif(CONFIG_SIZE_OPTIMIZATIONS)
|
2019-01-30 10:12:30 +01:00
|
|
|
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default in kconfig
|
2018-01-24 10:40:32 +01:00
|
|
|
else()
|
2019-01-19 01:15:19 +01:00
|
|
|
assert(0 "Unreachable code. Expected optimization level to have been chosen. See Kconfig.zephyr")
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
2020-02-07 00:48:22 +01:00
|
|
|
if(NOT CONFIG_ARCH_IS_SET)
|
|
|
|
message(WARNING "\
|
|
|
|
None of the CONFIG_<arch> (e.g. CONFIG_X86) symbols are set. \
|
|
|
|
Select one of them from the SOC_SERIES_* symbol or, lacking that, from the \
|
|
|
|
SOC_* symbol.")
|
|
|
|
endif()
|
|
|
|
|
2019-01-30 10:12:30 +01:00
|
|
|
# Apply the final optimization flag(s)
|
|
|
|
zephyr_compile_options(${OPTIMIZATION_FLAG})
|
|
|
|
|
2024-01-30 12:32:32 +01:00
|
|
|
if(CONFIG_LTO)
|
2024-02-27 13:17:37 +01:00
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
|
2024-01-30 12:32:32 +01:00
|
|
|
add_link_options($<TARGET_PROPERTY:linker,lto_arguments>)
|
|
|
|
endif()
|
|
|
|
|
2019-02-18 23:54:30 +01:00
|
|
|
# @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,required>>)
|
2019-02-18 23:54:30 +01:00
|
|
|
|
|
|
|
# @Intent: Obtain compiler specific flags for compiling under different ISO standards of C++
|
2022-12-08 22:16:44 +01:00
|
|
|
if(CONFIG_CPP)
|
2019-05-15 23:01:58 +02:00
|
|
|
# From kconfig choice, pick a single dialect.
|
|
|
|
# Kconfig choice ensures only one of these CONFIG_STD_CPP* is set.
|
|
|
|
if(CONFIG_STD_CPP98)
|
2020-08-18 14:47:53 +02:00
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp98>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp98})
|
2019-05-15 23:01:58 +02:00
|
|
|
elseif(CONFIG_STD_CPP11)
|
2020-08-18 14:47:53 +02:00
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp11>) # Default in kconfig
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp11})
|
2019-05-15 23:01:58 +02:00
|
|
|
elseif(CONFIG_STD_CPP14)
|
2020-08-18 14:47:53 +02:00
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp14>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp14})
|
2019-05-15 23:01:58 +02:00
|
|
|
elseif(CONFIG_STD_CPP17)
|
2020-08-18 14:47:53 +02:00
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp17>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp17})
|
2021-07-14 10:50:21 +02:00
|
|
|
elseif(CONFIG_STD_CPP2A)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp2a>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20})
|
2021-07-09 19:46:46 +02:00
|
|
|
elseif(CONFIG_STD_CPP20)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp20>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20})
|
2021-07-09 19:54:11 +02:00
|
|
|
elseif(CONFIG_STD_CPP2B)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp2b>)
|
2021-09-30 21:01:57 +02:00
|
|
|
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20})
|
2019-05-15 23:01:58 +02:00
|
|
|
else()
|
|
|
|
assert(0 "Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.")
|
|
|
|
endif()
|
2021-09-30 21:01:57 +02:00
|
|
|
set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE)
|
2018-10-23 18:20:51 +02:00
|
|
|
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${STD_CPP_DIALECT_FLAGS}>)
|
2019-05-15 23:01:58 +02:00
|
|
|
endif()
|
2019-02-18 23:54:30 +01:00
|
|
|
|
2022-12-09 11:43:43 +01:00
|
|
|
if(NOT CONFIG_CPP_EXCEPTIONS)
|
2019-02-18 23:54:30 +01:00
|
|
|
# @Intent: Obtain compiler specific flags related to C++ Exceptions
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_exceptions>>)
|
2019-02-18 23:54:30 +01:00
|
|
|
endif()
|
|
|
|
|
2022-12-09 12:06:15 +01:00
|
|
|
if(NOT CONFIG_CPP_RTTI)
|
2019-02-18 23:54:30 +01:00
|
|
|
# @Intent: Obtain compiler specific flags related to C++ Run Time Type Information
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_rtti>>)
|
2019-02-18 23:54:30 +01:00
|
|
|
endif()
|
|
|
|
|
2019-02-27 20:53:18 +01:00
|
|
|
if(CONFIG_MISRA_SANE)
|
2019-05-16 12:53:58 +02:00
|
|
|
# @Intent: Obtain toolchain compiler flags relating to MISRA.
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_misra_sane>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_error_misra_sane>>)
|
2019-02-27 20:53:18 +01:00
|
|
|
endif()
|
|
|
|
|
2020-08-26 18:48:33 +02:00
|
|
|
# This is intend to be temporary. Once we have fixed the violations that
|
|
|
|
# prevents build Zephyr, these flags shall be part of the default flags.
|
|
|
|
if(CONFIG_CODING_GUIDELINE_CHECK)
|
|
|
|
# @Intent: Obtain toolchain compiler flags relating to coding guideline
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_coding_guideline>>)
|
2020-08-26 18:48:33 +02:00
|
|
|
endif()
|
|
|
|
|
2019-06-11 13:55:53 +02:00
|
|
|
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
|
2020-08-13 15:49:46 +02:00
|
|
|
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}")
|
2019-06-11 13:55:53 +02:00
|
|
|
|
2023-02-08 23:56:50 +01:00
|
|
|
if(CONFIG_COMPILER_FREESTANDING)
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
# @Intent: Set compiler specific flag for bare metal freestanding option
|
2022-07-04 17:22:18 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,freestanding>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
endif()
|
2019-06-11 15:56:57 +02:00
|
|
|
|
2022-10-14 00:04:00 +02:00
|
|
|
if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
|
|
|
|
# @Intent: Set compiler specific flag to disable printf-related optimizations
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>)
|
|
|
|
endif()
|
|
|
|
|
2019-06-12 14:56:46 +02:00
|
|
|
# @Intent: Set compiler specific flag for tentative definitions, no-common
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,no_common>)
|
2019-06-12 14:56:46 +02:00
|
|
|
|
2019-07-23 09:00:55 +02:00
|
|
|
# @Intent: Set compiler specific flag for production of debug information
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,debug>)
|
2019-07-23 09:00:55 +02:00
|
|
|
|
2023-03-29 11:11:46 +02:00
|
|
|
if(CONFIG_COMPILER_SAVE_TEMPS)
|
|
|
|
# @Intent: Set compiler specific flag for saving temporary object files
|
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,save_temps>)
|
|
|
|
endif()
|
|
|
|
|
2023-05-05 09:58:12 +02:00
|
|
|
if(NOT CONFIG_COMPILER_TRACK_MACRO_EXPANSION)
|
|
|
|
# @Intent: Set compiler specific flags to not track macro expansion
|
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,no_track_macro_expansion>)
|
|
|
|
endif()
|
|
|
|
|
2021-04-15 17:20:10 +02:00
|
|
|
if(CONFIG_COMPILER_COLOR_DIAGNOSTICS)
|
2021-04-15 17:20:10 +02:00
|
|
|
# @Intent: Set compiler specific flag for diagnostic messages
|
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,diagnostic>)
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
zephyr_compile_options(
|
2017-12-12 18:59:37 +01:00
|
|
|
${TOOLCHAIN_C_FLAGS}
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
|
2019-01-30 21:48:25 +01:00
|
|
|
# @Intent: Obtain compiler specific flags related to assembly
|
2020-08-18 14:47:53 +02:00
|
|
|
# ToDo: Remember to get feedback from Oticon on this, as they might use the `ASM_BASE_FLAG` since this is done this way.
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,required>>)
|
2019-01-30 21:48:25 +01:00
|
|
|
|
2022-03-16 22:07:43 +01:00
|
|
|
# @Intent: Enforce standard integer type correspondence to match Zephyr usage.
|
2019-07-02 22:22:04 +02:00
|
|
|
# (must be after compiler specific flags)
|
2022-06-20 19:18:14 +02:00
|
|
|
if(CONFIG_ENFORCE_ZEPHYR_STDINT)
|
2022-03-29 21:52:59 +02:00
|
|
|
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h")
|
2021-09-12 12:33:15 +02:00
|
|
|
endif()
|
2019-07-02 22:22:04 +02:00
|
|
|
|
2019-01-30 21:48:25 +01:00
|
|
|
# Common toolchain-agnostic assembly flags
|
2017-10-27 15:43:34 +02:00
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:ASM>:-D_ASMLANGUAGE>
|
|
|
|
)
|
|
|
|
|
2019-04-25 15:46:11 +02:00
|
|
|
# @Intent: Set fundamental linker specific flags
|
|
|
|
toolchain_ld_base()
|
2018-11-26 13:48:34 +01:00
|
|
|
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_force_undefined_symbols(
|
|
|
|
_OffsetAbsSyms
|
|
|
|
_ConfigAbsSyms
|
|
|
|
)
|
|
|
|
|
2023-05-26 13:23:43 +02:00
|
|
|
if(NOT CONFIG_NATIVE_BUILD)
|
2019-04-25 16:31:30 +02:00
|
|
|
# @Intent: Set linker specific flags for bare metal target
|
|
|
|
toolchain_ld_baremetal()
|
2017-10-03 16:31:55 +02:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2023-06-07 10:28:22 +02:00
|
|
|
if(CONFIG_CPP AND NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY)
|
2019-04-26 08:43:04 +02:00
|
|
|
# @Intent: Set linker specific flags for C++
|
|
|
|
toolchain_ld_cpp()
|
2018-10-23 18:20:51 +02:00
|
|
|
endif()
|
|
|
|
|
2019-05-16 12:49:31 +02:00
|
|
|
# @Intent: Add the basic toolchain warning flags
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_base>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_base>>)
|
2019-05-06 15:19:27 +02:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# cmake -DW=... settings
|
|
|
|
#
|
|
|
|
# W=1 - warnings that may be relevant and does not occur too often
|
|
|
|
# W=2 - warnings that occur quite often but may still be relevant
|
|
|
|
# W=3 - the more obscure warnings, can most likely be ignored
|
|
|
|
# ==========================================================================
|
2019-05-16 12:49:31 +02:00
|
|
|
# @Intent: Add cmake -DW toolchain supported warnings, if any
|
2017-10-27 15:43:34 +02:00
|
|
|
if(W MATCHES "1")
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_1>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_1>>)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(W MATCHES "2")
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_2>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_2>>)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(W MATCHES "3")
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_3>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_3>>)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
2019-05-16 12:49:31 +02:00
|
|
|
# @Intent: Add extended, more specific, toolchain warning flags
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,warning_extended>)
|
2019-01-25 13:57:03 +01:00
|
|
|
|
2019-05-16 12:58:40 +02:00
|
|
|
# @Intent: Trigger an error when a declaration does not specify a type
|
2020-08-18 14:47:53 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_implicit_int>>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_error_implicit_int>>)
|
2019-05-16 12:58:40 +02:00
|
|
|
|
2022-08-22 17:47:03 +02:00
|
|
|
# @Intent: Do not make position independent code / executable
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_position_independent>>)
|
2023-05-04 13:43:41 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,no_position_independent>>)
|
2023-06-07 10:28:22 +02:00
|
|
|
|
|
|
|
# In case of CONFIG_NATIVE_LIBRARY we also don't want position independent code,
|
|
|
|
# but we cannot tell that to the linker yet as we are first only doing a
|
|
|
|
# relocatable link into a static library
|
|
|
|
zephyr_link_libraries_ifndef(CONFIG_NATIVE_LIBRARY
|
|
|
|
$<TARGET_PROPERTY:linker,no_position_independent>)
|
2022-08-22 17:47:03 +02:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Allow the user to inject options when calling cmake, e.g.
|
|
|
|
# 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..'
|
2017-11-10 12:22:23 +01:00
|
|
|
include(cmake/extra_flags.cmake)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
zephyr_cc_option(-fno-asynchronous-unwind-tables)
|
|
|
|
|
2023-01-22 21:47:36 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,no_global_merge>)
|
|
|
|
endif()
|
|
|
|
|
2020-09-28 20:27:11 +02:00
|
|
|
if(CONFIG_THREAD_LOCAL_STORAGE)
|
|
|
|
# Only support local exec TLS model at this point.
|
|
|
|
zephyr_cc_option(-ftls-model=local-exec)
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
if(CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT)
|
|
|
|
if(CONFIG_OMIT_FRAME_POINTER)
|
|
|
|
zephyr_cc_option(-fomit-frame-pointer)
|
|
|
|
else()
|
|
|
|
zephyr_cc_option(-fno-omit-frame-pointer)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-02-27 08:28:25 +01:00
|
|
|
separate_arguments(COMPILER_OPT_AS_LIST UNIX_COMMAND ${CONFIG_COMPILER_OPT})
|
|
|
|
zephyr_compile_options(${COMPILER_OPT_AS_LIST})
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
# TODO: Include arch compiler options at this point.
|
|
|
|
|
2023-01-21 00:21:23 +01:00
|
|
|
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
|
2023-03-16 15:58:27 +01:00
|
|
|
NOT CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM" AND
|
|
|
|
NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang")
|
2019-05-06 15:21:58 +02:00
|
|
|
# GCC assumed
|
|
|
|
zephyr_cc_option(-fno-reorder-functions)
|
2017-12-12 18:59:37 +01:00
|
|
|
|
2022-08-15 15:44:06 +02:00
|
|
|
# GCC 11 and above may generate a warning when dereferencing a constant
|
|
|
|
# address pointer whose address is below the value specified by the
|
|
|
|
# `min-pagesize` parameter (defaults to 0x1000). The `min-pagesize` parameter
|
|
|
|
# is set to 0 such that GCC never generates any warnings for the constant
|
|
|
|
# address pointers. For more details, refer to the GCC PR99578.
|
|
|
|
zephyr_cc_option(--param=min-pagesize=0)
|
|
|
|
|
2018-02-11 21:36:21 +01:00
|
|
|
if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc")
|
2017-10-27 15:43:34 +02:00
|
|
|
zephyr_cc_option(-fno-defer-pop)
|
|
|
|
endif()
|
2022-04-06 19:36:40 +02:00
|
|
|
else()
|
|
|
|
# Clang produces false positive vla warnings
|
|
|
|
zephyr_cc_option(-Wno-vla)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage)
|
|
|
|
|
2019-04-12 01:34:04 +02:00
|
|
|
# If the compiler supports it, strip the ${ZEPHYR_BASE} prefix from the
|
|
|
|
# __FILE__ macro used in __ASSERT*, in the
|
|
|
|
# .noinit."/home/joe/zephyr/fu/bar.c" section names and in any
|
|
|
|
# application code. This saves some memory, stops leaking user locations
|
|
|
|
# in binaries, makes failure logs more deterministic and most
|
|
|
|
# importantly makes builds more deterministic
|
2023-03-29 16:06:30 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_STRIP_PATHS)
|
|
|
|
# If several match then the last one wins. This matters for instances
|
|
|
|
# like tests/ and samples/: they're inside all of them! Then let's
|
|
|
|
# strip as little as possible.
|
|
|
|
zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR)
|
|
|
|
zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE)
|
|
|
|
if(WEST_TOPDIR)
|
|
|
|
zephyr_cc_option(-fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR)
|
|
|
|
endif()
|
2019-06-12 01:57:37 +02:00
|
|
|
endif()
|
2019-04-12 01:34:04 +02:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# TODO: Archiver arguments
|
|
|
|
# ar_option(D)
|
|
|
|
|
2018-11-29 10:08:08 +01:00
|
|
|
# Declare MPU userspace dependencies before the linker scripts to make
|
|
|
|
# sure the order of dependencies are met
|
2019-02-01 00:53:24 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
2021-07-12 22:33:32 +02:00
|
|
|
add_custom_target(app_smem)
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
set(APP_SMEM_ALIGNED_DEP app_smem_aligned_linker)
|
|
|
|
set(APP_SMEM_UNALIGNED_DEP app_smem_unaligned_linker)
|
2018-11-29 10:08:08 +01:00
|
|
|
endif()
|
|
|
|
|
2021-03-18 22:00:07 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
|
|
|
set(KOBJECT_LINKER_DEP kobject_linker)
|
|
|
|
endif()
|
|
|
|
|
2022-02-04 10:27:13 +01:00
|
|
|
if(DEFINED BUILD_VERSION)
|
|
|
|
set(build_version_argument "-DBUILD_VERSION=${BUILD_VERSION}")
|
2022-03-08 20:09:51 +01:00
|
|
|
elseif(NOT ZEPHYR_GIT_INDEX)
|
|
|
|
if(EXISTS ${ZEPHYR_BASE}/.git/index)
|
2023-10-06 12:20:08 +02:00
|
|
|
set(ZEPHYR_GIT_INDEX ${ZEPHYR_BASE}/.git/index CACHE PATH
|
|
|
|
"Path to Zephyr git repository index file")
|
2022-03-08 20:09:51 +01:00
|
|
|
elseif(EXISTS ${ZEPHYR_BASE}/.git)
|
|
|
|
# Likely a git-submodule. Let's ask git where the real database is located.
|
|
|
|
find_package(Git QUIET)
|
|
|
|
if(GIT_FOUND)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} rev-parse --absolute-git-dir
|
|
|
|
WORKING_DIRECTORY ${ZEPHYR_BASE}
|
|
|
|
OUTPUT_VARIABLE zephyr_git_dir
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_VARIABLE stderr
|
|
|
|
RESULT_VARIABLE return_code)
|
|
|
|
if(return_code)
|
|
|
|
message(WARNING "BUILD_VERSION: git rev-parse failed: ${stderr}")
|
|
|
|
else()
|
|
|
|
if(NOT "${stderr}" STREQUAL "")
|
|
|
|
message(WARNING "BUILD_VERSION: git rev-parse warned: ${stderr}")
|
|
|
|
endif()
|
|
|
|
set(ZEPHYR_GIT_INDEX ${zephyr_git_dir}/index CACHE PATH
|
2023-10-06 12:20:08 +02:00
|
|
|
"Path to Zephyr git repository index file")
|
2022-03-08 20:09:51 +01:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(WARNING "Could not find git installation, "
|
|
|
|
"please specify '-DBUILD_VERSION=<version>'")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(WARNING "ZEPHYR_BASE=${ZEPHYR_BASE} doesn't appear to be a git "
|
|
|
|
"repository, please specify '-DBUILD_VERSION=<version>'")
|
|
|
|
endif()
|
2022-02-04 10:27:13 +01:00
|
|
|
endif()
|
2022-03-08 20:09:51 +01:00
|
|
|
|
|
|
|
if(ZEPHYR_GIT_INDEX)
|
|
|
|
set(git_dependency ${ZEPHYR_GIT_INDEX})
|
|
|
|
endif()
|
|
|
|
|
2022-02-04 10:27:13 +01:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h
|
|
|
|
COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
|
|
|
|
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h
|
2023-03-23 08:43:01 +01:00
|
|
|
-DVERSION_TYPE=KERNEL
|
|
|
|
-DVERSION_FILE=${ZEPHYR_BASE}/VERSION
|
2023-09-07 12:47:44 +02:00
|
|
|
-DKERNEL_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:version_h,KERNEL_VERSION_CUSTOMIZATION>"
|
2022-02-04 10:27:13 +01:00
|
|
|
${build_version_argument}
|
|
|
|
-P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake
|
|
|
|
DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency}
|
2023-09-07 12:47:44 +02:00
|
|
|
COMMAND_EXPAND_LISTS
|
2022-02-04 10:27:13 +01:00
|
|
|
)
|
|
|
|
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2023-03-23 08:45:26 +01:00
|
|
|
if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h
|
|
|
|
COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
|
|
|
|
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h
|
|
|
|
-DVERSION_TYPE=APP
|
|
|
|
-DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION
|
2023-09-07 12:47:44 +02:00
|
|
|
-DAPP_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:app_version_h,APP_VERSION_CUSTOMIZATION>"
|
2023-03-23 08:45:26 +01:00
|
|
|
${build_version_argument}
|
|
|
|
-P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake
|
|
|
|
DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency}
|
2023-09-07 12:47:44 +02:00
|
|
|
COMMAND_EXPAND_LISTS
|
2023-03-23 08:45:26 +01:00
|
|
|
)
|
|
|
|
add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h)
|
|
|
|
add_dependencies(zephyr_interface app_version_h)
|
|
|
|
endif()
|
|
|
|
|
2018-01-09 10:52:57 +01:00
|
|
|
# Unfortunately, the order in which CMakeLists.txt code is processed
|
|
|
|
# matters so we need to be careful about how we order the processing
|
|
|
|
# of subdirectories. One example is "Compiler flags added late in the
|
|
|
|
# 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/
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Arch is placed early because it defines important compiler flags
|
|
|
|
# that must be exported to external build systems defined in
|
|
|
|
# e.g. subsys/.
|
|
|
|
add_subdirectory(arch)
|
2017-10-27 15:43:34 +02:00
|
|
|
add_subdirectory(lib)
|
|
|
|
# We use include instead of add_subdirectory to avoid creating a new directory scope.
|
|
|
|
# This is because source file properties are directory scoped, including the GENERATED
|
|
|
|
# property which is set implicitly for custom command outputs
|
|
|
|
include(misc/generated/CMakeLists.txt)
|
2018-09-03 22:20:14 +02:00
|
|
|
|
2023-08-11 22:40:05 +02:00
|
|
|
add_subdirectory(soc)
|
2017-10-27 15:43:34 +02:00
|
|
|
add_subdirectory(boards)
|
|
|
|
add_subdirectory(subsys)
|
|
|
|
add_subdirectory(drivers)
|
|
|
|
|
2019-03-19 10:38:18 +01:00
|
|
|
# Include zephyr modules generated CMake file.
|
2020-08-24 11:01:04 +02:00
|
|
|
foreach(module_name ${ZEPHYR_MODULE_NAMES})
|
|
|
|
# Note the second, binary_dir parameter requires the added
|
|
|
|
# subdirectory to have its own, local cmake target(s). If not then
|
|
|
|
# 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
|
2021-01-19 12:01:38 +01:00
|
|
|
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name})
|
2020-08-25 13:32:33 +02:00
|
|
|
if(NOT ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "")
|
2024-01-16 19:16:23 +01:00
|
|
|
set(ZEPHYR_CURRENT_MODULE_NAME ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_NAME})
|
2020-08-25 13:32:33 +02:00
|
|
|
set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR})
|
|
|
|
set(ZEPHYR_CURRENT_CMAKE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR})
|
|
|
|
add_subdirectory(${ZEPHYR_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name})
|
|
|
|
endif()
|
2020-08-24 11:01:04 +02:00
|
|
|
endforeach()
|
2024-01-16 19:16:23 +01:00
|
|
|
# Done processing modules, clear module variables
|
|
|
|
set(ZEPHYR_CURRENT_MODULE_NAME)
|
2020-08-24 11:01:04 +02:00
|
|
|
set(ZEPHYR_CURRENT_MODULE_DIR)
|
2020-08-25 13:32:33 +02:00
|
|
|
set(ZEPHYR_CURRENT_CMAKE_DIR)
|
2019-02-05 10:36:22 +01:00
|
|
|
|
2022-11-02 22:49:23 +01:00
|
|
|
get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES)
|
|
|
|
zephyr_link_libraries(${LIBC_LINK_LIBRARIES})
|
|
|
|
|
2020-05-29 22:24:51 +02:00
|
|
|
set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
|
|
|
|
set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json)
|
|
|
|
set(struct_tags_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/struct_tags.json)
|
2017-11-20 13:03:55 +01:00
|
|
|
|
2018-06-07 15:50:31 +02:00
|
|
|
# The syscalls subdirs txt file is constructed by python containing a list of folders to use for
|
|
|
|
# dependency handling, including empty folders.
|
|
|
|
# Windows: The list is used to specify DIRECTORY list with CMAKE_CONFIGURE_DEPENDS attribute.
|
|
|
|
# Other OS: The list will update whenever a file is added/removed/modified and ensure a re-build.
|
|
|
|
set(syscalls_subdirs_txt ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.txt)
|
|
|
|
|
|
|
|
# As syscalls_subdirs_txt is updated whenever a file is modified, this file can not be used for
|
|
|
|
# monitoring of added / removed folders. A trigger file is thus used for correct dependency
|
|
|
|
# handling. The trigger file will update when a folder is added / removed.
|
|
|
|
set(syscalls_subdirs_trigger ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.trigger)
|
|
|
|
|
2018-06-14 22:27:17 +02:00
|
|
|
if(NOT (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows))
|
|
|
|
set(syscalls_links --create-links ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_links)
|
|
|
|
endif()
|
|
|
|
|
2018-06-07 15:50:31 +02:00
|
|
|
# When running CMake it must be ensured that all dependencies are correctly acquired.
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:57:02 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/subfolder_list.py
|
2018-06-14 22:27:17 +02:00
|
|
|
--directory ${ZEPHYR_BASE}/include # Walk this directory
|
|
|
|
--out-file ${syscalls_subdirs_txt} # Write file with discovered folder
|
2023-01-04 17:08:36 +01:00
|
|
|
--trigger-file ${syscalls_subdirs_trigger} # Trigger file that is used for json generation
|
2018-06-14 22:27:17 +02:00
|
|
|
${syscalls_links} # If defined, create symlinks for dependencies
|
|
|
|
)
|
2019-07-18 10:38:25 +02:00
|
|
|
file(STRINGS ${syscalls_subdirs_txt} PARSE_SYSCALLS_PATHS_DEPENDS ENCODING UTF-8)
|
2018-06-07 15:50:31 +02:00
|
|
|
|
|
|
|
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
|
|
|
|
# On windows only adding/removing files or folders will be reflected in depends.
|
|
|
|
# Hence adding a file requires CMake to re-run to add this file to the file list.
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS})
|
|
|
|
|
|
|
|
# Also On Windows each header file must be monitored as file modifications are not reflected
|
|
|
|
# on directory level.
|
2018-06-14 20:21:18 +02:00
|
|
|
file(GLOB_RECURSE PARSE_SYSCALLS_HEADER_DEPENDS ${ZEPHYR_BASE}/include/*.h)
|
2018-06-07 15:50:31 +02:00
|
|
|
else()
|
|
|
|
# The syscall parsing depends on the folders in order to detect add/removed/modified files.
|
|
|
|
# When a folder is removed, CMake will try to find a target that creates that dependency.
|
|
|
|
# This command sets up the target for CMake to find.
|
2018-06-14 22:27:17 +02:00
|
|
|
# Without this code, CMake will fail with the following error:
|
2018-06-07 15:50:31 +02:00
|
|
|
# <folder> needed by '<target>', missing and no known rule to make it
|
|
|
|
# when a folder is removed.
|
|
|
|
add_custom_command(OUTPUT ${PARSE_SYSCALLS_PATHS_DEPENDS}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo ""
|
|
|
|
COMMENT "Preparing syscall dependency handling"
|
2018-06-14 22:27:17 +02:00
|
|
|
)
|
2018-06-07 15:50:31 +02:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
2018-06-14 22:27:17 +02:00
|
|
|
${syscalls_subdirs_trigger}
|
2018-06-07 15:50:31 +02:00
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:57:02 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/subfolder_list.py
|
2018-06-14 20:21:18 +02:00
|
|
|
--directory ${ZEPHYR_BASE}/include # Walk this directory
|
2018-06-14 22:27:17 +02:00
|
|
|
--out-file ${syscalls_subdirs_txt} # Write file with discovered folder
|
2023-01-04 17:08:36 +01:00
|
|
|
--trigger-file ${syscalls_subdirs_trigger} # Trigger file that is used for json generation
|
2018-06-14 22:27:17 +02:00
|
|
|
${syscalls_links} # If defined, create symlinks for dependencies
|
2018-06-07 15:50:31 +02:00
|
|
|
DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS}
|
2018-06-14 22:27:17 +02:00
|
|
|
)
|
2018-06-07 15:50:31 +02:00
|
|
|
|
2018-06-14 22:27:17 +02:00
|
|
|
# Ensure subdir file always exists when specifying CMake dependency.
|
|
|
|
if(NOT EXISTS ${syscalls_subdirs_txt})
|
|
|
|
file(WRITE ${syscalls_subdirs_txt} "")
|
2018-06-07 15:50:31 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# On other OS'es, modifying a file is reflected on the folder timestamp and hence detected
|
|
|
|
# when using depend on directory level.
|
|
|
|
# Thus CMake only needs to re-run when sub-directories are added / removed, which is indicated
|
|
|
|
# using a trigger file.
|
2018-06-14 22:27:17 +02:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${syscalls_subdirs_txt})
|
2018-06-07 15:50:31 +02:00
|
|
|
endif()
|
|
|
|
|
2018-04-30 15:59:16 +02:00
|
|
|
# syscall declarations are searched for in the SYSCALL_INCLUDE_DIRS
|
2018-07-02 11:29:19 +02:00
|
|
|
if(CONFIG_APPLICATION_DEFINED_SYSCALL)
|
2018-04-30 15:59:16 +02:00
|
|
|
list(APPEND SYSCALL_INCLUDE_DIRS ${APPLICATION_SOURCE_DIR})
|
2018-07-02 11:29:19 +02:00
|
|
|
endif()
|
|
|
|
|
2019-11-22 08:11:29 +01:00
|
|
|
if(CONFIG_ZTEST)
|
2018-04-30 15:59:16 +02:00
|
|
|
list(APPEND SYSCALL_INCLUDE_DIRS ${ZEPHYR_BASE}/subsys/testsuite/ztest/include)
|
2023-05-17 12:28:16 +02:00
|
|
|
|
2023-05-23 10:15:58 +02:00
|
|
|
if(CONFIG_NO_OPTIMIZATIONS AND CONFIG_ZTEST_WARN_NO_OPTIMIZATIONS)
|
|
|
|
message(WARNING "Running tests with CONFIG_NO_OPTIMIZATIONS is generally "
|
|
|
|
"not supported and known to break in many cases due to stack overflow or "
|
|
|
|
"other problems. Please do not file issues about it unless the test is "
|
|
|
|
"specifically tuned to run in this configuration. To disable this warning "
|
|
|
|
"set CONFIG_ZTEST_WARN_NO_OPTIMIZATIONS=n.")
|
2023-05-17 12:28:16 +02:00
|
|
|
endif()
|
|
|
|
|
2019-11-22 08:11:29 +01:00
|
|
|
endif()
|
|
|
|
|
2018-04-30 15:59:16 +02:00
|
|
|
foreach(d ${SYSCALL_INCLUDE_DIRS})
|
|
|
|
list(APPEND parse_syscalls_include_args
|
|
|
|
--include ${d}
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
2017-11-20 13:03:55 +01:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
${syscalls_json}
|
2020-05-29 22:24:51 +02:00
|
|
|
${struct_tags_json}
|
2017-11-20 13:03:55 +01:00
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:58:14 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/parse_syscalls.py
|
2023-05-25 20:41:48 +02:00
|
|
|
--scan ${ZEPHYR_BASE}/include # Read files from this dir
|
|
|
|
--scan ${ZEPHYR_BASE}/drivers # For net sockets
|
|
|
|
--scan ${ZEPHYR_BASE}/subsys/net # More net sockets
|
2018-04-30 15:59:16 +02:00
|
|
|
${parse_syscalls_include_args} # Read files from these dirs also
|
2020-02-29 23:51:42 +01:00
|
|
|
--json-file ${syscalls_json} # Write this file
|
2020-05-29 22:24:51 +02:00
|
|
|
--tag-struct-file ${struct_tags_json} # Write subsystem list to this file
|
2023-05-25 20:41:48 +02:00
|
|
|
--file-list ${syscalls_file_list_output}
|
|
|
|
$<$<BOOL:${CONFIG_EMIT_ALL_SYSCALLS}>:--emit-all-syscalls>
|
2018-06-14 22:27:17 +02:00
|
|
|
DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS}
|
2023-05-25 20:41:48 +02:00
|
|
|
${syscalls_file_list_output} ${syscalls_interface}
|
2017-11-20 13:03:55 +01:00
|
|
|
)
|
|
|
|
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
# Make sure Picolibc is built before the rest of the system; there's no explicit
|
|
|
|
# reference to any of the files as they're all picked up by various compiler
|
|
|
|
# settings
|
|
|
|
if(CONFIG_PICOLIBC_USE_MODULE)
|
|
|
|
set(picolibc_dependency PicolibcBuild)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h} ${picolibc_dependency})
|
2021-02-09 22:27:59 +01:00
|
|
|
|
|
|
|
set_property(TARGET ${SYSCALL_LIST_H_TARGET}
|
|
|
|
APPEND PROPERTY
|
|
|
|
ADDITIONAL_CLEAN_FILES
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscalls
|
|
|
|
)
|
|
|
|
|
2020-03-16 20:48:00 +01:00
|
|
|
add_custom_target(${PARSE_SYSCALLS_TARGET}
|
2020-08-04 18:26:43 +02:00
|
|
|
DEPENDS
|
|
|
|
${syscalls_json}
|
2020-08-04 18:31:48 +02:00
|
|
|
${struct_tags_json}
|
2020-08-04 18:26:43 +02:00
|
|
|
)
|
2019-11-05 18:39:05 +01:00
|
|
|
|
|
|
|
# 64-bit systems do not require special handling of 64-bit system call
|
|
|
|
# parameters or return values, indicate this to the system call boilerplate
|
|
|
|
# generation script.
|
|
|
|
if(CONFIG_64BIT)
|
|
|
|
set(SYSCALL_LONG_REGISTERS_ARG --long-registers)
|
|
|
|
endif()
|
|
|
|
|
2020-03-06 06:14:02 +01:00
|
|
|
if(CONFIG_TIMEOUT_64BIT)
|
2022-03-05 03:21:38 +01:00
|
|
|
set(SYSCALL_SPLIT_TIMEOUT_ARG --split-type k_timeout_t --split-type k_ticks_t)
|
2020-03-06 06:14:02 +01:00
|
|
|
endif()
|
|
|
|
|
2017-11-20 13:03:55 +01:00
|
|
|
add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h}
|
|
|
|
# Also, some files are written to include/generated/syscalls/
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:54:14 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_syscalls.py
|
2017-11-20 13:03:55 +01:00
|
|
|
--json-file ${syscalls_json} # Read this file
|
|
|
|
--base-output include/generated/syscalls # Write to this dir
|
|
|
|
--syscall-dispatch include/generated/syscall_dispatch.c # Write this file
|
2018-07-24 03:10:15 +02:00
|
|
|
--syscall-list ${syscall_list_h}
|
2023-03-10 23:07:59 +01:00
|
|
|
$<$<BOOL:${CONFIG_USERSPACE}>:--gen-mrsh-files>
|
2019-11-05 18:39:05 +01:00
|
|
|
${SYSCALL_LONG_REGISTERS_ARG}
|
2020-03-06 06:14:02 +01:00
|
|
|
${SYSCALL_SPLIT_TIMEOUT_ARG}
|
2017-11-20 13:03:55 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
2020-03-16 20:48:00 +01:00
|
|
|
DEPENDS ${PARSE_SYSCALLS_TARGET}
|
2017-11-20 13:03:55 +01:00
|
|
|
)
|
|
|
|
|
2020-02-29 23:51:42 +01:00
|
|
|
# This is passed into all calls to the gen_kobject_list.py script.
|
2023-01-04 17:08:36 +01:00
|
|
|
set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json})
|
2020-02-29 23:51:42 +01:00
|
|
|
|
2018-04-04 22:50:32 +02:00
|
|
|
set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${DRV_VALIDATION}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:53:29 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
|
2018-04-04 22:50:32 +02:00
|
|
|
--validation-output ${DRV_VALIDATION}
|
2020-02-29 23:51:42 +01:00
|
|
|
${gen_kobject_list_include_args}
|
2018-04-04 22:50:32 +02:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2020-02-29 23:51:42 +01:00
|
|
|
DEPENDS
|
2022-07-11 16:53:29 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
|
2020-03-16 20:48:00 +01:00
|
|
|
${PARSE_SYSCALLS_TARGET}
|
2018-04-04 22:50:32 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
2019-01-14 16:39:33 +01:00
|
|
|
add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION})
|
2018-04-04 22:50:32 +02:00
|
|
|
|
2020-02-12 15:42:09 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/kobj.cmake)
|
2018-04-05 22:59:33 +02:00
|
|
|
gen_kobj(KOBJ_INCLUDE_PATH)
|
2018-04-04 22:50:32 +02:00
|
|
|
|
2020-01-23 15:39:17 +01:00
|
|
|
# Add a pseudo-target that is up-to-date when all generated headers
|
|
|
|
# are up-to-date.
|
|
|
|
|
|
|
|
add_custom_target(zephyr_generated_headers)
|
|
|
|
add_dependencies(zephyr_generated_headers
|
2022-02-04 10:27:13 +01:00
|
|
|
offsets_h version_h
|
2020-01-23 15:39:17 +01:00
|
|
|
)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Generate offsets.c.obj from offsets.c
|
|
|
|
# Generate offsets.h from offsets.c.obj
|
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
set(OFFSETS_LIB offsets)
|
|
|
|
|
2018-11-15 10:37:46 +01:00
|
|
|
set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)
|
|
|
|
|
2019-02-04 12:10:57 +01:00
|
|
|
add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH})
|
2019-10-24 17:08:21 +02:00
|
|
|
target_include_directories(${OFFSETS_LIB} PRIVATE
|
|
|
|
kernel/include
|
|
|
|
${ARCH_DIR}/${ARCH}/include
|
|
|
|
)
|
2024-01-30 12:32:32 +01:00
|
|
|
|
|
|
|
# Make sure that LTO will never be enabled when compiling offsets.c
|
|
|
|
set_source_files_properties(${OFFSETS_C_PATH} PROPERTIES COMPILE_OPTIONS $<TARGET_PROPERTY:compiler,prohibit_lto>)
|
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
|
2020-08-04 18:31:48 +02:00
|
|
|
add_dependencies(zephyr_interface
|
2019-01-14 16:39:33 +01:00
|
|
|
${SYSCALL_LIST_H_TARGET}
|
|
|
|
${DRIVER_VALIDATION_H_TARGET}
|
|
|
|
${KOBJ_TYPES_H_TARGET}
|
2017-11-20 13:03:55 +01:00
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OFFSETS_H_PATH}
|
2022-07-11 16:53:45 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_offset_header.py
|
2019-02-04 12:10:57 +01:00
|
|
|
-i $<TARGET_OBJECTS:${OFFSETS_LIB}>
|
2017-10-27 15:43:34 +02:00
|
|
|
-o ${OFFSETS_H_PATH}
|
2019-08-15 14:45:59 +02:00
|
|
|
DEPENDS
|
|
|
|
${OFFSETS_LIB}
|
|
|
|
$<TARGET_OBJECTS:${OFFSETS_LIB}>
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
2019-01-14 16:39:33 +01:00
|
|
|
add_custom_target(${OFFSETS_H_TARGET} DEPENDS ${OFFSETS_H_PATH})
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-01 15:25:06 +01:00
|
|
|
zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
add_subdirectory(kernel)
|
|
|
|
|
2023-05-25 20:41:48 +02:00
|
|
|
get_property(
|
|
|
|
syscalls_file_list
|
|
|
|
TARGET syscalls_interface
|
|
|
|
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
|
|
|
)
|
|
|
|
file(CONFIGURE OUTPUT ${syscalls_file_list_output}
|
|
|
|
CONTENT "@syscalls_file_list@" @ONLY)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Read list content
|
|
|
|
get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS)
|
|
|
|
|
|
|
|
foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
|
2021-04-14 17:11:39 +02:00
|
|
|
get_property(lib_type TARGET ${zephyr_lib} PROPERTY TYPE)
|
|
|
|
# To prevent CMake failure when a driver is enabled, for example: REGULATOR=y
|
|
|
|
# we disable any Zephyr libraries without sources and adds the `empty_file.c`.
|
|
|
|
if(${lib_type} STREQUAL STATIC_LIBRARY
|
|
|
|
AND NOT ${zephyr_lib} STREQUAL app
|
|
|
|
)
|
2021-04-23 09:09:49 +02:00
|
|
|
get_property(source_list TARGET ${zephyr_lib} PROPERTY SOURCES)
|
|
|
|
get_property(lib_imported TARGET ${zephyr_lib} PROPERTY IMPORTED)
|
|
|
|
if(NOT source_list
|
|
|
|
AND NOT ${lib_imported}
|
2021-04-14 17:11:39 +02:00
|
|
|
)
|
2021-09-06 16:42:21 +02:00
|
|
|
get_property(allow_empty TARGET ${zephyr_lib} PROPERTY ALLOW_EMPTY)
|
|
|
|
if(NOT "${allow_empty}")
|
|
|
|
message(WARNING
|
|
|
|
"No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build."
|
|
|
|
)
|
|
|
|
endif()
|
2021-04-23 09:09:49 +02:00
|
|
|
target_sources(${zephyr_lib} PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c)
|
|
|
|
set_property(TARGET ${zephyr_lib} PROPERTY EXCLUDE_FROM_ALL TRUE)
|
|
|
|
list(REMOVE_ITEM ZEPHYR_LIBS_PROPERTY ${zephyr_lib})
|
|
|
|
continue()
|
|
|
|
endif()
|
2021-04-14 17:11:39 +02:00
|
|
|
endif()
|
2021-04-23 09:09:49 +02:00
|
|
|
|
|
|
|
# TODO: Could this become an INTERFACE property of zephyr_interface?
|
|
|
|
add_dependencies(${zephyr_lib} zephyr_generated_headers)
|
2017-10-27 15:43:34 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)
|
|
|
|
|
2018-11-13 11:04:02 +01:00
|
|
|
if (CONFIG_CODE_DATA_RELOCATION)
|
|
|
|
set(CODE_RELOCATION_DEP code_relocation_source_lib)
|
|
|
|
endif() # CONFIG_CODE_DATA_RELOCATION
|
2017-12-31 10:39:23 +01:00
|
|
|
|
2021-03-19 20:09:05 +01:00
|
|
|
# Give the linker script targets all of the include directories so
|
|
|
|
# that cmake can successfully find the linker scripts' header
|
2017-12-14 13:03:23 +01:00
|
|
|
# dependencies.
|
|
|
|
zephyr_get_include_directories_for_lang(C
|
|
|
|
ZEPHYR_INCLUDE_DIRS
|
|
|
|
STRIP_PREFIX # Don't use a -I prefix
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2023-06-14 14:30:41 +02:00
|
|
|
if(CONFIG_DEVICE_DEPS)
|
2023-06-14 12:57:29 +02:00
|
|
|
if(CONFIG_DEVICE_DEPS_DYNAMIC)
|
2023-06-14 17:12:55 +02:00
|
|
|
set(dynamic_deps --dynamic-deps)
|
2023-06-14 10:15:12 +02:00
|
|
|
endif()
|
|
|
|
|
2023-06-14 10:24:51 +02:00
|
|
|
if(CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC)
|
|
|
|
set(number_of_dynamic_devices ${CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM})
|
|
|
|
else()
|
|
|
|
set(number_of_dynamic_devices 0)
|
|
|
|
endif()
|
|
|
|
|
2023-06-14 11:51:36 +02:00
|
|
|
# device_deps.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by
|
|
|
|
# gen_device_deps.py
|
2021-04-21 09:06:02 +02:00
|
|
|
add_custom_command(
|
2023-06-14 11:51:36 +02:00
|
|
|
OUTPUT device_deps.c
|
2021-04-21 09:06:02 +02:00
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2023-06-14 11:51:36 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_device_deps.py
|
|
|
|
--output-source device_deps.c
|
2022-07-10 05:46:17 +02:00
|
|
|
--output-graphviz dev_graph.dot
|
2023-06-14 17:12:55 +02:00
|
|
|
${dynamic_deps}
|
2022-01-06 02:19:53 +01:00
|
|
|
--num-dynamic-devices ${number_of_dynamic_devices}
|
2021-10-20 12:19:28 +02:00
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
|
2021-04-21 09:06:02 +02:00
|
|
|
--zephyr-base ${ZEPHYR_BASE}
|
2021-05-21 21:34:58 +02:00
|
|
|
--start-symbol "$<TARGET_PROPERTY:linker,devices_start_symbol>"
|
2022-01-05 11:25:26 +01:00
|
|
|
VERBATIM
|
2021-10-20 12:19:28 +02:00
|
|
|
DEPENDS ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
2021-04-21 09:06:02 +02:00
|
|
|
)
|
2023-06-14 11:51:36 +02:00
|
|
|
set_property(GLOBAL APPEND PROPERTY GENERATED_APP_SOURCE_FILES device_deps.c)
|
2021-10-20 12:19:28 +02:00
|
|
|
|
2023-06-14 12:10:40 +02:00
|
|
|
# gen_device_deps runs on `__device_deps_pass1` so pass this info to the linker script generator
|
|
|
|
list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_DEVICE_DEPS_PASS1")
|
2021-04-21 09:06:02 +02:00
|
|
|
endif()
|
2020-06-30 17:05:35 +02:00
|
|
|
|
2018-11-13 11:04:02 +01:00
|
|
|
if(CONFIG_CODE_DATA_RELOCATION)
|
2019-05-03 10:33:03 +02:00
|
|
|
# @Intent: Linker script to relocate .text, data and .bss sections
|
|
|
|
toolchain_ld_relocation()
|
2018-11-13 11:04:02 +01:00
|
|
|
endif()
|
|
|
|
|
2018-11-21 10:01:56 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
2020-11-20 18:39:30 +01:00
|
|
|
zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv)
|
2020-08-21 19:13:53 +02:00
|
|
|
string(REPLACE "$<TARGET_PROPERTY:compiler,coverage>" ""
|
|
|
|
NO_COVERAGE_FLAGS "${compiler_flags_priv}"
|
|
|
|
)
|
2018-11-21 10:01:56 +01:00
|
|
|
|
2022-07-11 16:53:29 +02:00
|
|
|
set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
|
2022-07-11 16:56:46 +02:00
|
|
|
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
2018-07-05 10:51:03 +02:00
|
|
|
get_property(CSTD GLOBAL PROPERTY CSTD)
|
|
|
|
set_ifndef(CSTD c99)
|
|
|
|
|
2019-06-13 15:33:03 +02:00
|
|
|
# @Intent: Obtain compiler specific flag for specifying the c standard
|
2018-07-05 10:51:03 +02:00
|
|
|
zephyr_compile_options(
|
2020-08-18 14:47:53 +02:00
|
|
|
$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,cstd>${CSTD}>
|
2018-07-05 10:51:03 +02:00
|
|
|
)
|
2021-09-30 21:01:57 +02:00
|
|
|
set(CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}} PARENT_SCOPE)
|
2018-07-05 10:51:03 +02:00
|
|
|
|
2019-05-03 11:02:56 +02:00
|
|
|
# @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted
|
|
|
|
toolchain_ld_configure_files()
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
|
2023-10-27 21:49:16 +02:00
|
|
|
get_property(TOPT GLOBAL PROPERTY TOPT)
|
|
|
|
get_property(COMPILER_TOPT TARGET compiler PROPERTY linker_script)
|
|
|
|
set_ifndef( TOPT "${COMPILER_TOPT}")
|
|
|
|
set_ifndef( TOPT -Wl,-T) # Use this if the compiler driver doesn't set a value
|
|
|
|
|
|
|
|
if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT)
|
|
|
|
set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT})
|
|
|
|
if(NOT EXISTS ${LINKER_SCRIPT})
|
|
|
|
set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT})
|
|
|
|
assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT)
|
|
|
|
endif()
|
|
|
|
elseif(DEFINED BOARD_LINKER_SCRIPT)
|
|
|
|
set(LINKER_SCRIPT ${BOARD_LINKER_SCRIPT})
|
|
|
|
elseif(DEFINED SOC_LINKER_SCRIPT)
|
|
|
|
set(LINKER_SCRIPT ${SOC_LINKER_SCRIPT})
|
|
|
|
else()
|
|
|
|
find_package(Deprecated COMPONENTS SEARCHED_LINKER_SCRIPT)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT EXISTS ${LINKER_SCRIPT})
|
|
|
|
message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?")
|
|
|
|
endif()
|
|
|
|
|
2019-02-23 01:08:44 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld")
|
|
|
|
set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld")
|
2021-07-12 22:33:32 +02:00
|
|
|
|
|
|
|
if(CONFIG_LINKER_USE_PINNED_SECTION)
|
|
|
|
set(APP_SMEM_PINNED_ALIGNED_LD
|
2021-10-20 12:19:28 +02:00
|
|
|
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_aligned.ld")
|
2021-07-12 22:33:32 +02:00
|
|
|
set(APP_SMEM_PINNED_UNALIGNED_LD
|
2021-10-20 12:19:28 +02:00
|
|
|
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_unaligned.ld")
|
2021-07-12 22:33:32 +02:00
|
|
|
|
|
|
|
if(NOT CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT)
|
|
|
|
# The libc partition may hold symbols that are required during boot process,
|
|
|
|
# for example, stack guard (if enabled). So the libc partition must be pinned
|
|
|
|
# if not sections are in physical memory at boot, as the paging mechanism is
|
|
|
|
# only initialized post-kernel.
|
|
|
|
set_property(TARGET app_smem APPEND PROPERTY pinned_partitions "z_libc_partition")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_property(APP_SMEM_PINNED_PARTITION_LIST TARGET app_smem PROPERTY pinned_partitions)
|
|
|
|
if(APP_SMEM_PINNED_PARTITION_LIST)
|
|
|
|
list(JOIN APP_SMEM_PINNED_PARTITION_LIST "," APP_SMEM_PINNED_PARTITION_LIST_ARG_CSL)
|
|
|
|
set(APP_SMEM_PINNED_PARTITION_LIST_ARG "--pinpartitions=${APP_SMEM_PINNED_PARTITION_LIST_ARG_CSL}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-12-20 11:17:42 +01:00
|
|
|
set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../")
|
2018-02-01 08:12:32 +01:00
|
|
|
|
2019-02-01 21:18:31 +01:00
|
|
|
if(CONFIG_NEWLIB_LIBC)
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
set(LIBC_PART -l libc.a z_libc_partition -l libm.a z_libc_partition)
|
2019-02-01 21:18:31 +01:00
|
|
|
endif()
|
2019-11-15 14:07:51 +01:00
|
|
|
if(CONFIG_NEWLIB_LIBC_NANO)
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
set(LIBC_PART -l libc_nano.a z_libc_partition -l libm_nano.a z_libc_partition)
|
|
|
|
endif()
|
|
|
|
if(CONFIG_PICOLIBC)
|
|
|
|
set(LIBC_PART -l libc.a z_libc_partition)
|
2019-11-15 14:07:51 +01:00
|
|
|
endif()
|
2019-02-27 23:41:45 +01:00
|
|
|
|
2018-12-20 11:17:42 +01:00
|
|
|
add_custom_command(
|
2021-07-12 22:33:32 +02:00
|
|
|
OUTPUT ${APP_SMEM_UNALIGNED_LD} ${APP_SMEM_PINNED_UNALIGNED_LD}
|
2018-12-20 11:17:42 +01:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
2022-07-11 16:46:17 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_app_partitions.py
|
2021-11-24 15:35:47 +01:00
|
|
|
-f ${CMAKE_BINARY_DIR}/compile_commands.json
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
-o ${APP_SMEM_UNALIGNED_LD}
|
2021-07-12 22:33:32 +02:00
|
|
|
$<$<BOOL:${APP_SMEM_PINNED_UNALIGNED_LD}>:--pinoutput=${APP_SMEM_PINNED_UNALIGNED_LD}>
|
|
|
|
${APP_SMEM_PINNED_PARTITION_LIST_ARG}
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
${LIBC_PART}
|
2019-11-04 14:30:24 +01:00
|
|
|
$<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS>
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS
|
|
|
|
kernel
|
2022-08-12 01:45:57 +02:00
|
|
|
${CMAKE_BINARY_DIR}/compile_commands.json
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
${ZEPHYR_LIBS_PROPERTY}
|
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/
|
2019-11-04 14:30:24 +01:00
|
|
|
COMMAND_EXPAND_LISTS
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
COMMENT "Generating app_smem_unaligned linker section"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
2021-10-20 12:19:28 +02:00
|
|
|
${APP_SMEM_ALIGNED_DEP}
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
DEPENDS
|
2021-10-20 12:19:28 +02:00
|
|
|
${APP_SMEM_ALIGNED_LD}
|
|
|
|
${APP_SMEM_PINNED_ALIGNED_LD}
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
)
|
|
|
|
|
2021-10-20 12:19:28 +02:00
|
|
|
add_custom_target(
|
|
|
|
${APP_SMEM_UNALIGNED_DEP}
|
|
|
|
DEPENDS
|
|
|
|
${APP_SMEM_UNALIGNED_LD}
|
|
|
|
${APP_SMEM_PINNED_UNALIGNED_LD}
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib)
|
2021-10-20 12:19:28 +02:00
|
|
|
list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_APP_SMEM_UNALIGNED")
|
|
|
|
endif()
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
|
2021-10-20 12:19:28 +02:00
|
|
|
if (CONFIG_USERSPACE)
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
add_custom_command(
|
2021-07-12 22:33:32 +02:00
|
|
|
OUTPUT ${APP_SMEM_ALIGNED_LD} ${APP_SMEM_PINNED_ALIGNED_LD}
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
2022-07-11 16:46:17 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_app_partitions.py
|
2021-10-20 12:19:28 +02:00
|
|
|
-e $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
-o ${APP_SMEM_ALIGNED_LD}
|
2021-07-12 22:33:32 +02:00
|
|
|
$<$<BOOL:${APP_SMEM_PINNED_ALIGNED_LD}>:--pinoutput=${APP_SMEM_PINNED_ALIGNED_LD}>
|
|
|
|
${APP_SMEM_PINNED_PARTITION_LIST_ARG}
|
lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-27 03:07:50 +01:00
|
|
|
${LIBC_PART}
|
2019-11-04 14:30:24 +01:00
|
|
|
$<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS>
|
2018-12-20 11:17:42 +01:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2019-02-08 15:49:57 +01:00
|
|
|
DEPENDS
|
|
|
|
kernel
|
|
|
|
${ZEPHYR_LIBS_PROPERTY}
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
2018-12-20 11:17:42 +01:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/
|
2019-11-04 14:30:24 +01:00
|
|
|
COMMAND_EXPAND_LISTS
|
linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.
For example, tests/subsys/jwt and board mps2_an385:
z_test_mem_partition: addr 0x20000000, size 52
z_libc_partition : addr 0x20000040, size 4
k_mbedtls_partition : addr 0x20008000, size 32736
ending at 0x2000ffff, taking up 65536 bytes
With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.
After the changes here, the partitions are:
k_mbedtls_partition : addr 0x20000000, size 32736
z_test_mem_partition: addr 0x20008000, size 52
z_libc_partition : addr 0x20008040, size 4
ending at 0x2000805f, taking up 32864 bytes
With the above example, sorting results in a saving
of 32672 bytes of saving.
Fixes #14121
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-10 22:20:21 +01:00
|
|
|
COMMENT "Generating app_smem_aligned linker section"
|
2018-12-20 11:17:42 +01:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-03-18 22:00:07 +01:00
|
|
|
if(CONFIG_USERSPACE)
|
|
|
|
# This CONFIG_USERSPACE block is to create place holders to reserve space
|
|
|
|
# for the gperf generated structures for zephyr_prebuilt.elf.
|
|
|
|
# These place holders are there so that the placement of kobjects would be
|
|
|
|
# the same between linking zephyr_prebuilt.elf and zephyr.elf, as
|
|
|
|
# the gperf hash table is hashed on the addresses of kobjects.
|
|
|
|
# The placeholders are generated from app_smem_unaligned_prebuilt.elf.
|
|
|
|
|
|
|
|
set(KOBJECT_PREBUILT_HASH_LIST kobject_prebuilt_hash.gperf)
|
|
|
|
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE kobject_prebuilt_hash_preprocessed.c)
|
|
|
|
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC kobject_prebuilt_hash.c)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_PREBUILT_HASH_LIST}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${GEN_KOBJ_LIST}
|
2021-10-20 12:19:28 +02:00
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
|
2021-03-18 22:00:07 +01:00
|
|
|
--gperf-output ${KOBJECT_PREBUILT_HASH_LIST}
|
|
|
|
${gen_kobject_list_include_args}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
2021-03-18 22:00:07 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_prebuilt_hash_list
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_LIST}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
COMMAND
|
|
|
|
${GPERF}
|
|
|
|
--output-file ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
--multiple-iterations 10
|
|
|
|
${KOBJECT_PREBUILT_HASH_LIST}
|
|
|
|
DEPENDS kobj_prebuilt_hash_list ${KOBJECT_PREBUILT_HASH_LIST}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_prebuilt_hash_output_src_pre
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${PROCESS_GPERF}
|
|
|
|
-i ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
-o ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
2023-09-26 23:37:25 +02:00
|
|
|
-p "struct k_object"
|
2021-03-18 22:00:07 +01:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS kobj_prebuilt_hash_output_src_pre ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_prebuilt_hash_output_src
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_library(
|
|
|
|
kobj_prebuilt_hash_output_lib
|
2021-11-02 12:06:05 +01:00
|
|
|
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
2021-03-18 22:00:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
|
|
|
PROPERTIES COMPILE_FLAGS
|
|
|
|
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
|
|
|
|
|
2021-11-02 12:06:05 +01:00
|
|
|
target_compile_definitions(kobj_prebuilt_hash_output_lib
|
|
|
|
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
|
2021-03-18 22:00:07 +01:00
|
|
|
)
|
|
|
|
|
2021-11-02 12:06:05 +01:00
|
|
|
target_include_directories(kobj_prebuilt_hash_output_lib
|
|
|
|
PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES>
|
|
|
|
)
|
2021-03-18 22:00:07 +01:00
|
|
|
|
2021-11-02 12:06:05 +01:00
|
|
|
target_include_directories(kobj_prebuilt_hash_output_lib SYSTEM
|
|
|
|
PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
|
2021-03-18 22:00:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/linker-kobject-prebuilt-data.h")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_LINKER_HEADER_DATA}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:53:38 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_kobject_placeholders.py
|
2021-11-02 12:06:05 +01:00
|
|
|
--object $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib>
|
2021-03-18 22:00:07 +01:00
|
|
|
--outdir ${PROJECT_BINARY_DIR}/include/generated
|
|
|
|
--datapct ${CONFIG_KOBJECT_DATA_AREA_RESERVE_EXTRA_PERCENT}
|
|
|
|
--rodata ${CONFIG_KOBJECT_RODATA_AREA_EXTRA_BYTES}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS
|
2022-02-03 15:14:44 +01:00
|
|
|
kobj_prebuilt_hash_output_lib $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib>
|
2021-03-18 22:00:07 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
${KOBJECT_LINKER_DEP}
|
|
|
|
DEPENDS
|
|
|
|
${KOBJECT_LINKER_HEADER_DATA}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-06-14 14:30:41 +02:00
|
|
|
if(CONFIG_USERSPACE OR CONFIG_DEVICE_DEPS)
|
2021-10-20 12:19:28 +02:00
|
|
|
configure_linker_script(
|
|
|
|
${ZEPHYR_CURRENT_LINKER_CMD}
|
|
|
|
"${LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE}"
|
|
|
|
${CODE_RELOCATION_DEP}
|
|
|
|
${APP_SMEM_UNALIGNED_DEP}
|
|
|
|
${APP_SMEM_UNALIGNED_LD}
|
|
|
|
${APP_SMEM_PINNED_UNALIGNED_LD}
|
|
|
|
zephyr_generated_headers
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script
|
|
|
|
DEPENDS
|
|
|
|
${ZEPHYR_CURRENT_LINKER_CMD}
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET
|
|
|
|
linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script
|
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(${ZEPHYR_LINK_STAGE_EXECUTABLE} misc/empty_file.c)
|
|
|
|
toolchain_ld_link_elf(
|
|
|
|
TARGET_ELF ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map
|
|
|
|
LIBRARIES_PRE_SCRIPT ""
|
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD}
|
|
|
|
LIBRARIES_POST_SCRIPT ""
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2023-06-07 10:28:22 +02:00
|
|
|
target_link_libraries_ifdef(CONFIG_NATIVE_LIBRARY ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
$<TARGET_PROPERTY:linker,no_position_independent>)
|
2021-10-20 12:19:28 +02:00
|
|
|
target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map
|
|
|
|
)
|
|
|
|
set_property(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD})
|
|
|
|
add_dependencies(${ZEPHYR_LINK_STAGE_EXECUTABLE} linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script ${OFFSETS_LIB})
|
|
|
|
|
|
|
|
math(EXPR ZEPHYR_CURRENT_LINKER_PASS "1 + ${ZEPHYR_CURRENT_LINKER_PASS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(ZEPHYR_CURRENT_LINKER_CMD linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}.cmd)
|
|
|
|
set(ZEPHYR_LINK_STAGE_EXECUTABLE zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS})
|
|
|
|
list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_ZEPHYR_PREBUILT")
|
|
|
|
|
|
|
|
if(CONFIG_GEN_ISR_TABLES)
|
|
|
|
if(CONFIG_GEN_SW_ISR_TABLE)
|
|
|
|
list(APPEND GEN_ISR_TABLE_EXTRA_ARG --sw-isr-table)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_GEN_IRQ_VECTOR_TABLE)
|
|
|
|
list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# isr_tables.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by
|
|
|
|
# gen_isr_tables.py
|
|
|
|
add_custom_command(
|
2023-12-02 23:09:11 +01:00
|
|
|
OUTPUT isr_tables.c isr_tables_vt.ld isr_tables_swi.ld
|
2021-10-20 12:19:28 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
2022-07-11 16:51:50 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/gen_isr_tables.py
|
2021-10-20 12:19:28 +02:00
|
|
|
--output-source isr_tables.c
|
2023-12-02 23:09:11 +01:00
|
|
|
--linker-output-files isr_tables_vt.ld isr_tables_swi.ld
|
2021-10-20 12:19:28 +02:00
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
|
2023-07-26 16:52:21 +02:00
|
|
|
--intlist-section .intList
|
|
|
|
--intlist-section intList
|
2021-10-20 12:19:28 +02:00
|
|
|
$<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian>
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug>
|
|
|
|
${GEN_ISR_TABLE_EXTRA_ARG}
|
|
|
|
DEPENDS ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_USERSPACE)
|
|
|
|
set(KOBJECT_HASH_LIST kobject_hash.gperf)
|
|
|
|
set(KOBJECT_HASH_OUTPUT_SRC_PRE kobject_hash_preprocessed.c)
|
|
|
|
set(KOBJECT_HASH_OUTPUT_SRC kobject_hash.c)
|
|
|
|
set(KOBJECT_HASH_OUTPUT_OBJ_RENAMED kobject_hash_renamed.o)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# linking the hash table back into a now even more nearly finished
|
|
|
|
# elf file. More information in gen_kobject_list.py --help.
|
|
|
|
|
|
|
|
# Use the script GEN_KOBJ_LIST to scan the kernel binary's
|
|
|
|
# (${ZEPHYR_LINK_STAGE_EXECUTABLE}) DWARF information to produce a table of kernel
|
|
|
|
# objects (KOBJECT_HASH_LIST) which we will then pass to gperf
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_HASH_LIST}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${GEN_KOBJ_LIST}
|
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
|
|
|
|
--gperf-output ${KOBJECT_HASH_LIST}
|
|
|
|
${gen_kobject_list_include_args}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS
|
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_hash_list
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_LIST}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Use gperf to generate C code (KOBJECT_HASH_OUTPUT_SRC_PRE) which implements a
|
|
|
|
# perfect hashtable based on KOBJECT_HASH_LIST
|
|
|
|
add_custom_command(
|
2022-02-03 15:14:44 +01:00
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
2021-10-20 12:19:28 +02:00
|
|
|
COMMAND
|
|
|
|
${GPERF}
|
|
|
|
--output-file ${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
--multiple-iterations 10
|
|
|
|
${KOBJECT_HASH_LIST}
|
|
|
|
DEPENDS kobj_hash_list ${KOBJECT_HASH_LIST}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_hash_output_src_pre
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
)
|
|
|
|
|
|
|
|
# For our purposes the code/data generated by gperf is not optimal.
|
|
|
|
#
|
|
|
|
# The script PROCESS_GPERF creates a new c file KOBJECT_HASH_OUTPUT_SRC based on
|
|
|
|
# KOBJECT_HASH_OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated
|
|
|
|
# since we know we are always working with pointer values
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${KOBJECT_HASH_OUTPUT_SRC}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${PROCESS_GPERF}
|
|
|
|
-i ${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
|
|
|
-o ${KOBJECT_HASH_OUTPUT_SRC}
|
2023-09-26 23:37:25 +02:00
|
|
|
-p "struct k_object"
|
2021-10-20 12:19:28 +02:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2022-02-03 15:14:44 +01:00
|
|
|
DEPENDS kobj_hash_output_src_pre ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
2021-10-20 12:19:28 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_hash_output_src
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_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(
|
|
|
|
kobj_hash_output_lib
|
|
|
|
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC}
|
|
|
|
)
|
|
|
|
|
|
|
|
set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC}
|
|
|
|
PROPERTIES COMPILE_FLAGS
|
|
|
|
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
|
|
|
|
|
|
|
|
target_compile_definitions(kobj_hash_output_lib
|
|
|
|
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(kobj_hash_output_lib
|
|
|
|
PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES>
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(kobj_hash_output_lib SYSTEM
|
|
|
|
PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED}
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
2022-12-20 22:29:51 +01:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.literal=.kobject_data.literal
|
2021-10-20 12:19:28 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.data=.kobject_data.data
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.sdata=.kobject_data.sdata
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.text=.kobject_data.text
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.rodata=.kobject_data.rodata
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>$<TARGET_OBJECTS:kobj_hash_output_lib>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KOBJECT_HASH_OUTPUT_OBJ_RENAMED}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
2022-02-03 15:14:44 +01:00
|
|
|
DEPENDS kobj_hash_output_lib $<TARGET_OBJECTS:kobj_hash_output_lib>
|
2021-10-20 12:19:28 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
add_custom_target(
|
|
|
|
kobj_hash_output_obj_renamed
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_library(kobj_hash_output_obj_renamed_lib STATIC IMPORTED GLOBAL)
|
|
|
|
set_property(
|
|
|
|
TARGET kobj_hash_output_obj_renamed_lib
|
|
|
|
PROPERTY
|
|
|
|
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
|
|
|
add_dependencies(
|
|
|
|
kobj_hash_output_obj_renamed_lib
|
|
|
|
kobj_hash_output_obj_renamed
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(
|
|
|
|
GLOBAL APPEND PROPERTY
|
|
|
|
GENERATED_KERNEL_OBJECT_FILES kobj_hash_output_obj_renamed_lib
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-03-19 20:09:05 +01:00
|
|
|
configure_linker_script(
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_CURRENT_LINKER_CMD}
|
|
|
|
"${LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE}"
|
2021-03-19 20:09:05 +01:00
|
|
|
${APP_SMEM_ALIGNED_DEP}
|
2021-03-18 22:00:07 +01:00
|
|
|
${KOBJECT_LINKER_DEP}
|
2021-03-19 20:09:05 +01:00
|
|
|
${CODE_RELOCATION_DEP}
|
|
|
|
zephyr_generated_headers
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
linker_zephyr_prebuilt_script_target
|
|
|
|
DEPENDS
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_CURRENT_LINKER_CMD}
|
2021-03-19 20:09:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET
|
|
|
|
linker_zephyr_prebuilt_script_target
|
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
|
|
|
|
2021-10-20 12:19:28 +02:00
|
|
|
# Read global variables into local variables
|
|
|
|
get_property(GASF GLOBAL PROPERTY GENERATED_APP_SOURCE_FILES)
|
|
|
|
get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES)
|
|
|
|
get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# FIXME: Is there any way to get rid of empty_file.c?
|
2021-10-20 12:19:28 +02:00
|
|
|
add_executable( ${ZEPHYR_LINK_STAGE_EXECUTABLE} misc/empty_file.c ${GASF})
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_link_elf(
|
2021-10-20 12:19:28 +02:00
|
|
|
TARGET_ELF ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_PRE_SCRIPT ""
|
2021-10-20 12:19:28 +02:00
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD}
|
2019-05-07 16:32:36 +02:00
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2023-06-07 10:28:22 +02:00
|
|
|
target_link_libraries_ifdef(CONFIG_NATIVE_LIBRARY ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
$<TARGET_PROPERTY:linker,partial_linking>)
|
2021-10-20 12:19:28 +02:00
|
|
|
target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map
|
2021-02-09 22:27:59 +01:00
|
|
|
)
|
2023-04-13 12:10:08 +02:00
|
|
|
set(BYPRODUCT_KERNEL_ELF_NAME "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}" CACHE FILEPATH "Kernel elf file" FORCE)
|
2021-03-19 20:09:05 +01:00
|
|
|
set_property(TARGET
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
|
|
|
PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD}
|
2021-03-19 20:09:05 +01:00
|
|
|
)
|
|
|
|
add_dependencies(
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
2021-03-19 20:09:05 +01:00
|
|
|
linker_zephyr_prebuilt_script_target
|
|
|
|
${OFFSETS_LIB}
|
|
|
|
)
|
2017-10-03 16:31:55 +02:00
|
|
|
|
2019-04-17 08:30:52 +02:00
|
|
|
set(generated_kernel_files ${GKSF} ${GKOF})
|
|
|
|
if(NOT generated_kernel_files)
|
|
|
|
# Use the prebuilt elf as the final elf since we don't have a
|
|
|
|
# generation stage.
|
2021-10-20 12:19:28 +02:00
|
|
|
set(logical_target_for_zephyr_elf ${ZEPHYR_LINK_STAGE_EXECUTABLE})
|
2019-04-17 08:30:52 +02:00
|
|
|
else()
|
2021-03-19 20:18:52 +01:00
|
|
|
# The final linker pass uses the same source linker script of the
|
|
|
|
# previous passes, but this time with a different output
|
|
|
|
# file and preprocessed with the define LINKER_ZEPHYR_FINAL.
|
2019-04-29 17:16:54 +02:00
|
|
|
configure_linker_script(
|
2021-03-19 20:18:52 +01:00
|
|
|
linker.cmd
|
2021-11-01 12:53:28 +01:00
|
|
|
"LINKER_ZEPHYR_FINAL"
|
2019-02-08 15:49:57 +01:00
|
|
|
${CODE_RELOCATION_DEP}
|
2021-10-20 12:19:28 +02:00
|
|
|
${ZEPHYR_LINK_STAGE_EXECUTABLE}
|
2020-01-23 15:39:17 +01:00
|
|
|
zephyr_generated_headers
|
2019-02-08 15:39:37 +01:00
|
|
|
)
|
2018-02-01 08:12:32 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
add_custom_target(
|
2021-03-19 20:18:52 +01:00
|
|
|
linker_zephyr_final_script_target
|
2017-10-27 15:43:34 +02:00
|
|
|
DEPENDS
|
2021-03-19 20:18:52 +01:00
|
|
|
linker.cmd
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
2017-12-14 13:03:23 +01:00
|
|
|
set_property(TARGET
|
2021-03-19 20:18:52 +01:00
|
|
|
linker_zephyr_final_script_target
|
2017-12-14 13:03:23 +01:00
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-10-20 12:09:39 +02:00
|
|
|
add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${GASF} ${GKSF})
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_link_elf(
|
|
|
|
TARGET_ELF ${ZEPHYR_FINAL_EXECUTABLE}
|
2019-06-14 01:15:44 +02:00
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_FINAL_EXECUTABLE}.map
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_PRE_SCRIPT ${GKOF}
|
2021-03-19 20:18:52 +01:00
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_POST_SCRIPT ""
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2021-03-19 20:18:52 +01:00
|
|
|
set_property(TARGET ${ZEPHYR_FINAL_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd)
|
|
|
|
add_dependencies( ${ZEPHYR_FINAL_EXECUTABLE} linker_zephyr_final_script_target)
|
2019-05-07 15:20:20 +02:00
|
|
|
|
|
|
|
# Use the pass2 elf as the final elf
|
|
|
|
set(logical_target_for_zephyr_elf ${ZEPHYR_FINAL_EXECUTABLE})
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
2018-10-16 13:25:04 +02:00
|
|
|
# Export the variable to the application's scope to allow the
|
|
|
|
# application to know what the name of the final elf target is.
|
|
|
|
set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE)
|
|
|
|
|
2019-06-14 01:15:44 +02:00
|
|
|
# Override the base name of the last, "logical" .elf output (and last .map) so:
|
2019-04-17 08:30:52 +02:00
|
|
|
# 1. it doesn't depend on the number of passes above and the
|
|
|
|
# post_build_commands below can always find it no matter which is it;
|
|
|
|
# 2. it can be defined in Kconfig
|
2017-10-27 15:43:34 +02:00
|
|
|
set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME})
|
|
|
|
|
2017-11-20 15:37:59 +01:00
|
|
|
set(post_build_commands "")
|
2019-05-10 10:06:32 +02:00
|
|
|
set(post_build_byproducts "")
|
2017-11-20 15:37:59 +01:00
|
|
|
|
2019-06-14 01:15:44 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND
|
2022-03-16 13:21:39 +01:00
|
|
|
${CMAKE_COMMAND} -E copy ${logical_target_for_zephyr_elf}.map ${KERNEL_MAP_NAME}
|
2019-06-14 01:15:44 +02:00
|
|
|
)
|
2021-02-09 22:27:59 +01:00
|
|
|
list(APPEND post_build_byproducts ${KERNEL_MAP_NAME})
|
2019-06-14 01:15:44 +02:00
|
|
|
|
2018-11-26 10:47:16 +01:00
|
|
|
if(NOT CONFIG_BUILD_NO_GAP_FILL)
|
|
|
|
# Use ';' as separator to get proper space in resulting command.
|
2020-08-18 14:47:53 +02:00
|
|
|
set(GAP_FILL "$<TARGET_PROPERTY:bintools,elfconvert_flag_gapfill>0xff")
|
2018-11-26 10:47:16 +01:00
|
|
|
endif()
|
|
|
|
|
2019-07-18 15:16:39 +02:00
|
|
|
if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE)
|
2021-02-02 21:06:11 +01:00
|
|
|
target_link_libraries(${logical_target_for_zephyr_elf} $<TARGET_PROPERTY:linker,memusage>)
|
2020-08-18 14:47:53 +02:00
|
|
|
|
|
|
|
get_property(memusage_build_command TARGET bintools PROPERTY memusage_command)
|
|
|
|
if(memusage_build_command)
|
|
|
|
# Note: The use of generator expressions allows downstream extensions to add/change the post build.
|
|
|
|
# Unfortunately, the BYPRODUCTS does not allow for generator expression, so question is if we
|
|
|
|
# should remove the downstream ability from start.
|
|
|
|
# Or fix the output name, by the use of `get_property`
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2020-09-04 21:07:46 +02:00
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,memusage_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,memusage_flag>
|
|
|
|
$<TARGET_PROPERTY:bintools,memusage_infile>${KERNEL_ELF_NAME}
|
2020-08-18 14:47:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# For now, the byproduct can only be supported upstream on byproducts name,
|
|
|
|
# cause byproduct does not support generator expressions
|
|
|
|
get_property(memusage_byproducts TARGET bintools PROPERTY memusage_byproducts)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${memusage_byproducts}
|
|
|
|
)
|
|
|
|
endif()
|
2019-07-18 15:16:39 +02:00
|
|
|
endif()
|
|
|
|
|
2022-01-12 14:21:07 +01:00
|
|
|
if(CONFIG_BUILD_OUTPUT_ADJUST_LMA)
|
|
|
|
math(EXPR adjustment "${CONFIG_BUILD_OUTPUT_ADJUST_LMA}" OUTPUT_FORMAT DECIMAL)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_lma_adjust>${adjustment}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_ELF_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2022-12-09 11:43:43 +01:00
|
|
|
if(NOT CONFIG_CPP_EXCEPTIONS)
|
2022-03-07 11:36:53 +01:00
|
|
|
set(eh_frame_section ".eh_frame")
|
|
|
|
else()
|
|
|
|
set(eh_frame_section "")
|
|
|
|
endif()
|
|
|
|
set(remove_sections_argument_list "")
|
|
|
|
foreach(section .comment COMMON ${eh_frame_section})
|
|
|
|
list(APPEND remove_sections_argument_list
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>${section})
|
|
|
|
endforeach()
|
|
|
|
|
2019-08-13 20:44:20 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd)
|
2020-08-18 14:47:53 +02:00
|
|
|
get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats)
|
|
|
|
if(ihex IN_LIST elfconvert_formats)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
|
|
|
${GAP_FILL}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>ihex
|
2022-03-07 11:36:53 +01:00
|
|
|
${remove_sections_argument_list}
|
2020-08-18 14:47:53 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_HEX_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
2020-08-18 14:47:53 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_HEX_NAME}
|
|
|
|
)
|
2023-04-13 12:10:08 +02:00
|
|
|
set(BYPRODUCT_KERNEL_HEX_NAME "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}" CACHE FILEPATH "Kernel hex file" FORCE)
|
2020-08-18 14:47:53 +02:00
|
|
|
endif()
|
2019-05-10 10:06:32 +02:00
|
|
|
endif()
|
2017-11-23 13:54:26 +01:00
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_BIN)
|
2020-08-18 14:47:53 +02:00
|
|
|
get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats)
|
|
|
|
if(binary IN_LIST elfconvert_formats)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
|
|
|
${GAP_FILL}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary
|
2022-03-07 11:36:53 +01:00
|
|
|
${remove_sections_argument_list}
|
2020-08-18 14:47:53 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_BIN_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
2020-08-18 14:47:53 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_BIN_NAME}
|
|
|
|
)
|
2023-04-13 12:10:08 +02:00
|
|
|
set(BYPRODUCT_KERNEL_BIN_NAME "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}" CACHE FILEPATH "Kernel binary file" FORCE)
|
2020-08-18 14:47:53 +02:00
|
|
|
endif()
|
2019-05-10 10:06:32 +02:00
|
|
|
endif()
|
2017-11-20 15:37:59 +01:00
|
|
|
|
2020-12-31 22:51:52 +01:00
|
|
|
if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2)
|
2022-01-27 06:45:27 +01:00
|
|
|
if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_BASE)
|
|
|
|
set(flash_addr "${CONFIG_FLASH_BASE_ADDRESS}")
|
|
|
|
else()
|
|
|
|
set(flash_addr "${CONFIG_FLASH_LOAD_OFFSET}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_OFFSET)
|
|
|
|
# Note, the `+ 0` in formula below avoids errors in cases where a Kconfig
|
|
|
|
# variable is undefined and thus expands to nothing.
|
|
|
|
math(EXPR flash_addr
|
|
|
|
"${flash_addr} + ${CONFIG_FLASH_LOAD_OFFSET} + 0"
|
|
|
|
OUTPUT_FORMAT HEXADECIMAL
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-12-31 22:51:52 +01:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2022-07-11 16:57:15 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/uf2conv.py
|
2020-12-31 22:51:52 +01:00
|
|
|
-c
|
|
|
|
-f ${CONFIG_BUILD_OUTPUT_UF2_FAMILY_ID}
|
2022-01-27 06:45:27 +01:00
|
|
|
-b ${flash_addr}
|
2020-12-31 22:51:52 +01:00
|
|
|
-o ${KERNEL_UF2_NAME}
|
|
|
|
${KERNEL_BIN_NAME}
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_UF2_NAME}
|
|
|
|
)
|
2023-04-13 12:10:08 +02:00
|
|
|
set(BYPRODUCT_KERNEL_UF2_NAME "${PROJECT_BINARY_DIR}/${KERNEL_UF2_NAME}" CACHE FILEPATH "Kernel uf2 file" FORCE)
|
2020-12-31 22:51:52 +01:00
|
|
|
endif()
|
2020-10-20 20:31:56 +02:00
|
|
|
|
2021-10-12 23:08:36 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_META)
|
2023-12-05 17:41:06 +01:00
|
|
|
set(KERNEL_META_PATH ${PROJECT_BINARY_DIR}/${KERNEL_META_NAME} CACHE INTERNAL "")
|
|
|
|
|
2021-10-12 23:08:36 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/zephyr_module.py
|
|
|
|
${ZEPHYR_MODULES_ARG}
|
2023-05-17 13:59:28 +02:00
|
|
|
${EXTRA_ZEPHYR_MODULES_ARG}
|
2023-12-05 17:41:06 +01:00
|
|
|
--meta-out ${KERNEL_META_PATH}
|
2024-01-17 15:56:59 +01:00
|
|
|
--zephyr-base=${ZEPHYR_BASE}
|
2021-11-04 18:35:50 +01:00
|
|
|
$<$<BOOL:${CONFIG_BUILD_OUTPUT_META_STATE_PROPAGATE}>:--meta-state-propagate>
|
2021-10-12 23:08:36 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
2023-12-05 17:41:06 +01:00
|
|
|
${KERNEL_META_PATH}
|
2021-10-12 23:08:36 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-10-20 20:31:56 +02:00
|
|
|
# Cleanup intermediate files
|
|
|
|
if(CONFIG_CLEANUP_INTERMEDIATE_FILES)
|
2021-11-25 12:23:34 +01:00
|
|
|
foreach(index RANGE ${ZEPHYR_CURRENT_LINKER_PASS})
|
|
|
|
# Those files can be very large in some cases, delete them as we do not need them.
|
2020-10-20 20:31:56 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND
|
2021-11-25 12:23:34 +01:00
|
|
|
${CMAKE_COMMAND} -E remove zephyr_pre${index}.elf
|
2020-10-20 20:31:56 +02:00
|
|
|
)
|
2021-11-25 12:23:34 +01:00
|
|
|
endforeach()
|
2020-10-20 20:31:56 +02:00
|
|
|
endif()
|
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_S19)
|
2020-08-18 14:47:53 +02:00
|
|
|
get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats)
|
|
|
|
if(srec IN_LIST elfconvert_formats)
|
|
|
|
# Should we print a warning if case the tools does not support converting to s19 ?
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
|
|
|
${GAP_FILL}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>srec
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_srec_len>1
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_S19_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
2020-08-18 14:47:53 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_S19_NAME}
|
|
|
|
)
|
2023-04-13 12:10:08 +02:00
|
|
|
set(BYPRODUCT_KERNEL_S19_NAME "${PROJECT_BINARY_DIR}/${KERNEL_S19_NAME}" CACHE FILEPATH "Kernel s19 file" FORCE)
|
2020-08-18 14:47:53 +02:00
|
|
|
endif()
|
2019-05-10 10:06:32 +02:00
|
|
|
endif()
|
2017-11-20 15:37:59 +01:00
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_OUTPUT_DISASSEMBLY)
|
2020-08-18 14:47:53 +02:00
|
|
|
if(CONFIG_OUTPUT_DISASSEMBLE_ALL)
|
|
|
|
set(disassembly_type "$<TARGET_PROPERTY:bintools,disassembly_flag_all>")
|
2020-05-07 06:38:37 +02:00
|
|
|
else()
|
2020-08-18 14:47:53 +02:00
|
|
|
set(disassembly_type "$<TARGET_PROPERTY:bintools,disassembly_flag_inline_source>")
|
2020-05-07 06:38:37 +02:00
|
|
|
endif()
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2020-08-18 14:47:53 +02:00
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,disassembly_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,disassembly_flag>
|
|
|
|
${disassembly_type}
|
2020-08-18 14:46:06 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,disassembly_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,disassembly_flag_outfile>${KERNEL_LST_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,disassembly_flag_final>
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_LST_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-20 15:37:59 +01:00
|
|
|
|
2022-06-27 16:08:37 +02:00
|
|
|
if(CONFIG_OUTPUT_SYMBOLS)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,symbols_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,symbols_flag>
|
|
|
|
$<TARGET_PROPERTY:bintools,symbols_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,symbols_outfile>${KERNEL_SYMBOLS_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,symbols_final>
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_SYMBOLS_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_OUTPUT_STAT)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2020-08-18 14:46:06 +02:00
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,readelf_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,readelf_flag>
|
|
|
|
$<TARGET_PROPERTY:bintools,readelf_flag_headers>
|
2021-05-20 17:38:57 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,readelf_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,readelf_flag_outfile>${KERNEL_STAT_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,readelf_flag_final>
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_STAT_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-20 15:37:59 +01:00
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_STRIPPED)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2020-08-18 14:46:06 +02:00
|
|
|
COMMAND $<TARGET_PROPERTY:bintools,strip_command>
|
|
|
|
$<TARGET_PROPERTY:bintools,strip_flag>
|
|
|
|
$<TARGET_PROPERTY:bintools,strip_flag_all>
|
|
|
|
$<TARGET_PROPERTY:bintools,strip_flag_infile>${KERNEL_ELF_NAME}
|
|
|
|
$<TARGET_PROPERTY:bintools,strip_flag_outfile>${KERNEL_STRIP_NAME}
|
2020-09-04 10:05:00 +02:00
|
|
|
$<TARGET_PROPERTY:bintools,strip_flag_final>
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_STRIP_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_BUILD_OUTPUT_EXE)
|
2023-06-07 10:39:48 +02:00
|
|
|
if (NOT CONFIG_NATIVE_LIBRARY)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME}
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_EXE_NAME}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
|
|
|
|
set(MAKE "${CMAKE_MAKE_PROGRAM}" CACHE FILEPATH "cmake defined make")
|
|
|
|
endif()
|
|
|
|
find_program(MAKE make REQUIRED)
|
|
|
|
add_custom_target(native_runner_executable
|
|
|
|
ALL
|
|
|
|
COMMENT "Building native simulator runner, and linking final executable"
|
|
|
|
COMMAND
|
|
|
|
${MAKE} -f ${ZEPHYR_BASE}/scripts/native_simulator/Makefile all --warn-undefined-variables
|
2023-11-14 15:23:55 +01:00
|
|
|
-r NSI_CONFIG_FILE=${APPLICATION_BINARY_DIR}/zephyr/NSI/nsi_config
|
2023-06-07 10:39:48 +02:00
|
|
|
# nsi_config is created by the board cmake file
|
|
|
|
DEPENDS ${logical_target_for_zephyr_elf}
|
|
|
|
BYPRODUCTS ${KERNEL_EXE_NAME}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
2023-06-07 10:39:48 +02:00
|
|
|
endif()
|
2023-11-23 15:27:09 +01:00
|
|
|
set(BYPRODUCT_KERNEL_EXE_NAME "${PROJECT_BINARY_DIR}/${KERNEL_EXE_NAME}" CACHE FILEPATH "Kernel exe file" FORCE)
|
2019-05-10 10:06:32 +02:00
|
|
|
endif()
|
2017-11-23 13:54:26 +01:00
|
|
|
|
2022-01-10 11:02:26 +01:00
|
|
|
if(CONFIG_BUILD_OUTPUT_INFO_HEADER)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2022-07-11 16:55:13 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_image_info.py
|
2022-01-10 11:02:26 +01:00
|
|
|
--elf-file=${KERNEL_ELF_NAME}
|
|
|
|
--header-file=${PROJECT_BINARY_DIR}/include/public/zephyr_image_info.h
|
2022-01-12 14:21:07 +01:00
|
|
|
$<$<BOOL:${adjustment}>:--adjusted-lma=${adjustment}>
|
2022-01-10 11:02:26 +01:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${PROJECT_BINARY_DIR}/include/public/zephyr_image_info.h
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-11-23 15:27:09 +01:00
|
|
|
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}
|
2023-03-09 18:29:54 +01:00
|
|
|
)
|
2023-11-23 15:27:09 +01:00
|
|
|
endif()
|
2023-03-09 18:29:54 +01:00
|
|
|
|
2023-09-18 13:35:35 +02:00
|
|
|
add_custom_target(
|
|
|
|
initlevels
|
2023-11-23 15:27:09 +01:00
|
|
|
COMMAND ${check_init_priorities_command} --initlevels
|
|
|
|
DEPENDS ${check_init_priorities_dependencies}
|
2023-09-18 13:35:35 +02:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
endif()
|
2023-09-11 17:09:14 +02:00
|
|
|
|
2023-10-13 12:08:32 +02:00
|
|
|
# Generate signed (MCUboot or other) related artifacts as needed. Priority is:
|
|
|
|
# * Sysbuild (if set)
|
|
|
|
# * SIGNING_SCRIPT target property (if set)
|
|
|
|
# * MCUboot signing script (if MCUboot is enabled)
|
|
|
|
zephyr_get(signing_script VAR SIGNING_SCRIPT SYSBUILD)
|
|
|
|
|
|
|
|
if(NOT signing_script)
|
2023-03-23 14:42:33 +01:00
|
|
|
get_target_property(signing_script zephyr_property_target SIGNING_SCRIPT)
|
2023-10-13 12:08:32 +02:00
|
|
|
|
|
|
|
if(NOT signing_script AND CONFIG_BOOTLOADER_MCUBOOT)
|
|
|
|
set(signing_script ${CMAKE_CURRENT_LIST_DIR}/cmake/mcuboot.cmake)
|
2023-03-23 14:42:33 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Include signing script, if set
|
|
|
|
if(signing_script)
|
|
|
|
message(STATUS "Including signing script: ${signing_script}")
|
|
|
|
|
|
|
|
include(${signing_script})
|
2020-08-18 20:28:04 +02:00
|
|
|
endif()
|
|
|
|
|
2022-10-26 15:34:09 +02:00
|
|
|
# Generate USB-C VIF policies in XML format
|
|
|
|
if (CONFIG_BUILD_OUTPUT_VIF)
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/vif.cmake)
|
|
|
|
endif()
|
|
|
|
|
2019-01-25 07:23:13 +01:00
|
|
|
get_property(extra_post_build_commands
|
|
|
|
GLOBAL PROPERTY
|
|
|
|
extra_post_build_commands
|
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
${extra_post_build_commands}
|
|
|
|
)
|
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
get_property(extra_post_build_byproducts
|
|
|
|
GLOBAL PROPERTY
|
|
|
|
extra_post_build_byproducts
|
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${extra_post_build_byproducts}
|
|
|
|
)
|
|
|
|
|
2022-03-29 15:47:01 +02:00
|
|
|
if(CONFIG_LOG_DICTIONARY_DB)
|
2022-01-26 23:44:55 +01:00
|
|
|
set(log_dict_db_output --json=${PROJECT_BINARY_DIR}/log_dictionary.json)
|
2022-02-04 22:18:13 +01:00
|
|
|
elseif(CONFIG_LOG_MIPI_SYST_USE_CATALOG)
|
|
|
|
set(log_dict_db_output --syst=${PROJECT_BINARY_DIR}/mipi_syst_collateral.xml)
|
|
|
|
endif()
|
2021-04-02 21:54:53 +02:00
|
|
|
|
2022-02-04 22:18:13 +01:00
|
|
|
if(log_dict_db_output)
|
2021-04-02 21:54:53 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py
|
|
|
|
${KERNEL_ELF_NAME}
|
2022-01-26 23:44:55 +01:00
|
|
|
${log_dict_db_output}
|
2022-02-04 10:27:13 +01:00
|
|
|
--build-header ${PROJECT_BINARY_DIR}/include/generated/version.h
|
2021-04-02 21:54:53 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${LOG_DICT_DB_NAME}
|
|
|
|
)
|
2022-01-26 23:44:55 +01:00
|
|
|
|
|
|
|
unset(log_dict_db_output)
|
2021-04-02 21:54:53 +02:00
|
|
|
endif()
|
|
|
|
|
2019-04-17 08:30:52 +02:00
|
|
|
# Add post_build_commands to post-process the final .elf file produced by
|
2021-10-20 12:19:28 +02:00
|
|
|
# either the ZEPHYR_LINK_STAGE_EXECUTABLE or the KERNEL_ELF executable
|
2019-04-17 08:30:52 +02:00
|
|
|
# targets above.
|
2017-11-20 15:37:59 +01:00
|
|
|
add_custom_command(
|
|
|
|
TARGET ${logical_target_for_zephyr_elf}
|
|
|
|
POST_BUILD
|
2023-12-06 10:20:34 +01:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Generating files from ${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME} for board: ${BOARD}"
|
2017-11-20 15:37:59 +01:00
|
|
|
${post_build_commands}
|
2019-05-10 10:06:32 +02:00
|
|
|
BYPRODUCTS
|
|
|
|
${post_build_byproducts}
|
2020-08-18 14:47:53 +02:00
|
|
|
COMMAND_EXPAND_LISTS
|
2019-01-25 07:23:13 +01:00
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2018-10-30 08:39:13 +01:00
|
|
|
# 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)
|
|
|
|
if(HEX_FILES_TO_MERGE)
|
|
|
|
# Merge in out-of-tree hex files.
|
2018-12-05 09:32:32 +01:00
|
|
|
set(MERGED_HEX_NAME merged.hex)
|
2018-10-30 08:39:13 +01:00
|
|
|
|
|
|
|
add_custom_command(
|
2018-12-05 09:32:32 +01:00
|
|
|
OUTPUT ${MERGED_HEX_NAME}
|
2018-10-30 08:39:13 +01:00
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2022-07-11 16:55:37 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/build/mergehex.py
|
2018-12-05 09:32:32 +01:00
|
|
|
-o ${MERGED_HEX_NAME}
|
2018-10-30 08:39:13 +01:00
|
|
|
${HEX_FILES_TO_MERGE}
|
|
|
|
DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf}
|
|
|
|
)
|
|
|
|
|
2018-12-05 09:32:32 +01:00
|
|
|
add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME})
|
2020-06-30 09:55:54 +02:00
|
|
|
list(APPEND RUNNERS_DEPS mergehex)
|
2020-01-03 09:25:03 +01:00
|
|
|
|
|
|
|
message(VERBOSE "Merging hex files: ${HEX_FILES_TO_MERGE}")
|
2018-10-30 08:39:13 +01:00
|
|
|
endif()
|
|
|
|
|
2021-08-30 13:09:48 +02:00
|
|
|
if(SUPPORTED_EMU_PLATFORMS)
|
|
|
|
list(GET SUPPORTED_EMU_PLATFORMS 0 default_emu)
|
2022-02-15 04:08:42 +01:00
|
|
|
if(EXISTS ${ZEPHYR_BASE}/cmake/emu/${default_emu}.cmake)
|
|
|
|
add_custom_target(run DEPENDS run_${default_emu})
|
|
|
|
endif()
|
2021-08-30 13:09:48 +02:00
|
|
|
|
|
|
|
foreach(EMU_PLATFORM ${SUPPORTED_EMU_PLATFORMS})
|
2022-02-15 04:08:42 +01:00
|
|
|
if(EXISTS ${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake)
|
|
|
|
include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake)
|
|
|
|
endif()
|
2021-08-30 13:09:48 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(TARGET debugserver_${default_emu})
|
|
|
|
add_custom_target(debugserver DEPENDS debugserver_${default_emu})
|
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
else()
|
|
|
|
add_custom_target(run
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E echo
|
|
|
|
"==================================================="
|
2018-12-19 10:40:57 +01:00
|
|
|
"Emulation/Simulation not supported with this board."
|
2017-12-21 22:45:45 +01:00
|
|
|
"==================================================="
|
|
|
|
)
|
2017-11-22 00:54:55 +01:00
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
add_subdirectory(cmake/flash)
|
|
|
|
add_subdirectory(cmake/usage)
|
|
|
|
add_subdirectory(cmake/reports)
|
|
|
|
|
2019-06-17 22:26:11 +02:00
|
|
|
if(NOT CONFIG_TEST)
|
2018-05-24 22:18:36 +02:00
|
|
|
if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT))
|
2019-12-06 12:54:53 +01:00
|
|
|
message(WARNING "__ASSERT() statements are globally ENABLED")
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2019-06-17 22:26:11 +02:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-01-09 23:20:44 +01:00
|
|
|
if(CONFIG_BOARD_DEPRECATED_RELEASE)
|
2017-10-27 15:43:34 +02:00
|
|
|
message(WARNING "
|
|
|
|
WARNING: The board '${BOARD}' is deprecated and will be
|
2020-01-09 23:20:44 +01:00
|
|
|
removed in version ${CONFIG_BOARD_DEPRECATED_RELEASE}"
|
2018-12-19 10:40:57 +01:00
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2020-01-09 02:10:51 +01:00
|
|
|
|
|
|
|
if(CONFIG_SOC_DEPRECATED_RELEASE)
|
|
|
|
message(WARNING "
|
|
|
|
WARNING: The SoC '${SOC_NAME}' is deprecated and will be
|
|
|
|
removed in version ${CONFIG_SOC_DEPRECATED_RELEASE}"
|
|
|
|
)
|
|
|
|
endif()
|
2019-06-06 20:12:14 +02:00
|
|
|
|
2019-08-29 16:19:32 +02:00
|
|
|
# In CMake projects, 'CMAKE_BUILD_TYPE' usually determines the
|
|
|
|
# optimization flag, but in Zephyr it is determined through
|
|
|
|
# Kconfig. Here we give a warning when there is a mismatch between the
|
|
|
|
# two in case the user is not aware of this.
|
|
|
|
set(build_types None Debug Release RelWithDebInfo MinSizeRel)
|
|
|
|
|
|
|
|
if((CMAKE_BUILD_TYPE IN_LIST build_types) AND (NOT NO_BUILD_TYPE_WARNING))
|
|
|
|
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_uppercase)
|
2021-12-10 15:06:30 +01:00
|
|
|
# The CMAKE_C_FLAGS_<build_type> is a string, so we do a regex to see if the
|
|
|
|
# optimization flag is present in that string.
|
|
|
|
# To avoid false-positive matches, the flag must either be matched first
|
|
|
|
# or last in string, or come after / followed by minimum a space.
|
|
|
|
if(NOT (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_uppercase} MATCHES "(^| )${OPTIMIZATION_FLAG}($| )"))
|
2019-08-29 16:19:32 +02:00
|
|
|
message(WARNING "
|
|
|
|
The CMake build type was set to '${CMAKE_BUILD_TYPE}', but the optimization flag was set to '${OPTIMIZATION_FLAG}'.
|
|
|
|
This may be intentional and the warning can be turned off by setting the CMake variable 'NO_BUILD_TYPE_WARNING'"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-09-11 15:06:28 +02:00
|
|
|
# @Intent: Set compiler specific flags for standard C/C++ includes
|
2019-06-06 20:12:14 +02:00
|
|
|
# Done at the very end, so any other system includes which may
|
|
|
|
# be added by Zephyr components were first in list.
|
2020-08-18 14:47:53 +02:00
|
|
|
# Note, the compile flags are moved, but the system include is still present here.
|
|
|
|
zephyr_compile_options($<TARGET_PROPERTY:compiler,nostdinc>)
|
|
|
|
target_include_directories(zephyr_interface SYSTEM INTERFACE $<TARGET_PROPERTY:compiler,nostdinc_include>)
|
2020-09-09 15:42:32 +02:00
|
|
|
|
2022-12-09 19:19:58 +01:00
|
|
|
if(CONFIG_MINIMAL_LIBCPP)
|
2021-09-11 15:06:28 +02:00
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,nostdincxx>>)
|
|
|
|
endif()
|
|
|
|
|
2020-09-09 15:42:32 +02:00
|
|
|
# Finally export all build flags from Zephyr
|
|
|
|
add_subdirectory_ifdef(
|
|
|
|
CONFIG_MAKEFILE_EXPORTS
|
|
|
|
cmake/makefile_exports
|
|
|
|
)
|