Skip to content

Commit c9804d2

Browse files
tejlmandnashif
authored andcommitted
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 <[email protected]>
1 parent a9db9a3 commit c9804d2

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ if(CONFIG_HAS_DTS)
795795
--output-source dev_handles.c
796796
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
797797
--zephyr-base ${ZEPHYR_BASE}
798+
--start-symbol "$<TARGET_PROPERTY:linker,devices_start_symbol>"
798799
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
799800
)
800801
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c)

cmake/linker/arcmwdt/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
set_property(TARGET linker PROPERTY devices_start_symbol "__device_start")
23

34
find_program(CMAKE_LINKER ${CROSS_COMPILE}lldac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
45

cmake/linker/ld/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
set_property(TARGET linker PROPERTY devices_start_symbol "__device_start")
23

34
if(DEFINED TOOLCHAIN_HOME)
45
# When Toolchain home is defined, then we are cross-compiling, so only look

cmake/linker/lld/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
set_property(TARGET linker PROPERTY devices_start_symbol "__device_start")
23

34
find_program(CMAKE_LINKER ld.lld )
45

cmake/target_toolchain.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ set(CMAKE_SYSTEM_VERSION ${PROJECT_VERSION})
3232
# We are not building dynamically loadable libraries
3333
set(BUILD_SHARED_LIBS OFF)
3434

35+
# Custom targets for compiler and linker flags.
36+
add_custom_target(asm)
37+
add_custom_target(compiler)
38+
add_custom_target(compiler-cpp)
39+
add_custom_target(linker)
40+
3541
if(NOT (COMPILER STREQUAL "host-gcc"))
3642
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/target.cmake)
3743
endif()

cmake/target_toolchain_flags.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ set(TOOLCHAIN_SIGNATURE ${CMAKE_C_COMPILER_MD5_SUM})
2424
string(MD5 COMPILER_SIGNATURE ${CMAKE_C_COMPILER}_${CMAKE_C_COMPILER_ID}_${CMAKE_C_COMPILER_VERSION})
2525
set(TOOLCHAIN_SIGNATURE ${TOOLCHAIN_SIGNATURE}_${COMPILER_SIGNATURE})
2626

27-
# Custom targets for compiler and linker flags.
28-
add_custom_target(asm)
29-
add_custom_target(compiler)
30-
add_custom_target(compiler-cpp)
31-
add_custom_target(linker)
32-
3327
# Loading of templates are strictly not needed as they does not set any
3428
# properties.
3529
# They purely provides an overview as well as a starting point for supporting

scripts/gen_handles.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def parse_args():
7373
is not provided the environment will be checked for \
7474
the ZEPHYR_BASE environment variable.")
7575

76+
parser.add_argument("-s", "--start-symbol", required=True,
77+
help="Symbol name of the section which contains the \
78+
devices. The symbol name must point to the first \
79+
device in that section.")
80+
7681
args = parser.parse_args()
7782
if "VERBOSE" in os.environ:
7883
args.verbose = 1
@@ -145,7 +150,7 @@ def obj_handles(self):
145150
else:
146151
format += "Q"
147152
size = 8
148-
offset = self.ld_constants["DEVICE_STRUCT_HANDLES_OFFSET"]
153+
offset = self.ld_constants["_DEVICE_STRUCT_HANDLES_OFFSET"]
149154
self.__handles = struct.unpack(format, data[offset:offset + size])[0]
150155
return self.__handles
151156

@@ -172,7 +177,8 @@ def main():
172177
devices = []
173178
handles = []
174179
# Leading _ are stripped from the stored constant key
175-
want_constants = set(["__device_start",
180+
181+
want_constants = set([args.start_symbol,
176182
"_DEVICE_STRUCT_SIZEOF",
177183
"_DEVICE_STRUCT_HANDLES_OFFSET"])
178184
ld_constants = dict()
@@ -181,7 +187,7 @@ def main():
181187
if isinstance(section, SymbolTableSection):
182188
for sym in section.iter_symbols():
183189
if sym.name in want_constants:
184-
ld_constants[sym.name.lstrip("_")] = sym.entry.st_value
190+
ld_constants[sym.name] = sym.entry.st_value
185191
continue
186192
if sym.entry.st_info.type != 'STT_OBJECT':
187193
continue
@@ -204,7 +210,7 @@ def main():
204210

205211
devices = sorted(devices, key = lambda k: k.sym.entry.st_value)
206212

207-
device_start_addr = ld_constants["device_start"]
213+
device_start_addr = ld_constants[args.start_symbol]
208214
device_size = 0
209215

210216
assert len(devices) == len(handles), 'mismatch devices and handles'

0 commit comments

Comments
 (0)