Skip to content

Commit ec331c6

Browse files
Jordan Yatesnashif
authored andcommitted
device: simplify structure of handles array
Force the inclusion of a `DEVICE_HANDLE_SEP` at the end of the devicetree dependency section of the array. This lets us simplify the implementation of `device_required_handles_get`, as there is only one symbol the section ends with. This does not use any extra ROM as the array is padded out to the original size with `DEVICE_HANDLE_ENDS` anyway. Also adds a description of the array format where the array is instantiated. Signed-off-by: Jordan Yates <[email protected]>
1 parent b5c4140 commit ec331c6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

include/device.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ device_required_handles_get(const struct device *dev,
478478
if (rv != NULL) {
479479
size_t i = 0;
480480

481-
while ((rv[i] != DEVICE_HANDLE_ENDS)
482-
&& (rv[i] != DEVICE_HANDLE_SEP)) {
481+
while (rv[i] != DEVICE_HANDLE_SEP) {
483482
++i;
484483
}
485484
*count = i;
@@ -674,6 +673,22 @@ static inline bool device_is_ready(const struct device *dev)
674673
* in a distinct pass1 section (which will be replaced by
675674
* postprocessing).
676675
*
676+
* Before processing in gen_handles.py, the array format is:
677+
* {
678+
* DEVICE_ORDINAL (or DEVICE_HANDLE_NULL if not a devicetree node),
679+
* List of devicetree dependency ordinals (if any),
680+
* DEVICE_HANDLE_SEP,
681+
* List of injected dependency ordinals (if any),
682+
* }
683+
*
684+
* After processing in gen_handles.py, the format is updated to:
685+
* {
686+
* List of existing devicetree dependency handles (if any),
687+
* DEVICE_HANDLE_SEP,
688+
* List of injected dependency ordinals (if any),
689+
* DEVICE_HANDLE_NULL padding to original length (at least one)
690+
* }
691+
*
677692
* It is also (experimentally) necessary to provide explicit alignment
678693
* on each object. Otherwise x86-64 builds will introduce padding
679694
* between objects in the same input section in individual object

scripts/gen_handles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,11 @@ def main():
294294
dep_paths.append(dn.path)
295295
else:
296296
dep_paths.append('(%s)' % dn.path)
297+
# Force separator to signal start of injected dependencies
298+
hdls.append(DEVICE_HANDLE_SEP)
297299
if len(hs.ext_deps) > 0:
298300
# TODO: map these to something smaller?
299301
ext_paths.extend(map(str, hs.ext_deps))
300-
hdls.append(DEVICE_HANDLE_SEP)
301302
hdls.extend(hs.ext_deps)
302303

303304
# When CONFIG_USERSPACE is enabled the pre-built elf is

0 commit comments

Comments
 (0)