Skip to content

Commit 971dfa6

Browse files
tejlmandkartben
authored andcommitted
device: export CMake pre-load from device subsystem enumeration script
Extend the device subsystem enumeration script to produce a CMake pre-load script. This allow CMake linker generator scripts to create iterable sections based on output from device subsystem enumeration. This ensures that same functionality is available in both ld linker templates and the linker generator. Update linker generators to support the use of the device subsystem enumeration CMake pre-load script. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 0332770 commit 971dfa6

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,21 +889,30 @@ set(
889889
${CMAKE_CURRENT_BINARY_DIR}/include/generated/device-api-sections.ld
890890
)
891891

892+
set(DEVICE_API_LINKER_SECTIONS_CMAKE
893+
${CMAKE_CURRENT_BINARY_DIR}/include/generated/device-api-sections.cmake
894+
)
895+
892896
add_custom_command(
893-
OUTPUT ${DEVICE_API_LD_SECTIONS}
897+
OUTPUT ${DEVICE_API_LD_SECTIONS} ${DEVICE_API_LINKER_SECTIONS_CMAKE}
894898
COMMAND
895899
${PYTHON_EXECUTABLE}
896900
${ZEPHYR_BASE}/scripts/build/gen_iter_sections.py
901+
--alignment ${CONFIG_LINKER_ITERABLE_SUBALIGN}
897902
--input ${struct_tags_json}
898903
--tag __subsystem
899904
--ld-output ${DEVICE_API_LD_SECTIONS}
905+
--cmake-output ${DEVICE_API_LINKER_SECTIONS_CMAKE}
900906
DEPENDS
901907
${ZEPHYR_BASE}/scripts/build/gen_iter_sections.py
902908
${struct_tags_json}
903909
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
904910
)
905911

906-
add_custom_target(${DEVICE_API_LD_TARGET} DEPENDS ${DEVICE_API_LD_SECTIONS})
912+
add_custom_target(${DEVICE_API_LD_TARGET}
913+
DEPENDS ${DEVICE_API_LD_SECTIONS}
914+
${DEVICE_API_LINKER_SECTIONS_CMAKE}
915+
)
907916

908917
# Add a pseudo-target that is up-to-date when all generated headers
909918
# are up-to-date.

cmake/linker/armlink/target.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
4444
${STEERING_FILE}
4545
${STEERING_C}
4646
COMMAND ${CMAKE_COMMAND}
47+
-C ${DEVICE_API_LINKER_SECTIONS_CMAKE}
4748
-C ${cmake_linker_script_settings}
4849
-DPASS="${linker_pass_define}"
4950
${STEERING_FILE_ARG}
5051
${STEERING_C_ARG}
5152
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
5253
-P ${ZEPHYR_BASE}/cmake/linker/armlink/scatter_script.cmake
54+
DEPENDS ${DEVICE_API_LD_TARGET}
5355
)
5456

5557
if("LINKER_ZEPHYR_FINAL" IN_LIST linker_pass_define_list)

cmake/linker/ld/target.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
3636
add_custom_command(
3737
OUTPUT ${linker_script_gen}
3838
COMMAND ${CMAKE_COMMAND}
39+
-C ${DEVICE_API_LINKER_SECTIONS_CMAKE}
3940
-C ${cmake_linker_script_settings}
4041
-DPASS="${linker_pass_define}"
4142
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
4243
-P ${ZEPHYR_BASE}/cmake/linker/ld/ld_script.cmake
44+
DEPENDS ${DEVICE_API_LD_TARGET}
4345
)
4446
else()
4547
set(template_script_defines ${linker_pass_define})

cmake/linker/linker_script_common.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function(create_section)
132132
set(INDEX 100)
133133
set(settings_single "ALIGN;ANY;FIRST;KEEP;OFFSET;PRIO;SECTION;SORT")
134134
set(settings_multi "FLAGS;INPUT;PASS;SYMBOLS")
135-
foreach(settings ${SECTION_SETTINGS})
135+
foreach(settings ${SECTION_SETTINGS} ${DEVICE_API_SECTION_SETTINGS})
136136
if("${settings}" MATCHES "^{(.*)}$")
137137
cmake_parse_arguments(SETTINGS "" "${settings_single}" "${settings_multi}" ${CMAKE_MATCH_1})
138138

@@ -652,7 +652,7 @@ foreach(group ${GROUPS})
652652
endif()
653653
endforeach()
654654

655-
foreach(section ${SECTIONS})
655+
foreach(section ${SECTIONS} ${DEVICE_API_SECTIONS})
656656
if("${section}" MATCHES "^{(.*)}$")
657657
create_section(${CMAKE_MATCH_1} SYSTEM ${new_system})
658658
endif()

scripts/build/gen_iter_sections.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,30 @@ def get_tagged_items(filepath: str, tag: str) -> list:
1616
return json.load(fp)[tag]
1717

1818

19-
def gen_ld(filepath: str, items: list):
19+
def gen_ld(filepath: str, items: list, alignment: int):
2020
with open(filepath, "w") as fp:
2121
for item in items:
22-
fp.write(f"ITERABLE_SECTION_ROM({item}, Z_LINK_ITERABLE_SUBALIGN)\n")
22+
fp.write(f"ITERABLE_SECTION_ROM({item}, {alignment})\n")
23+
24+
25+
def gen_cmake(filepath: str, items: list, alignment: int):
26+
with open(filepath, "w") as fp:
27+
for item in items:
28+
fp.write(
29+
f'list(APPEND sections "{{NAME\\;{item}_area\\;'
30+
+ 'GROUP\\;RODATA_REGION\\;'
31+
+ f'SUBALIGN\\;{alignment}\\;'
32+
+ 'NOINPUT\\;TRUE}")\n'
33+
)
34+
fp.write(
35+
f'list(APPEND section_settings "{{SECTION\\;{item}_area\\;'
36+
+ 'SORT\\;NAME\\;'
37+
+ 'KEEP\\;TRUE\\;'
38+
+ f'INPUT\\;._{item}.static.*\\;'
39+
+ f'SYMBOLS\\;_{item}_list_start\\;_{item}_list_end}}")\n'
40+
)
41+
fp.write('set(DEVICE_API_SECTIONS "${sections}" CACHE INTERNAL "")\n')
42+
fp.write('set(DEVICE_API_SECTION_SETTINGS "${section_settings}" CACHE INTERNAL "")\n')
2343

2444

2545
def parse_args() -> argparse.Namespace:
@@ -30,8 +50,12 @@ def parse_args() -> argparse.Namespace:
3050
)
3151

3252
parser.add_argument("-i", "--input", required=True, help="Path to input list of tags")
53+
parser.add_argument("-a", "--alignment", required=True, help="Iterable section alignment")
3354
parser.add_argument("-t", "--tag", required=True, help="Tag to generate iterable sections for")
3455
parser.add_argument("-l", "--ld-output", required=True, help="Path to output linker file")
56+
parser.add_argument(
57+
"-c", "--cmake-output", required=True, help="Path to CMake linker script inclusion file"
58+
)
3559

3660
return parser.parse_args()
3761

@@ -41,7 +65,8 @@ def main():
4165

4266
items = get_tagged_items(args.input, args.tag)
4367

44-
gen_ld(args.ld_output, items)
68+
gen_ld(args.ld_output, items, args.alignment)
69+
gen_cmake(args.cmake_output, items, args.alignment)
4570

4671

4772
if __name__ == "__main__":

0 commit comments

Comments
 (0)