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$$<section name>$$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 <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
a9db9a3aa8
commit
c9804d24fe
7 changed files with 20 additions and 10 deletions
|
@ -795,6 +795,7 @@ if(CONFIG_HAS_DTS)
|
||||||
--output-source dev_handles.c
|
--output-source dev_handles.c
|
||||||
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
|
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
|
||||||
--zephyr-base ${ZEPHYR_BASE}
|
--zephyr-base ${ZEPHYR_BASE}
|
||||||
|
--start-symbol "$<TARGET_PROPERTY:linker,devices_start_symbol>"
|
||||||
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
|
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
|
||||||
)
|
)
|
||||||
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c)
|
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# 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)
|
find_program(CMAKE_LINKER ${CROSS_COMPILE}lldac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
set_property(TARGET linker PROPERTY devices_start_symbol "__device_start")
|
||||||
|
|
||||||
if(DEFINED TOOLCHAIN_HOME)
|
if(DEFINED TOOLCHAIN_HOME)
|
||||||
# When Toolchain home is defined, then we are cross-compiling, so only look
|
# When Toolchain home is defined, then we are cross-compiling, so only look
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
set_property(TARGET linker PROPERTY devices_start_symbol "__device_start")
|
||||||
|
|
||||||
find_program(CMAKE_LINKER ld.lld )
|
find_program(CMAKE_LINKER ld.lld )
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,12 @@ set(CMAKE_SYSTEM_VERSION ${PROJECT_VERSION})
|
||||||
# We are not building dynamically loadable libraries
|
# We are not building dynamically loadable libraries
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
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"))
|
if(NOT (COMPILER STREQUAL "host-gcc"))
|
||||||
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/target.cmake)
|
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/target.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -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})
|
string(MD5 COMPILER_SIGNATURE ${CMAKE_C_COMPILER}_${CMAKE_C_COMPILER_ID}_${CMAKE_C_COMPILER_VERSION})
|
||||||
set(TOOLCHAIN_SIGNATURE ${TOOLCHAIN_SIGNATURE}_${COMPILER_SIGNATURE})
|
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
|
# Loading of templates are strictly not needed as they does not set any
|
||||||
# properties.
|
# properties.
|
||||||
# They purely provides an overview as well as a starting point for supporting
|
# They purely provides an overview as well as a starting point for supporting
|
||||||
|
|
|
@ -73,6 +73,11 @@ def parse_args():
|
||||||
is not provided the environment will be checked for \
|
is not provided the environment will be checked for \
|
||||||
the ZEPHYR_BASE environment variable.")
|
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()
|
args = parser.parse_args()
|
||||||
if "VERBOSE" in os.environ:
|
if "VERBOSE" in os.environ:
|
||||||
args.verbose = 1
|
args.verbose = 1
|
||||||
|
@ -145,7 +150,7 @@ class Device:
|
||||||
else:
|
else:
|
||||||
format += "Q"
|
format += "Q"
|
||||||
size = 8
|
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]
|
self.__handles = struct.unpack(format, data[offset:offset + size])[0]
|
||||||
return self.__handles
|
return self.__handles
|
||||||
|
|
||||||
|
@ -172,7 +177,8 @@ def main():
|
||||||
devices = []
|
devices = []
|
||||||
handles = []
|
handles = []
|
||||||
# Leading _ are stripped from the stored constant key
|
# Leading _ are stripped from the stored constant key
|
||||||
want_constants = set(["__device_start",
|
|
||||||
|
want_constants = set([args.start_symbol,
|
||||||
"_DEVICE_STRUCT_SIZEOF",
|
"_DEVICE_STRUCT_SIZEOF",
|
||||||
"_DEVICE_STRUCT_HANDLES_OFFSET"])
|
"_DEVICE_STRUCT_HANDLES_OFFSET"])
|
||||||
ld_constants = dict()
|
ld_constants = dict()
|
||||||
|
@ -181,7 +187,7 @@ def main():
|
||||||
if isinstance(section, SymbolTableSection):
|
if isinstance(section, SymbolTableSection):
|
||||||
for sym in section.iter_symbols():
|
for sym in section.iter_symbols():
|
||||||
if sym.name in want_constants:
|
if sym.name in want_constants:
|
||||||
ld_constants[sym.name.lstrip("_")] = sym.entry.st_value
|
ld_constants[sym.name] = sym.entry.st_value
|
||||||
continue
|
continue
|
||||||
if sym.entry.st_info.type != 'STT_OBJECT':
|
if sym.entry.st_info.type != 'STT_OBJECT':
|
||||||
continue
|
continue
|
||||||
|
@ -204,7 +210,7 @@ def main():
|
||||||
|
|
||||||
devices = sorted(devices, key = lambda k: k.sym.entry.st_value)
|
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
|
device_size = 0
|
||||||
|
|
||||||
assert len(devices) == len(handles), 'mismatch devices and handles'
|
assert len(devices) == len(handles), 'mismatch devices and handles'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue