Skip to content

Commit e5335f3

Browse files
gmarullnashif
authored andcommitted
device: dynamic device handles were declared as const
When CONFIG_HAS_DYNAMIC_DEVICE_HANDLES is selected, devices handles are placed in RAM region so that they can be modified at runtime. However, the gen_handles.py script added the `const` attribute to the device handle arrays regardless of this setting, leading to faults when running the application. This may be an indicator that this feature is not actively used. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 9f25fa2 commit e5335f3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ zephyr_get_include_directories_for_lang(C
897897
)
898898

899899
if(CONFIG_HAS_DTS)
900+
if(CONFIG_HAS_DYNAMIC_DEVICE_HANDLES)
901+
set(dynamic_handles --dynamic-handles)
902+
endif()
903+
900904
if(CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC)
901905
set(number_of_dynamic_devices ${CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM})
902906
else()
@@ -912,6 +916,7 @@ if(CONFIG_HAS_DTS)
912916
${ZEPHYR_BASE}/scripts/build/gen_handles.py
913917
--output-source dev_handles.c
914918
--output-graphviz dev_graph.dot
919+
${dynamic_handles}
915920
--num-dynamic-devices ${number_of_dynamic_devices}
916921
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
917922
--zephyr-base ${ZEPHYR_BASE}

scripts/build/gen_handles.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def parse_args():
4646

4747
parser.add_argument("-k", "--kernel", required=True,
4848
help="Input zephyr ELF binary")
49+
parser.add_argument("--dynamic-handles", action="store_true",
50+
help="Indicates if device handles are dynamic")
4951
parser.add_argument("-d", "--num-dynamic-devices", required=False, default=0,
5052
type=int, help="Input number of dynamic devices allowed")
5153
parser.add_argument("-o", "--output-source", required=True,
@@ -93,7 +95,7 @@ def dev_path_str(dev):
9395
lines.append(' */')
9496
return lines
9597

96-
def c_handle_array(dev, handles, extra_support_handles=0):
98+
def c_handle_array(dev, handles, dynamic_handles, extra_support_handles=0):
9799
handles = [
98100
*[str(d.handle) for d in handles["depends"]],
99101
'DEVICE_HANDLE_SEP',
@@ -103,7 +105,10 @@ def c_handle_array(dev, handles, extra_support_handles=0):
103105
*(extra_support_handles * ['DEVICE_HANDLE_NULL']),
104106
'DEVICE_HANDLE_ENDS',
105107
]
106-
ctype = 'const Z_DECL_ALIGN(device_handle_t) __attribute__((__section__(".__device_handles_pass2")))'
108+
ctype = (
109+
'{:s}Z_DECL_ALIGN(device_handle_t) '
110+
'__attribute__((__section__(".__device_handles_pass2")))'
111+
).format('const ' if not dynamic_handles else '')
107112
return [
108113
# The `extern` line pretends this was first declared in some .h
109114
# file to silence "should it be static?" warnings in some
@@ -153,7 +158,9 @@ def main():
153158
}
154159
extra_sups = args.num_dynamic_devices if dev.pm and dev.pm.is_power_domain else 0
155160
lines = c_handle_comment(dev, sorted_handles)
156-
lines.extend(c_handle_array(dev, sorted_handles, extra_sups))
161+
lines.extend(
162+
c_handle_array(dev, sorted_handles, args.dynamic_handles, extra_sups)
163+
)
157164
lines.extend([''])
158165
fp.write('\n'.join(lines))
159166

0 commit comments

Comments
 (0)