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
|
|
|
project(Zephyr-Kernel VERSION ${PROJECT_VERSION})
|
|
|
|
enable_language(C CXX ASM)
|
|
|
|
|
|
|
|
# Verify that the toolchain can compile a dummy file, if it is not we
|
2019-06-18 20:45:40 +02:00
|
|
|
# won't be able to test for compatibility with certain C flags.
|
2017-10-27 15:43:34 +02:00
|
|
|
check_c_compiler_flag("" toolchain_is_ok)
|
|
|
|
assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.")
|
|
|
|
|
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)
|
2019-01-14 16:31:02 +01:00
|
|
|
set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_prebuilt)
|
2019-05-07 15:20:20 +02:00
|
|
|
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_MACROS_H_TARGET syscall_macros_h_target)
|
|
|
|
set(SYSCALL_LIST_H_TARGET syscall_list_h_target)
|
|
|
|
set(DRIVER_VALIDATION_H_TARGET driver_validation_h_target)
|
|
|
|
set(KOBJ_TYPES_H_TARGET kobj_types_h_target)
|
|
|
|
set(LINKER_SCRIPT_TARGET linker_script_target)
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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(
|
|
|
|
kernel/include
|
2018-11-15 10:37:46 +01:00
|
|
|
${ARCH_DIR}/${ARCH}/include
|
2017-10-27 15:43:34 +02:00
|
|
|
include
|
|
|
|
include/drivers
|
|
|
|
${PROJECT_BINARY_DIR}/include/generated
|
|
|
|
${USERINCLUDE}
|
|
|
|
${STDINCLUDE}
|
|
|
|
)
|
|
|
|
|
2019-01-25 10:14:13 +01:00
|
|
|
# Don't add non-existing include directories, it creates noise and
|
|
|
|
# warnings in some tooling
|
|
|
|
foreach(optional_include_dir
|
|
|
|
${SOC_DIR}/${ARCH}/${SOC_PATH}
|
|
|
|
${SOC_DIR}/${ARCH}/${SOC_PATH}/include
|
|
|
|
${SOC_DIR}/${ARCH}/${SOC_FAMILY}/include
|
|
|
|
)
|
|
|
|
if(EXISTS ${optional_include_dir})
|
|
|
|
zephyr_include_directories(${optional_include_dir})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
zephyr_compile_definitions(
|
|
|
|
KERNEL
|
|
|
|
__ZEPHYR__=1
|
2018-01-03 18:26:19 +01:00
|
|
|
)
|
|
|
|
|
2019-01-10 12:07:51 +01:00
|
|
|
# @Intent: Set compiler flags to enable buffer overflow checks in libc functions
|
|
|
|
# @config in CONFIG_NO_OPTIMIZATIONS optional : Optimizations may affect security
|
|
|
|
toolchain_cc_security_fortify()
|
|
|
|
|
|
|
|
# @Intent: Set compiler flags to detect general stack overflows across all functions
|
|
|
|
if(CONFIG_STACK_CANARIES)
|
|
|
|
toolchain_cc_security_canaries()
|
2018-01-03 18:26:19 +01:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2018-04-10 04:53:26 +02:00
|
|
|
if(BUILD_VERSION)
|
|
|
|
zephyr_compile_definitions(
|
|
|
|
BUILD_VERSION=${BUILD_VERSION}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
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
|
|
|
#
|
2019-01-30 10:12:30 +01:00
|
|
|
toolchain_cc_optimize_for_no_optimizations_flag(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG)
|
|
|
|
toolchain_cc_optimize_for_debug_flag(OPTIMIZE_FOR_DEBUG_FLAG)
|
|
|
|
toolchain_cc_optimize_for_speed_flag(OPTIMIZE_FOR_SPEED_FLAG)
|
|
|
|
toolchain_cc_optimize_for_size_flag(OPTIMIZE_FOR_SIZE_FLAG)
|
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()
|
|
|
|
|
2019-01-30 10:12:30 +01:00
|
|
|
# Apply the final optimization flag(s)
|
|
|
|
zephyr_compile_options(${OPTIMIZATION_FLAG})
|
|
|
|
|
2019-02-18 23:54:30 +01:00
|
|
|
# @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig
|
|
|
|
toolchain_cc_cpp_base_flags(CPP_BASE_FLAGS)
|
|
|
|
foreach(flag ${CPP_BASE_FLAGS})
|
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:${flag}>
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# @Intent: Obtain compiler specific flags for compiling under different ISO standards of C++
|
|
|
|
toolchain_cc_cpp_dialect_std_98_flags(CPP_DIALECT_STD_98_FLAGS)
|
|
|
|
toolchain_cc_cpp_dialect_std_11_flags(CPP_DIALECT_STD_11_FLAGS)
|
|
|
|
toolchain_cc_cpp_dialect_std_14_flags(CPP_DIALECT_STD_14_FLAGS)
|
|
|
|
toolchain_cc_cpp_dialect_std_17_flags(CPP_DIALECT_STD_17_FLAGS)
|
|
|
|
toolchain_cc_cpp_dialect_std_2a_flags(CPP_DIALECT_STD_2A_FLAGS)
|
2018-10-23 18:20:51 +02:00
|
|
|
|
2019-05-15 23:01:58 +02:00
|
|
|
if(CONFIG_CPLUSPLUS)
|
|
|
|
# From kconfig choice, pick a single dialect.
|
|
|
|
# Kconfig choice ensures only one of these CONFIG_STD_CPP* is set.
|
|
|
|
if(CONFIG_STD_CPP98)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_98_FLAGS})
|
|
|
|
elseif(CONFIG_STD_CPP11)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_11_FLAGS}) # Default in kconfig
|
|
|
|
elseif(CONFIG_STD_CPP14)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_14_FLAGS})
|
|
|
|
elseif(CONFIG_STD_CPP17)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_17_FLAGS})
|
|
|
|
elseif(CONFIG_STD_CPP2A)
|
|
|
|
set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_2A_FLAGS})
|
|
|
|
else()
|
|
|
|
assert(0 "Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.")
|
|
|
|
endif()
|
2018-10-23 18:20:51 +02:00
|
|
|
|
2019-05-15 23:01:58 +02:00
|
|
|
foreach(flag ${STD_CPP_DIALECT_FLAGS})
|
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:${flag}>
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2019-02-18 23:54:30 +01:00
|
|
|
|
|
|
|
if(NOT CONFIG_EXCEPTIONS)
|
|
|
|
# @Intent: Obtain compiler specific flags related to C++ Exceptions
|
|
|
|
toolchain_cc_cpp_no_exceptions_flag(CPP_NO_EXCEPTIONS_FLAG)
|
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:${CPP_NO_EXCEPTIONS_FLAG}>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT CONFIG_RTTI)
|
|
|
|
# @Intent: Obtain compiler specific flags related to C++ Run Time Type Information
|
|
|
|
toolchain_cc_cpp_no_rtti_flag(CPP_NO_RTTI_FLAG)
|
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:${CPP_NO_RTTI_FLAG}>
|
|
|
|
)
|
|
|
|
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.
|
|
|
|
toolchain_cc_warning_error_misra_sane(CC_MISRA_SANE_FLAG)
|
|
|
|
toolchain_cc_cpp_warning_error_misra_sane(CPP_MISRA_SANE_FLAG)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:${CC_MISRA_SANE_FLAG}>)
|
|
|
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${CPP_MISRA_SANE_FLAG}>)
|
2019-02-27 20:53:18 +01:00
|
|
|
endif()
|
|
|
|
|
2019-06-11 13:55:53 +02:00
|
|
|
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
|
|
|
|
toolchain_cc_imacros(${AUTOCONF_H})
|
|
|
|
|
2019-06-11 15:56:57 +02:00
|
|
|
# @Intent: Set compiler specific flag for bare metal freestanding option
|
|
|
|
toolchain_cc_freestanding()
|
|
|
|
|
2019-06-12 14:56:46 +02:00
|
|
|
# @Intent: Set compiler specific flag for tentative definitions, no-common
|
|
|
|
toolchain_cc_nocommon()
|
|
|
|
|
2019-07-23 09:00:55 +02:00
|
|
|
# @Intent: Set compiler specific flag for production of debug information
|
|
|
|
toolchain_cc_produce_debug_info()
|
|
|
|
|
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
|
|
|
|
toolchain_cc_asm_base_flags(ASM_BASE_FLAG)
|
|
|
|
zephyr_compile_options(
|
|
|
|
$<$<COMPILE_LANGUAGE:ASM>:${ASM_BASE_FLAG}>
|
|
|
|
)
|
|
|
|
|
2019-07-02 22:22:04 +02:00
|
|
|
# @Intent: Enforce standard integer type correspondance to match Zephyr usage.
|
|
|
|
# (must be after compiler specific flags)
|
|
|
|
toolchain_cc_imacros(${ZEPHYR_BASE}/include/toolchain/zephyr_stdint.h)
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2017-10-03 16:31:55 +02:00
|
|
|
if(NOT CONFIG_NATIVE_APPLICATION)
|
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
|
|
|
|
2018-10-23 18:20:51 +02:00
|
|
|
if(CONFIG_LIB_CPLUSPLUS)
|
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
|
2019-05-06 15:19:27 +02:00
|
|
|
toolchain_cc_warning_base()
|
|
|
|
|
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")
|
2019-05-06 14:34:43 +02:00
|
|
|
toolchain_cc_warning_dw_1()
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(W MATCHES "2")
|
2019-05-06 14:34:43 +02:00
|
|
|
toolchain_cc_warning_dw_2()
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(W MATCHES "3")
|
2019-05-06 14:34:43 +02:00
|
|
|
toolchain_cc_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
|
2019-05-06 15:21:58 +02:00
|
|
|
toolchain_cc_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
|
|
|
|
toolchain_cc_warning_error_implicit_int()
|
|
|
|
|
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)
|
|
|
|
zephyr_cc_option(-fno-pie)
|
|
|
|
zephyr_cc_option(-fno-pic)
|
|
|
|
zephyr_cc_option(-fno-strict-overflow)
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2019-05-06 15:21:58 +02:00
|
|
|
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
|
|
# GCC assumed
|
|
|
|
zephyr_cc_option(-fno-reorder-functions)
|
2017-12-12 18:59:37 +01:00
|
|
|
|
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()
|
|
|
|
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
|
2019-06-01 00:28:38 +02:00
|
|
|
|
|
|
|
# If both match then the last one wins. This matters for tests/ and
|
|
|
|
# samples/ inside *both* CMAKE_SOURCE_DIR and ZEPHYR_BASE: for them
|
|
|
|
# let's strip the shortest prefix.
|
|
|
|
zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR)
|
|
|
|
zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE)
|
|
|
|
# TODO: -fmacro-prefix-map=modules/etc. "build/zephyr_modules.txt" might help.
|
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)
|
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
|
|
|
if(CONFIG_ARM)
|
|
|
|
set(PRIV_STACK_DEP priv_stacks_prebuilt)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-11-29 10:14:27 +01:00
|
|
|
get_property(TOPT GLOBAL PROPERTY TOPT)
|
2019-03-08 10:29:33 +01:00
|
|
|
set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains,
|
|
|
|
# while -Wl,-T works for both, gcc and clang
|
2018-11-29 10:14:27 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT)
|
|
|
|
set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT})
|
2018-04-12 14:48:05 +02:00
|
|
|
if(NOT EXISTS ${LINKER_SCRIPT})
|
2017-10-27 15:43:34 +02:00
|
|
|
set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT})
|
2018-04-12 14:48:05 +02:00
|
|
|
assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Try a board specific linker file
|
|
|
|
set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld)
|
|
|
|
if(NOT EXISTS ${LINKER_SCRIPT})
|
|
|
|
# If not available, try an SoC specific linker file
|
2018-09-04 21:34:06 +02:00
|
|
|
set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT EXISTS ${LINKER_SCRIPT})
|
|
|
|
message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?")
|
|
|
|
endif()
|
|
|
|
|
2018-01-30 11:26:42 +01:00
|
|
|
# Custom section support in linker scripts requires that the application source
|
|
|
|
# directory is in the preprocessor search path, in order to find the custom
|
|
|
|
# linker script fragments.
|
|
|
|
if(CONFIG_CUSTOM_RODATA_LD OR CONFIG_CUSTOM_RWDATA_LD OR CONFIG_CUSTOM_SECTIONS_LD)
|
|
|
|
zephyr_include_directories(${APPLICATION_SOURCE_DIR})
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h)
|
|
|
|
|
2018-10-09 16:03:29 +02:00
|
|
|
# Error-out when the deprecated naming convention is found (until
|
|
|
|
# after 1.14.0 has been released)
|
|
|
|
foreach(path
|
2019-02-08 15:39:37 +01:00
|
|
|
${BOARD_DIR}/dts.fixup
|
|
|
|
${PROJECT_SOURCE_DIR}/soc/${ARCH}/${SOC_PATH}/dts.fixup
|
2018-10-09 16:03:29 +02:00
|
|
|
${APPLICATION_SOURCE_DIR}/dts.fixup
|
2019-02-08 15:39:37 +01:00
|
|
|
)
|
2018-10-09 16:03:29 +02:00
|
|
|
if(EXISTS ${path})
|
2019-02-08 15:39:37 +01:00
|
|
|
message(FATAL_ERROR
|
|
|
|
"A deprecated filename has been detected. Porting is required."
|
|
|
|
"The file '${path}' exists, but it should be named dts_fixup.h instead."
|
|
|
|
"See https://github.com/zephyrproject-rtos/zephyr/pull/10352 for more details"
|
|
|
|
)
|
2018-10-09 16:03:29 +02:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set_ifndef( DTS_BOARD_FIXUP_FILE ${BOARD_DIR}/dts_fixup.h)
|
|
|
|
set_ifndef( DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts_fixup.h)
|
|
|
|
set( DTS_APP_FIXUP_FILE ${APPLICATION_SOURCE_DIR}/dts_fixup.h)
|
|
|
|
|
2019-01-28 13:40:50 +01:00
|
|
|
set_ifndef(DTS_CAT_OF_FIXUP_FILES ${ZEPHYR_BINARY_DIR}/include/generated/generated_dts_board_fixups.h)
|
2018-10-09 16:03:29 +02:00
|
|
|
|
2019-01-28 13:40:50 +01:00
|
|
|
# Concatenate the fixups into a single header file for easy
|
|
|
|
# #include'ing
|
|
|
|
file(WRITE ${DTS_CAT_OF_FIXUP_FILES} "/* May only be included by generated_dts_board.h */\n\n")
|
|
|
|
foreach(fixup_file
|
2019-02-08 15:39:37 +01:00
|
|
|
${DTS_BOARD_FIXUP_FILE}
|
|
|
|
${DTS_SOC_FIXUP_FILE}
|
|
|
|
${DTS_APP_FIXUP_FILE}
|
|
|
|
${shield_dts_fixups}
|
|
|
|
)
|
2019-01-28 13:40:50 +01:00
|
|
|
if(EXISTS ${fixup_file})
|
2019-02-08 15:39:37 +01:00
|
|
|
file(READ ${fixup_file} contents)
|
|
|
|
file(APPEND ${DTS_CAT_OF_FIXUP_FILES} "${contents}")
|
2018-10-09 16:03:29 +02:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
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
|
|
|
|
2018-09-13 16:25:53 +02:00
|
|
|
if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt)
|
2018-09-04 21:34:06 +02:00
|
|
|
add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH})
|
2018-09-03 22:20:14 +02:00
|
|
|
else()
|
2018-09-04 21:34:06 +02:00
|
|
|
add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH})
|
2018-09-03 22:20:14 +02:00
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
add_subdirectory(boards)
|
|
|
|
add_subdirectory(ext)
|
|
|
|
add_subdirectory(subsys)
|
|
|
|
add_subdirectory(drivers)
|
|
|
|
|
2019-03-19 10:38:18 +01:00
|
|
|
# Include zephyr modules generated CMake file.
|
|
|
|
if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt)
|
2019-07-18 10:38:25 +02:00
|
|
|
file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT
|
|
|
|
ENCODING UTF-8)
|
2019-03-19 10:38:18 +01:00
|
|
|
|
|
|
|
foreach(module ${ZEPHYR_MODULES_TXT})
|
2019-03-31 22:29:30 +02:00
|
|
|
# Match "<name>":"<path>" for each line of file, each corresponding to
|
|
|
|
# one module. The use of quotes is required due to CMake not supporting
|
|
|
|
# lazy regexes (it supports greedy only).
|
|
|
|
string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module})
|
|
|
|
string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module})
|
|
|
|
message("Including module: ${module_name} in path: ${module_path}")
|
2019-06-01 00:37:40 +02:00
|
|
|
# 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
|
2019-05-28 20:34:21 +02:00
|
|
|
add_subdirectory(${module_path} ${CMAKE_BINARY_DIR}/modules/${module_name})
|
2019-03-19 10:38:18 +01:00
|
|
|
endforeach()
|
2019-02-12 10:19:38 +01:00
|
|
|
endif()
|
2019-02-05 10:36:22 +01:00
|
|
|
|
2017-11-29 17:46:37 +01:00
|
|
|
set(syscall_macros_h ${ZEPHYR_BINARY_DIR}/include/generated/syscall_macros.h)
|
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
add_custom_target(${SYSCALL_MACROS_H_TARGET} DEPENDS ${syscall_macros_h})
|
2019-04-29 17:17:30 +02:00
|
|
|
add_custom_command( OUTPUT ${syscall_macros_h}
|
2017-11-29 17:46:37 +01:00
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2018-06-14 20:21:18 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/gen_syscall_header.py
|
2017-11-29 17:46:37 +01:00
|
|
|
> ${syscall_macros_h}
|
2018-06-14 20:21:18 +02:00
|
|
|
DEPENDS ${ZEPHYR_BASE}/scripts/gen_syscall_header.py
|
2017-11-29 17:46:37 +01:00
|
|
|
)
|
|
|
|
|
2017-11-20 13:03:55 +01: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)
|
|
|
|
|
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}
|
2018-06-14 20:21:18 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/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
|
|
|
|
--trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation
|
|
|
|
${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}
|
2018-06-14 20:21:18 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/subfolder_list.py
|
|
|
|
--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
|
|
|
|
--trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation
|
|
|
|
${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-07-02 11:29:19 +02:00
|
|
|
# SYSCALL_INCLUDE_DIRECTORY will include the directories that needs to be
|
|
|
|
# searched for syscall declarations if CONFIG_APPLICATION_DEFINED_SYSCALL is set
|
|
|
|
if(CONFIG_APPLICATION_DEFINED_SYSCALL)
|
|
|
|
set(SYSCALL_INCLUDE_DIRECTORY --include ${APPLICATION_SOURCE_DIR})
|
|
|
|
endif()
|
|
|
|
|
2017-11-20 13:03:55 +01:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
${syscalls_json}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
2018-06-14 20:21:18 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/parse_syscalls.py
|
2018-07-02 11:29:19 +02:00
|
|
|
--include ${ZEPHYR_BASE}/include # Read files from this dir
|
|
|
|
${SYSCALL_INCLUDE_DIRECTORY}
|
2018-06-14 22:27:17 +02:00
|
|
|
--json-file ${syscalls_json} # Write this file
|
|
|
|
DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS}
|
2017-11-20 13:03:55 +01:00
|
|
|
)
|
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h})
|
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}
|
2018-06-14 20:21:18 +02:00
|
|
|
${ZEPHYR_BASE}/scripts/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}
|
2017-11-20 13:03:55 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
DEPENDS ${syscalls_json}
|
|
|
|
)
|
|
|
|
|
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}
|
|
|
|
${ZEPHYR_BASE}/scripts/gen_kobject_list.py
|
|
|
|
--validation-output ${DRV_VALIDATION}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2019-04-12 18:00:52 +02:00
|
|
|
DEPENDS ${ZEPHYR_BASE}/scripts/gen_kobject_list.py
|
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
|
|
|
|
2018-04-05 22:59:33 +02:00
|
|
|
include($ENV{ZEPHYR_BASE}/cmake/kobj.cmake)
|
|
|
|
gen_kobj(KOBJ_INCLUDE_PATH)
|
2018-04-04 22:50:32 +02: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-01-14 16:39:33 +01:00
|
|
|
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
|
|
|
|
add_dependencies( ${OFFSETS_LIB}
|
|
|
|
${SYSCALL_LIST_H_TARGET}
|
|
|
|
${SYSCALL_MACROS_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}
|
2018-01-11 15:46:44 +01:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/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
|
|
|
|
|
|
|
zephyr_include_directories(${TOOLCHAIN_INCLUDES})
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
# Read list content
|
|
|
|
get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS)
|
|
|
|
|
|
|
|
foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
|
|
|
|
# TODO: Could this become an INTERFACE property of zephyr_interface?
|
2019-01-14 16:39:33 +01:00
|
|
|
add_dependencies(${zephyr_lib} ${OFFSETS_H_TARGET})
|
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
|
|
|
|
2019-04-29 17:16:54 +02:00
|
|
|
configure_linker_script(
|
2019-04-29 20:27:23 +02:00
|
|
|
linker.cmd
|
2019-04-29 20:35:12 +02:00
|
|
|
""
|
2019-02-08 15:49:57 +01:00
|
|
|
${PRIV_STACK_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
|
|
|
${APP_SMEM_ALIGNED_DEP}
|
2019-02-08 15:49:57 +01:00
|
|
|
${CODE_RELOCATION_DEP}
|
|
|
|
${OFFSETS_H_TARGET}
|
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(
|
2019-01-14 16:39:33 +01:00
|
|
|
${LINKER_SCRIPT_TARGET}
|
2017-10-27 15:43:34 +02:00
|
|
|
DEPENDS
|
|
|
|
linker.cmd
|
2017-12-14 13:03:23 +01:00
|
|
|
)
|
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
# Give the '${LINKER_SCRIPT_TARGET}' target all of the include directories so
|
2017-12-14 13:03:23 +01:00
|
|
|
# that cmake can successfully find the linker_script's header
|
|
|
|
# dependencies.
|
|
|
|
zephyr_get_include_directories_for_lang(C
|
|
|
|
ZEPHYR_INCLUDE_DIRS
|
|
|
|
STRIP_PREFIX # Don't use a -I prefix
|
|
|
|
)
|
|
|
|
set_property(TARGET
|
2019-01-14 16:39:33 +01:00
|
|
|
${LINKER_SCRIPT_TARGET}
|
2017-12-14 13:03:23 +01:00
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
if(CONFIG_GEN_ISR_TABLES)
|
2017-12-12 18:59:37 +01:00
|
|
|
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()
|
|
|
|
|
2019-01-14 16:31:02 +01:00
|
|
|
# isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by
|
2017-10-27 15:43:34 +02:00
|
|
|
# gen_isr_tables.py
|
2019-08-01 07:56:45 +02:00
|
|
|
set(obj_copy_cmd "")
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST obj_copy_cmd
|
|
|
|
TARGET_INPUT ${OUTPUT_FORMAT}
|
|
|
|
TARGET_OUTPUT "binary"
|
|
|
|
SECTION_ONLY ".intList"
|
|
|
|
FILE_INPUT $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
|
|
|
|
FILE_OUTPUT "isrList.bin"
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT isr_tables.c
|
2019-08-01 07:56:45 +02:00
|
|
|
${obj_copy_cmd}
|
2017-10-27 15:43:34 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
2018-01-11 15:46:44 +01:00
|
|
|
${ZEPHYR_BASE}/arch/common/gen_isr_tables.py
|
2017-10-27 15:43:34 +02:00
|
|
|
--output-source isr_tables.c
|
2019-01-14 16:31:02 +01:00
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
|
2017-10-27 15:43:34 +02:00
|
|
|
--intlist isrList.bin
|
2018-10-09 11:59:16 +02:00
|
|
|
$<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian>
|
2018-01-04 14:08:39 +01:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug>
|
2017-12-12 18:59:37 +01:00
|
|
|
${GEN_ISR_TABLE_EXTRA_ARG}
|
2019-01-14 16:31:02 +01:00
|
|
|
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c)
|
|
|
|
endif()
|
|
|
|
|
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)
|
|
|
|
zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv)
|
|
|
|
string(REPLACE "-ftest-coverage" "" NO_COVERAGE_FLAGS "${compiler_flags_priv}")
|
|
|
|
string(REPLACE "-fprofile-arcs" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}")
|
2019-04-02 00:57:35 +02:00
|
|
|
string(REPLACE "-fno-inline" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}")
|
2018-11-21 10:01:56 +01:00
|
|
|
|
|
|
|
get_property(include_dir_in_interface TARGET zephyr_interface
|
|
|
|
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
get_property(sys_include_dir_in_interface TARGET zephyr_interface
|
|
|
|
PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
get_property(compile_definitions_interface TARGET zephyr_interface
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2019-04-17 00:39:45 +02:00
|
|
|
# Warning most of this gperf code is duplicated below for
|
|
|
|
# gen_kobject_list.py / output_lib
|
2018-02-01 08:19:49 +01:00
|
|
|
if(CONFIG_ARM AND CONFIG_USERSPACE)
|
|
|
|
set(GEN_PRIV_STACKS $ENV{ZEPHYR_BASE}/scripts/gen_priv_stacks.py)
|
|
|
|
set(PROCESS_PRIV_STACKS_GPERF $ENV{ZEPHYR_BASE}/scripts/process_gperf.py)
|
|
|
|
|
|
|
|
set(PRIV_STACKS priv_stacks_hash.gperf)
|
|
|
|
set(PRIV_STACKS_OUTPUT_SRC_PRE priv_stacks_hash_preprocessed.c)
|
|
|
|
set(PRIV_STACKS_OUTPUT_SRC priv_stacks_hash.c)
|
|
|
|
set(PRIV_STACKS_OUTPUT_OBJ priv_stacks_hash.c.obj)
|
|
|
|
set(PRIV_STACKS_OUTPUT_OBJ_RENAMED priv_stacks_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.
|
|
|
|
|
|
|
|
# Use the script GEN_PRIV_STACKS to scan the kernel binary's
|
2019-01-14 16:31:02 +01:00
|
|
|
# (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel
|
2018-02-01 08:19:49 +01:00
|
|
|
# objects (PRIV_STACKS) which we will then pass to gperf
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${PRIV_STACKS}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${GEN_PRIV_STACKS}
|
|
|
|
--kernel $<TARGET_FILE:priv_stacks_prebuilt>
|
|
|
|
--output ${PRIV_STACKS}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS priv_stacks_prebuilt
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(priv_stacks DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS})
|
|
|
|
|
|
|
|
# Use gperf to generate C code (PRIV_STACKS_OUTPUT_SRC_PRE) which implements a
|
|
|
|
# perfect hashtable based on PRIV_STACKS
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${PRIV_STACKS_OUTPUT_SRC_PRE}
|
|
|
|
COMMAND
|
|
|
|
${GPERF} -C
|
|
|
|
--output-file ${PRIV_STACKS_OUTPUT_SRC_PRE}
|
|
|
|
${PRIV_STACKS}
|
2018-05-01 08:10:26 +02:00
|
|
|
DEPENDS priv_stacks ${PRIV_STACKS}
|
2018-02-01 08:19:49 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(priv_stacks_output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE})
|
|
|
|
|
|
|
|
# For our purposes the code/data generated by gperf is not optimal.
|
|
|
|
#
|
|
|
|
# The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on
|
|
|
|
# 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 ${PRIV_STACKS_OUTPUT_SRC}
|
|
|
|
COMMAND
|
2018-06-21 14:34:42 +02:00
|
|
|
${PYTHON_EXECUTABLE}
|
2018-02-01 08:19:49 +01:00
|
|
|
${PROCESS_PRIV_STACKS_GPERF}
|
|
|
|
-i ${PRIV_STACKS_OUTPUT_SRC_PRE}
|
|
|
|
-o ${PRIV_STACKS_OUTPUT_SRC}
|
|
|
|
-p "struct _k_priv_stack_map"
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2018-05-01 08:10:26 +02:00
|
|
|
DEPENDS priv_stacks_output_src_pre ${PRIV_STACKS_OUTPUT_SRC_PRE}
|
2018-02-01 08:19:49 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(priv_stacks_output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC})
|
|
|
|
|
2018-11-21 10:01:56 +01:00
|
|
|
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}
|
|
|
|
PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}")
|
|
|
|
|
|
|
|
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}
|
|
|
|
PROPERTIES COMPILE_FLAGS
|
2019-03-15 01:04:11 +01:00
|
|
|
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections ")
|
2018-11-21 10:01:56 +01:00
|
|
|
|
2018-02-01 08:19:49 +01:00
|
|
|
# We need precise control of where generated text/data ends up in the final
|
|
|
|
# kernel image. Disable function/data sections and use objcopy to move
|
|
|
|
# generated data into special section names
|
|
|
|
add_library(priv_stacks_output_lib STATIC
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Turn off -ffunction-sections, etc.
|
|
|
|
# NB: Using a library instead of target_compile_options(priv_stacks_output_lib
|
|
|
|
# [...]) because a library's options have precedence
|
|
|
|
add_library(priv_stacks_output_lib_interface INTERFACE)
|
2019-03-14 17:50:08 +01:00
|
|
|
foreach(incl ${include_dir_in_interface})
|
2018-11-21 10:01:56 +01:00
|
|
|
target_include_directories(priv_stacks_output_lib_interface INTERFACE ${incl})
|
|
|
|
endforeach()
|
|
|
|
|
2019-03-14 17:50:08 +01:00
|
|
|
foreach(incl ${sys_include_dir_in_interface})
|
|
|
|
target_include_directories(priv_stacks_output_lib_interface SYSTEM INTERFACE ${incl})
|
|
|
|
endforeach()
|
|
|
|
|
2018-02-01 08:19:49 +01:00
|
|
|
target_link_libraries(priv_stacks_output_lib priv_stacks_output_lib_interface)
|
|
|
|
|
|
|
|
set(PRIV_STACKS_OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/priv_stacks_output_lib.dir/${PRIV_STACKS_OUTPUT_OBJ})
|
|
|
|
|
2019-08-01 07:56:45 +02:00
|
|
|
set(obj_copy_cmd "")
|
|
|
|
set(obj_copy_sections_rename
|
|
|
|
.bss=.priv_stacks.noinit
|
|
|
|
.data=.priv_stacks.data
|
|
|
|
.text=.priv_stacks.text
|
|
|
|
.rodata=.priv_stacks.rodata
|
|
|
|
)
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST obj_copy_cmd
|
|
|
|
SECTION_RENAME ${obj_copy_sections_rename}
|
|
|
|
FILE_INPUT ${PRIV_STACKS_OUTPUT_OBJ_PATH}
|
|
|
|
FILE_OUTPUT ${PRIV_STACKS_OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
2018-02-01 08:19:49 +01:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}
|
2019-08-01 07:56:45 +02:00
|
|
|
${obj_copy_cmd}
|
2018-02-01 08:19:49 +01:00
|
|
|
DEPENDS priv_stacks_output_lib
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(priv_stacks_output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED})
|
|
|
|
|
|
|
|
add_library(priv_stacks_output_obj_renamed_lib STATIC IMPORTED GLOBAL)
|
|
|
|
set_property(
|
|
|
|
TARGET priv_stacks_output_obj_renamed_lib
|
|
|
|
PROPERTY
|
|
|
|
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
|
|
|
add_dependencies(
|
|
|
|
priv_stacks_output_obj_renamed_lib
|
|
|
|
priv_stacks_output_obj_renamed
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES priv_stacks_output_obj_renamed_lib)
|
|
|
|
endif()
|
|
|
|
|
2019-04-17 00:39:45 +02:00
|
|
|
# Warning: most of this gperf code is duplicated above for
|
|
|
|
# gen_priv_stacks.py / priv_stacks_output_lib
|
2017-10-27 15:43:34 +02:00
|
|
|
if(CONFIG_USERSPACE)
|
2018-01-11 15:46:44 +01:00
|
|
|
set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/gen_kobject_list.py)
|
|
|
|
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/process_gperf.py)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
set(OBJ_LIST kobject_hash.gperf)
|
|
|
|
set(OUTPUT_SRC_PRE kobject_hash_preprocessed.c)
|
|
|
|
set(OUTPUT_SRC kobject_hash.c)
|
|
|
|
set(OUTPUT_OBJ kobject_hash.c.obj)
|
|
|
|
set(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
|
2019-04-17 00:39:45 +02:00
|
|
|
# elf file. More information in gen_kobject_list.py --help.
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
# Use the script GEN_KOBJ_LIST to scan the kernel binary's
|
2019-01-14 16:31:02 +01:00
|
|
|
# (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel
|
2017-10-27 15:43:34 +02:00
|
|
|
# objects (OBJ_LIST) which we will then pass to gperf
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OBJ_LIST}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${GEN_KOBJ_LIST}
|
2019-01-14 16:31:02 +01:00
|
|
|
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
|
2018-04-04 22:50:32 +02:00
|
|
|
--gperf-output ${OBJ_LIST}
|
2017-10-27 15:43:34 +02:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2019-01-14 16:31:02 +01:00
|
|
|
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
|
2017-10-27 15:43:34 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST})
|
|
|
|
|
|
|
|
# Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a
|
|
|
|
# perfect hashtable based on OBJ_LIST
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OUTPUT_SRC_PRE}
|
|
|
|
COMMAND
|
|
|
|
${GPERF}
|
|
|
|
--output-file ${OUTPUT_SRC_PRE}
|
|
|
|
${OBJ_LIST}
|
2018-01-31 10:42:46 +01:00
|
|
|
DEPENDS obj_list ${OBJ_LIST}
|
2017-10-27 15:43:34 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE})
|
|
|
|
|
|
|
|
# For our purposes the code/data generated by gperf is not optimal.
|
|
|
|
#
|
|
|
|
# The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on
|
|
|
|
# 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 ${OUTPUT_SRC}
|
|
|
|
COMMAND
|
2018-06-21 14:34:42 +02:00
|
|
|
${PYTHON_EXECUTABLE}
|
2017-10-27 15:43:34 +02:00
|
|
|
${PROCESS_GPERF}
|
|
|
|
-i ${OUTPUT_SRC_PRE}
|
|
|
|
-o ${OUTPUT_SRC}
|
2018-02-01 08:19:49 +01:00
|
|
|
-p "struct _k_object"
|
2017-10-27 15:43:34 +02:00
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
2018-01-31 10:42:46 +01:00
|
|
|
DEPENDS output_src_pre ${OUTPUT_SRC_PRE}
|
2017-10-27 15:43:34 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC})
|
|
|
|
|
|
|
|
# We need precise control of where generated text/data ends up in the final
|
|
|
|
# kernel image. Disable function/data sections and use objcopy to move
|
|
|
|
# generated data into special section names
|
|
|
|
add_library(output_lib STATIC
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}
|
|
|
|
)
|
|
|
|
|
2018-11-21 10:01:56 +01:00
|
|
|
set_source_files_properties(${OUTPUT_SRC} PROPERTIES COMPILE_FLAGS
|
2019-03-15 01:04:11 +01:00
|
|
|
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
|
2018-11-21 10:01:56 +01:00
|
|
|
|
|
|
|
set_source_files_properties(${OUTPUT_SRC}
|
|
|
|
PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}")
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
# Turn off -ffunction-sections, etc.
|
|
|
|
# NB: Using a library instead of target_compile_options(output_lib
|
|
|
|
# [...]) because a library's options have precedence
|
|
|
|
add_library(output_lib_interface INTERFACE)
|
2018-11-21 10:01:56 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
target_link_libraries(output_lib output_lib_interface)
|
|
|
|
|
2019-03-14 17:50:08 +01:00
|
|
|
foreach(incl ${include_dir_in_interface})
|
2018-11-21 10:01:56 +01:00
|
|
|
target_include_directories(output_lib_interface INTERFACE ${incl})
|
|
|
|
endforeach()
|
|
|
|
|
2019-03-14 17:50:08 +01:00
|
|
|
foreach(incl ${sys_include_dir_in_interface})
|
|
|
|
target_include_directories(output_lib_interface SYSTEM INTERFACE ${incl})
|
|
|
|
endforeach()
|
2018-11-21 10:01:56 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ})
|
|
|
|
|
2019-08-01 07:56:45 +02:00
|
|
|
set(obj_copy_cmd "")
|
|
|
|
set(obj_copy_sections_rename
|
|
|
|
.data=.kobject_data.data
|
|
|
|
.text=.kobject_data.text
|
|
|
|
.rodata=.kobject_data.rodata
|
|
|
|
)
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST obj_copy_cmd
|
|
|
|
SECTION_RENAME ${obj_copy_sections_rename}
|
|
|
|
FILE_INPUT ${OUTPUT_OBJ_PATH}
|
|
|
|
FILE_OUTPUT ${OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}
|
2019-08-01 07:56:45 +02:00
|
|
|
${obj_copy_cmd}
|
2017-10-27 15:43:34 +02:00
|
|
|
DEPENDS output_lib
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
|
|
|
add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED})
|
|
|
|
|
|
|
|
add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL)
|
|
|
|
set_property(
|
|
|
|
TARGET output_obj_renamed_lib
|
|
|
|
PROPERTY
|
|
|
|
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}
|
|
|
|
)
|
|
|
|
add_dependencies(
|
|
|
|
output_obj_renamed_lib
|
|
|
|
output_obj_renamed
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Read global variables into local variables
|
|
|
|
get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES)
|
|
|
|
get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES)
|
|
|
|
|
2017-10-03 16:31:55 +02:00
|
|
|
|
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
|
|
|
|
toolchain_cc_cstd_flag(CC_CSTD ${CSTD})
|
2018-07-05 10:51:03 +02:00
|
|
|
zephyr_compile_options(
|
2019-06-13 15:33:03 +02:00
|
|
|
$<$<COMPILE_LANGUAGE:C>:${CC_CSTD}>
|
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
|
|
|
|
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")
|
2018-12-20 11:17:42 +01:00
|
|
|
set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../")
|
2018-02-01 08:12:32 +01:00
|
|
|
|
2018-12-20 11:17:42 +01:00
|
|
|
add_custom_target(
|
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
|
|
|
${APP_SMEM_ALIGNED_DEP}
|
|
|
|
DEPENDS
|
|
|
|
${APP_SMEM_ALIGNED_LD}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
${APP_SMEM_UNALIGNED_DEP}
|
2019-02-08 15:49:57 +01:00
|
|
|
DEPENDS
|
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
|
|
|
${APP_SMEM_UNALIGNED_LD}
|
2018-12-20 11:17:42 +01:00
|
|
|
)
|
userspace: compartmentalized app memory organization
Summary: revised attempt at addressing issue 6290. The
following provides an alternative to using
CONFIG_APPLICATION_MEMORY by compartmentalizing data into
Memory Domains. Dependent on MPU limitations, supports
compartmentalized Memory Domains for 1...N logical
applications. This is considered an initial attempt at
designing flexible compartmentalized Memory Domains for
multiple logical applications and, with the provided python
script and edited CMakeLists.txt, provides support for power
of 2 aligned MPU architectures.
Overview: The current patch uses qualifiers to group data into
subsections. The qualifier usage allows for dynamic subsection
creation and affords the developer a large amount of flexibility
in the grouping, naming, and size of the resulting partitions and
domains that are built on these subsections. By additional macro
calls, functions are created that help calculate the size,
address, and permissions for the subsections and enable the
developer to control application data in specified partitions and
memory domains.
Background: Initial attempts focused on creating a single
section in the linker script that then contained internally
grouped variables/data to allow MPU/MMU alignment and protection.
This did not provide additional functionality beyond
CONFIG_APPLICATION_MEMORY as we were unable to reliably group
data or determine their grouping via exported linker symbols.
Thus, the resulting decision was made to dynamically create
subsections using the current qualifier method. An attempt to
group the data by object file was tested, but found that this
broke applications such as ztest where two object files are
created: ztest and main. This also creates an issue of grouping
the two object files together in the same memory domain while
also allowing for compartmenting other data among threads.
Because it is not possible to know a) the name of the partition
and thus the symbol in the linker, b) the size of all the data
in the subsection, nor c) the overall number of partitions
created by the developer, it was not feasible to align the
subsections at compile time without using dynamically generated
linker script for MPU architectures requiring power of 2
alignment.
In order to provide support for MPU architectures that require a
power of 2 alignment, a python script is run at build prior to
when linker_priv_stacks.cmd is generated. This script scans the
built object files for all possible partitions and the names given
to them. It then generates a linker file (app_smem.ld) that is
included in the main linker.ld file. This app_smem.ld allows the
compiler and linker to then create each subsection and align to
the next power of 2.
Usage:
- Requires: app_memory/app_memdomain.h .
- _app_dmem(id) marks a variable to be placed into a data
section for memory partition id.
- _app_bmem(id) marks a variable to be placed into a bss
section for memory partition id.
- These are seen in the linker.map as "data_smem_id" and
"data_smem_idb".
- To create a k_mem_partition, call the macro
app_mem_partition(part0) where "part0" is the name then used to
refer to that partition. This macro only creates a function and
necessary data structures for the later "initialization".
- To create a memory domain for the partition, the macro
app_mem_domain(dom0) is called where "dom0" is the name then
used for the memory domain.
- To initialize the partition (effectively adding the partition
to a linked list), init_part_part0() is called. This is followed
by init_app_memory(), which walks all partitions in the linked
list and calculates the sizes for each partition.
- Once the partition is initialized, the domain can be
initialized with init_domain_dom0(part0) which initializes the
domain with partition part0.
- After the domain has been initialized, the current thread
can be added using add_thread_dom0(k_current_get()).
- The code used in ztests ans kernel/init has been added under
a conditional #ifdef to isolate the code from other tests.
The userspace test CMakeLists.txt file has commands to insert
the CONFIG_APP_SHARED_MEM definition into the required build
targets.
Example:
/* create partition at top of file outside functions */
app_mem_partition(part0);
/* create domain */
app_mem_domain(dom0);
_app_dmem(dom0) int var1;
_app_bmem(dom0) static volatile int var2;
int main()
{
init_part_part0();
init_app_memory();
init_domain_dom0(part0);
add_thread_dom0(k_current_get());
...
}
- If multiple partitions are being created, a variadic
preprocessor macro can be used as provided in
app_macro_support.h:
FOR_EACH(app_mem_partition, part0, part1, part2);
or, for multiple domains, similarly:
FOR_EACH(app_mem_domain, dom0, dom1);
Similarly, the init_part_* can also be used in the macro:
FOR_EACH(init_part, part0, part1, part2);
Testing:
- This has been successfully tested on qemu_x86 and the
ARM frdm_k64f board. It compiles and builds power of 2
aligned subsections for the linker script on the 96b_carbon
boards. These power of 2 alignments have been checked by
hand and are viewable in the zephyr.map file that is
produced during build. However, due to a shortage of
available MPU regions on the 96b_carbon board, we are unable
to test this.
- When run on the 96b_carbon board, the test suite will
enter execution, but each individaul test will fail due to
an MPU FAULT. This is expected as the required number of
MPU regions exceeds the number allowed due to the static
allocation. As the MPU driver does not detect this issue,
the fault occurs because the data being accessed has been
placed outside the active MPU region.
- This now compiles successfully for the ARC boards
em_starterkit_em7d and em_starterkit_em7d_v22. However,
as we lack ARC hardware to run this build on, we are unable
to test this build.
Current known issues:
1) While the script and edited CMakeLists.txt creates the
ability to align to the next power of 2, this does not
address the shortage of available MPU regions on certain
devices (e.g. 96b_carbon). In testing the APB and PPB
regions were commented out.
2) checkpatch.pl lists several issues regarding the
following:
a) Complex macros. The FOR_EACH macros as defined in
app_macro_support.h are listed as complex macros needing
parentheses. Adding parentheses breaks their
functionality, and we have otherwise been unable to
resolve the reported error.
b) __aligned() preferred. The _app_dmem_pad() and
_app_bmem_pad() macros give warnings that __aligned()
is preferred. Prior iterations had this implementation,
which resulted in errors due to "complex macros".
c) Trailing semicolon. The macro init_part(name) has
a trailing semicolon as the semicolon is needed for the
inlined macro call that is generated when this macro
expands.
Update: updated to alternative CONFIG_APPLCATION_MEMORY.
Added config option CONFIG_APP_SHARED_MEM to enable a new section
app_smem to contain the shared memory component. This commit
seperates the Kconfig definition from the definition used for the
conditional code. The change is in response to changes in the
way the build system treats definitions. The python script used
to generate a linker script for app_smem was also midified to
simplify the alignment directives. A default linker script
app_smem.ld was added to remove the conditional includes dependency
on CONFIG_APP_SHARED_MEM. By addining the default linker script
the prebuild stages link properly prior to the python script running
Signed-off-by: Joshua Domagalski <jedomag@tycho.nsa.gov>
Signed-off-by: Shawn Mosley <smmosle@tycho.nsa.gov>
2018-04-26 16:14:02 +02:00
|
|
|
|
2019-02-01 21:18:31 +01:00
|
|
|
if(CONFIG_NEWLIB_LIBC)
|
2019-02-21 22:44:54 +01:00
|
|
|
set(NEWLIB_PART -l libc.a z_libc_partition)
|
2019-02-01 21:18:31 +01:00
|
|
|
endif()
|
2019-02-27 23:41:45 +01:00
|
|
|
if(CONFIG_MBEDTLS)
|
2019-05-09 14:43:30 +02:00
|
|
|
set(MBEDTLS_PART -l lib..__modules__crypto__mbedtls.a k_mbedtls_partition)
|
2019-02-27 23:41:45 +01:00
|
|
|
endif()
|
|
|
|
|
2018-12-20 11:17:42 +01:00
|
|
|
add_custom_command(
|
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
|
|
|
OUTPUT ${APP_SMEM_UNALIGNED_LD}
|
2018-12-20 11:17:42 +01:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
|
|
|
${ZEPHYR_BASE}/scripts/gen_app_partitions.py
|
|
|
|
-d ${OBJ_FILE_DIR}
|
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}
|
|
|
|
${NEWLIB_PART} ${MBEDTLS_PART}
|
|
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
|
|
DEPENDS
|
|
|
|
kernel
|
|
|
|
${ZEPHYR_LIBS_PROPERTY}
|
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/
|
|
|
|
COMMENT "Generating app_smem_unaligned linker section"
|
|
|
|
)
|
|
|
|
|
2019-04-29 17:16:54 +02:00
|
|
|
configure_linker_script(
|
2019-04-29 20:27:23 +02:00
|
|
|
linker_app_smem_unaligned.cmd
|
2019-04-29 20:35:12 +02:00
|
|
|
"-DLINKER_APP_SMEM_UNALIGNED"
|
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
|
|
|
${CODE_RELOCATION_DEP}
|
|
|
|
${APP_SMEM_UNALIGNED_DEP}
|
|
|
|
${APP_SMEM_UNALIGNED_LD}
|
|
|
|
${OFFSETS_H_TARGET}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
linker_app_smem_unaligned_script
|
|
|
|
DEPENDS
|
|
|
|
linker_app_smem_unaligned.cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET
|
|
|
|
linker_app_smem_unaligned_script
|
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib)
|
|
|
|
add_executable( app_smem_unaligned_prebuilt misc/empty_file.c)
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_link_elf(
|
|
|
|
TARGET_ELF app_smem_unaligned_prebuilt
|
2019-06-14 01:15:44 +02:00
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/app_smem_unaligned_prebuilt.map
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_PRE_SCRIPT ""
|
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_app_smem_unaligned.cmd
|
|
|
|
LIBRARIES_POST_SCRIPT ""
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_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
|
|
|
set_property(TARGET app_smem_unaligned_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_app_smem_unaligned.cmd)
|
2019-04-29 14:49:33 +02:00
|
|
|
add_dependencies( app_smem_unaligned_prebuilt linker_app_smem_unaligned_script ${OFFSETS_LIB})
|
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(
|
|
|
|
OUTPUT ${APP_SMEM_ALIGNED_LD}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
|
|
|
${ZEPHYR_BASE}/scripts/gen_app_partitions.py
|
|
|
|
-e $<TARGET_FILE:app_smem_unaligned_prebuilt>
|
|
|
|
-o ${APP_SMEM_ALIGNED_LD}
|
2019-02-27 23:41:45 +01:00
|
|
|
${NEWLIB_PART} ${MBEDTLS_PART}
|
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}
|
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
|
|
|
app_smem_unaligned_prebuilt
|
2018-12-20 11:17:42 +01:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/
|
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()
|
|
|
|
|
2019-02-01 00:53:24 +01:00
|
|
|
if(CONFIG_USERSPACE AND CONFIG_ARM)
|
2019-04-29 17:16:54 +02:00
|
|
|
configure_linker_script(
|
2019-04-29 20:27:23 +02:00
|
|
|
linker_priv_stacks.cmd
|
2019-04-29 20:35:12 +02:00
|
|
|
""
|
2019-02-08 15:49:57 +01:00
|
|
|
${CODE_RELOCATION_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
|
|
|
${APP_SMEM_ALIGNED_DEP}
|
|
|
|
${APP_SMEM_ALIGNED_LD}
|
2019-02-08 15:49:57 +01:00
|
|
|
${OFFSETS_H_TARGET}
|
2019-02-08 15:39:37 +01:00
|
|
|
)
|
2018-02-01 08:19:49 +01:00
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
linker_priv_stacks_script
|
|
|
|
DEPENDS
|
|
|
|
linker_priv_stacks.cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET
|
|
|
|
linker_priv_stacks_script
|
|
|
|
PROPERTY INCLUDE_DIRECTORIES
|
|
|
|
${ZEPHYR_INCLUDE_DIRS}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(PRIV_STACK_LIB priv_stacks_output_obj_renamed_lib)
|
|
|
|
add_executable( priv_stacks_prebuilt misc/empty_file.c)
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_link_elf(
|
|
|
|
TARGET_ELF priv_stacks_prebuilt
|
2019-06-14 01:15:44 +02:00
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/priv_stacks_prebuilt.map
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_PRE_SCRIPT ""
|
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd
|
|
|
|
LIBRARIES_POST_SCRIPT ""
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2018-02-01 08:19:49 +01:00
|
|
|
set_property(TARGET priv_stacks_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd)
|
2019-04-29 14:49:33 +02:00
|
|
|
add_dependencies( priv_stacks_prebuilt linker_priv_stacks_script ${OFFSETS_LIB})
|
2018-02-12 12:17:04 +01:00
|
|
|
endif()
|
2018-02-01 08:19:49 +01:00
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# FIXME: Is there any way to get rid of empty_file.c?
|
2019-01-14 16:31:02 +01:00
|
|
|
add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c)
|
2019-05-07 16:32:36 +02:00
|
|
|
toolchain_ld_link_elf(
|
|
|
|
TARGET_ELF ${ZEPHYR_PREBUILT_EXECUTABLE}
|
2019-06-14 01:15:44 +02:00
|
|
|
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_PREBUILT_EXECUTABLE}.map
|
2019-05-07 16:32:36 +02:00
|
|
|
LIBRARIES_PRE_SCRIPT ""
|
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd
|
|
|
|
LIBRARIES_POST_SCRIPT ${PRIV_STACK_LIB}
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2019-01-14 16:31:02 +01:00
|
|
|
set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd)
|
2019-04-29 14:49:33 +02:00
|
|
|
add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${PRIV_STACK_DEP} ${LINKER_SCRIPT_TARGET} ${OFFSETS_LIB})
|
2017-10-27 15:43:34 +02:00
|
|
|
|
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.
|
|
|
|
set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE})
|
|
|
|
else()
|
2017-10-27 15:43:34 +02:00
|
|
|
# The second linker pass uses the same source linker script of the
|
2017-12-31 10:39:23 +01:00
|
|
|
# first pass (LINKER_SCRIPT), but this time with a different output
|
|
|
|
# file and preprocessed with the define LINKER_PASS2.
|
2019-04-29 17:16:54 +02:00
|
|
|
configure_linker_script(
|
2019-04-29 20:27:23 +02:00
|
|
|
linker_pass_final.cmd
|
2019-04-29 20:35:12 +02:00
|
|
|
"-DLINKER_PASS2"
|
2019-02-08 15:49:57 +01:00
|
|
|
${PRIV_STACK_DEP}
|
|
|
|
${CODE_RELOCATION_DEP}
|
|
|
|
${ZEPHYR_PREBUILT_EXECUTABLE}
|
|
|
|
${OFFSETS_H_TARGET}
|
2019-02-08 15:39:37 +01:00
|
|
|
)
|
2018-02-01 08:12:32 +01:00
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
set(LINKER_PASS_FINAL_SCRIPT_TARGET linker_pass_final_script_target)
|
2017-10-27 15:43:34 +02:00
|
|
|
add_custom_target(
|
2019-01-14 16:39:33 +01:00
|
|
|
${LINKER_PASS_FINAL_SCRIPT_TARGET}
|
2017-10-27 15:43:34 +02:00
|
|
|
DEPENDS
|
2018-01-25 18:07:03 +01:00
|
|
|
linker_pass_final.cmd
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
2017-12-14 13:03:23 +01:00
|
|
|
set_property(TARGET
|
2019-01-14 16:39:33 +01:00
|
|
|
${LINKER_PASS_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
|
|
|
|
2019-05-07 15:20:20 +02:00
|
|
|
add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${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}
|
|
|
|
LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_pass_final.cmd
|
|
|
|
LIBRARIES_POST_SCRIPT ""
|
|
|
|
DEPENDENCIES ${CODE_RELOCATION_DEP}
|
|
|
|
)
|
2019-05-07 15:20:20 +02:00
|
|
|
set_property(TARGET ${ZEPHYR_FINAL_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd)
|
|
|
|
add_dependencies( ${ZEPHYR_FINAL_EXECUTABLE} ${PRIV_STACK_DEP} ${LINKER_PASS_FINAL_SCRIPT_TARGET})
|
|
|
|
|
|
|
|
# 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
|
|
|
|
cmake -E rename ${logical_target_for_zephyr_elf}.map ${KERNEL_MAP_NAME}
|
|
|
|
)
|
|
|
|
|
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.
|
2019-08-01 07:56:45 +02:00
|
|
|
set(GAP_FILL "0xff")
|
2018-11-26 10:47:16 +01:00
|
|
|
endif()
|
|
|
|
|
2019-07-18 15:16:39 +02:00
|
|
|
if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE)
|
|
|
|
# @Intent: Use the toolchain bintools method for printing memory usage
|
|
|
|
set(memUsageCmd "")
|
|
|
|
set(memUsageByProd "")
|
|
|
|
bintools_print_mem_usage(
|
|
|
|
RESULT_CMD_LIST memUsageCmd
|
|
|
|
RESULT_BYPROD_LIST memUsageByProd
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
${memUsageCmd}
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${memUsageByProd}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2019-05-10 10:06:32 +02:00
|
|
|
if(CONFIG_BUILD_OUTPUT_HEX)
|
2019-08-01 07:56:45 +02:00
|
|
|
set(out_hex_cmd "")
|
|
|
|
set(out_hex_byprod "")
|
|
|
|
set(out_hex_sections_remove
|
|
|
|
.comment
|
|
|
|
COMMON
|
|
|
|
.eh_frame
|
|
|
|
)
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST out_hex_cmd
|
|
|
|
RESULT_BYPROD_LIST out_hex_byprod
|
|
|
|
STRIP_ALL
|
|
|
|
GAP_FILL ${GAP_FILL}
|
|
|
|
TARGET_OUTPUT "ihex"
|
|
|
|
SECTION_REMOVE ${out_hex_sections_remove}
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_HEX_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_hex_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_HEX_NAME}
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_hex_byprod}
|
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)
|
2019-08-01 07:56:45 +02:00
|
|
|
set(out_bin_cmd "")
|
|
|
|
set(out_bin_byprod "")
|
|
|
|
set(out_bin_sections_remove
|
|
|
|
.comment
|
|
|
|
COMMON
|
|
|
|
.eh_frame
|
|
|
|
)
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST out_bin_cmd
|
|
|
|
RESULT_BYPROD_LIST out_bin_byprod
|
|
|
|
STRIP_ALL
|
|
|
|
GAP_FILL ${GAP_FILL}
|
|
|
|
TARGET_OUTPUT "binary"
|
|
|
|
SECTION_REMOVE ${out_bin_sections_remove}
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_BIN_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_bin_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_BIN_NAME}
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_bin_byprod}
|
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_BUILD_OUTPUT_S19)
|
2019-08-01 07:56:45 +02:00
|
|
|
set(out_S19_cmd "")
|
|
|
|
set(out_S19_byprod "")
|
|
|
|
bintools_objcopy(
|
|
|
|
RESULT_CMD_LIST out_S19_cmd
|
|
|
|
RESULT_BYPROD_LIST out_S19_byprod
|
|
|
|
GAP_FILL ${GAP_FILL}
|
|
|
|
TARGET_OUTPUT "srec"
|
|
|
|
SREC_LEN 1
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_S19_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_S19_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_S19_NAME}
|
2019-08-01 07:56:45 +02:00
|
|
|
${out_S19_byprod}
|
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)
|
2019-08-01 08:01:39 +02:00
|
|
|
set(out_disassembly_cmd "")
|
|
|
|
set(out_disassembly_byprod "")
|
|
|
|
bintools_objdump(
|
|
|
|
RESULT_CMD_LIST out_disassembly_cmd
|
|
|
|
RESULT_BYPROD_LIST out_disassembly_byprod
|
|
|
|
DISASSEMBLE_SOURCE
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_LST_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 08:01:39 +02:00
|
|
|
${out_disassembly_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_LST_NAME}
|
2019-08-01 08:01:39 +02:00
|
|
|
${out_disassembly_byprod}
|
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_STAT)
|
2019-08-01 08:04:12 +02:00
|
|
|
set(out_stat_cmd "")
|
|
|
|
set(out_stat_byprod "")
|
|
|
|
bintools_readelf(
|
|
|
|
RESULT_CMD_LIST out_stat_cmd
|
|
|
|
RESULT_BYPROD_LIST out_stat_byprod
|
|
|
|
HEADERS
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_STAT_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 08:04:12 +02:00
|
|
|
${out_stat_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_STAT_NAME}
|
2019-08-01 08:04:12 +02:00
|
|
|
${out_stat_byprod}
|
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_BUILD_OUTPUT_STRIPPED)
|
2019-08-01 08:06:54 +02:00
|
|
|
set(out_stripped_cmd "")
|
|
|
|
set(out_stripped_byprod "")
|
|
|
|
bintools_strip(
|
|
|
|
RESULT_CMD_LIST out_stripped_cmd
|
|
|
|
RESULT_BYPROD_LIST out_stripped_byprod
|
|
|
|
STRIP_ALL
|
|
|
|
FILE_INPUT ${KERNEL_ELF_NAME}
|
|
|
|
FILE_OUTPUT ${KERNEL_STRIP_NAME}
|
|
|
|
)
|
2019-05-10 10:06:32 +02:00
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
2019-08-01 08:06:54 +02:00
|
|
|
${out_stripped_cmd}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_STRIP_NAME}
|
2019-08-01 08:06:54 +02:00
|
|
|
${out_stripped_byprod}
|
2019-05-10 10:06:32 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_BUILD_OUTPUT_EXE)
|
|
|
|
list(APPEND
|
|
|
|
post_build_commands
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME}
|
|
|
|
)
|
|
|
|
list(APPEND
|
|
|
|
post_build_byproducts
|
|
|
|
${KERNEL_EXE_NAME}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-23 13:54:26 +01:00
|
|
|
|
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}
|
|
|
|
)
|
|
|
|
|
2019-04-17 08:30:52 +02:00
|
|
|
# Add post_build_commands to post-process the final .elf file produced by
|
|
|
|
# either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable
|
|
|
|
# targets above.
|
2017-11-20 15:37:59 +01:00
|
|
|
add_custom_command(
|
|
|
|
TARGET ${logical_target_for_zephyr_elf}
|
|
|
|
POST_BUILD
|
|
|
|
${post_build_commands}
|
2019-05-10 10:06:32 +02:00
|
|
|
BYPRODUCTS
|
|
|
|
${post_build_byproducts}
|
2019-04-17 08:30:52 +02:00
|
|
|
COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}"
|
2017-10-27 15:43:34 +02:00
|
|
|
# NB: COMMENT only works for some CMake-Generators
|
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}
|
|
|
|
${ZEPHYR_BASE}/scripts/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})
|
2018-12-05 10:15:40 +01:00
|
|
|
list(APPEND FLASH_DEPS mergehex)
|
2018-10-30 08:39:13 +01:00
|
|
|
endif()
|
|
|
|
|
2017-11-22 00:54:55 +01:00
|
|
|
if(EMU_PLATFORM)
|
2018-01-11 15:46:44 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake)
|
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))
|
2017-10-27 15:43:34 +02:00
|
|
|
message(WARNING "
|
|
|
|
------------------------------------------------------------
|
|
|
|
--- WARNING: __ASSERT() statements are globally ENABLED ---
|
2018-05-31 11:05:12 +02:00
|
|
|
--- The kernel will run more slowly and use more memory ---
|
2017-10-27 15:43:34 +02:00
|
|
|
------------------------------------------------------------"
|
2018-12-19 10:40:57 +01:00
|
|
|
)
|
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
|
|
|
|
|
|
|
if(CONFIG_BOARD_DEPRECATED)
|
|
|
|
message(WARNING "
|
|
|
|
WARNING: The board '${BOARD}' is deprecated and will be
|
|
|
|
removed in version ${CONFIG_BOARD_DEPRECATED}"
|
2018-12-19 10:40:57 +01:00
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2019-06-06 20:12:14 +02:00
|
|
|
|
|
|
|
# @Intent: Set compiler specific flags for standard C includes
|
|
|
|
# Done at the very end, so any other system includes which may
|
|
|
|
# be added by Zephyr components were first in list.
|
|
|
|
toolchain_cc_nostdinc()
|