From c9804d24fe10cf5a9c1e14662ea27b5c2f8ce9b1 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 21 May 2021 21:34:58 +0200 Subject: [PATCH] scripts: gen_handles.py: take device start symbol as argument. The current gen_handles.py script uses linker defined symbols. As preparation for support of more linkers the gen_tables.py now takes the device start symbol as argument. For example, armlink and ld uses different symbols. With ld those can be named explicitly, but for armlink the linker decides the names. For ld, Zephyr defines: __device_start For armlink, the symbol is defined as: Image$$
$$Base Therefore knowledge of the linker symbol to be used must be passed to gen_handles.py so that the correct symbol can be used for locating devices. To support this change, the creation of the asm, compiler, compiler-cpp, linker targets has been moved from target_toolchain_flags.cmake to target_toolchain.cmake. All linkers has been updated to support the use of the device_start_symbol on the linker target. List of linkers updated: - ld - lld - arcmwdt Signed-off-by: Torsten Rasmussen --- CMakeLists.txt | 1 + cmake/linker/arcmwdt/target.cmake | 1 + cmake/linker/ld/target.cmake | 1 + cmake/linker/lld/target.cmake | 1 + cmake/target_toolchain.cmake | 6 ++++++ cmake/target_toolchain_flags.cmake | 6 ------ scripts/gen_handles.py | 14 ++++++++++---- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59f861039eb..4a41792546d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -795,6 +795,7 @@ if(CONFIG_HAS_DTS) --output-source dev_handles.c --kernel $ --zephyr-base ${ZEPHYR_BASE} + --start-symbol "$" DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} ) set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c) diff --git a/cmake/linker/arcmwdt/target.cmake b/cmake/linker/arcmwdt/target.cmake index 4675f9344d5..9c0a6271e08 100644 --- a/cmake/linker/arcmwdt/target.cmake +++ b/cmake/linker/arcmwdt/target.cmake @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 +set_property(TARGET linker PROPERTY devices_start_symbol "__device_start") find_program(CMAKE_LINKER ${CROSS_COMPILE}lldac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 571964fcbe9..2bef796673f 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 +set_property(TARGET linker PROPERTY devices_start_symbol "__device_start") if(DEFINED TOOLCHAIN_HOME) # When Toolchain home is defined, then we are cross-compiling, so only look diff --git a/cmake/linker/lld/target.cmake b/cmake/linker/lld/target.cmake index a4d0b2f915d..6aca2d6f35b 100644 --- a/cmake/linker/lld/target.cmake +++ b/cmake/linker/lld/target.cmake @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 +set_property(TARGET linker PROPERTY devices_start_symbol "__device_start") find_program(CMAKE_LINKER ld.lld ) diff --git a/cmake/target_toolchain.cmake b/cmake/target_toolchain.cmake index 1edb6385172..0d8bbc2d32d 100644 --- a/cmake/target_toolchain.cmake +++ b/cmake/target_toolchain.cmake @@ -32,6 +32,12 @@ set(CMAKE_SYSTEM_VERSION ${PROJECT_VERSION}) # We are not building dynamically loadable libraries set(BUILD_SHARED_LIBS OFF) +# Custom targets for compiler and linker flags. +add_custom_target(asm) +add_custom_target(compiler) +add_custom_target(compiler-cpp) +add_custom_target(linker) + if(NOT (COMPILER STREQUAL "host-gcc")) include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/target.cmake) endif() diff --git a/cmake/target_toolchain_flags.cmake b/cmake/target_toolchain_flags.cmake index b74c3e78722..35c1fb08f4f 100644 --- a/cmake/target_toolchain_flags.cmake +++ b/cmake/target_toolchain_flags.cmake @@ -24,12 +24,6 @@ set(TOOLCHAIN_SIGNATURE ${CMAKE_C_COMPILER_MD5_SUM}) string(MD5 COMPILER_SIGNATURE ${CMAKE_C_COMPILER}_${CMAKE_C_COMPILER_ID}_${CMAKE_C_COMPILER_VERSION}) set(TOOLCHAIN_SIGNATURE ${TOOLCHAIN_SIGNATURE}_${COMPILER_SIGNATURE}) -# Custom targets for compiler and linker flags. -add_custom_target(asm) -add_custom_target(compiler) -add_custom_target(compiler-cpp) -add_custom_target(linker) - # Loading of templates are strictly not needed as they does not set any # properties. # They purely provides an overview as well as a starting point for supporting diff --git a/scripts/gen_handles.py b/scripts/gen_handles.py index 441ad6419a4..c8354d9ec83 100755 --- a/scripts/gen_handles.py +++ b/scripts/gen_handles.py @@ -73,6 +73,11 @@ def parse_args(): is not provided the environment will be checked for \ the ZEPHYR_BASE environment variable.") + parser.add_argument("-s", "--start-symbol", required=True, + help="Symbol name of the section which contains the \ + devices. The symbol name must point to the first \ + device in that section.") + args = parser.parse_args() if "VERBOSE" in os.environ: args.verbose = 1 @@ -145,7 +150,7 @@ class Device: else: format += "Q" size = 8 - offset = self.ld_constants["DEVICE_STRUCT_HANDLES_OFFSET"] + offset = self.ld_constants["_DEVICE_STRUCT_HANDLES_OFFSET"] self.__handles = struct.unpack(format, data[offset:offset + size])[0] return self.__handles @@ -172,7 +177,8 @@ def main(): devices = [] handles = [] # Leading _ are stripped from the stored constant key - want_constants = set(["__device_start", + + want_constants = set([args.start_symbol, "_DEVICE_STRUCT_SIZEOF", "_DEVICE_STRUCT_HANDLES_OFFSET"]) ld_constants = dict() @@ -181,7 +187,7 @@ def main(): if isinstance(section, SymbolTableSection): for sym in section.iter_symbols(): if sym.name in want_constants: - ld_constants[sym.name.lstrip("_")] = sym.entry.st_value + ld_constants[sym.name] = sym.entry.st_value continue if sym.entry.st_info.type != 'STT_OBJECT': continue @@ -204,7 +210,7 @@ def main(): devices = sorted(devices, key = lambda k: k.sym.entry.st_value) - device_start_addr = ld_constants["device_start"] + device_start_addr = ld_constants[args.start_symbol] device_size = 0 assert len(devices) == len(handles), 'mismatch devices and handles'