Skip to content

Commit

Permalink
scripts: dts: gen_defines/edtlib: improve encapsulation
Browse files Browse the repository at this point in the history
Moves node sorting concern into EDT.

Signed-off-by: Florian Grandel <[email protected]>
  • Loading branch information
fg-cfh authored and benediktibk committed Sep 10, 2024
1 parent 5b5be31 commit b1c809e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 0 additions & 19 deletions scripts/dts/gen_defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,6 @@ def main():
with open(args.dts_out, "w", encoding="utf-8") as f:
print(edt.dts_source, file=f)

# The raw index into edt.compat2nodes[compat] is used for node
# instance numbering within a compatible.
#
# As a way to satisfy people's intuitions about instance numbers,
# though, we sort this list so enabled instances come first.
#
# This might look like a hack, but it keeps drivers and
# applications which don't use instance numbers carefully working
# as expected, since e.g. instance number 0 is always the
# singleton instance if there's just one enabled node of a
# particular compatible.
#
# This doesn't violate any devicetree.h API guarantees about
# instance ordering, since we make no promises that instance
# numbers are stable across builds.
for compat, nodes in edt.compat2nodes.items():
edt.compat2nodes[compat] = sorted(
nodes, key=lambda node: 0 if node.status == "okay" else 1)

# Create the generated header.
with open(args.header_out, "w", encoding="utf-8") as header_file:
write_top_comment(edt)
Expand Down
19 changes: 19 additions & 0 deletions scripts/dts/python-devicetree/src/devicetree/edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,25 @@ def _init_luts(self) -> None:
f"node '{node.path}' compatible '{compat}' "
f"has unknown vendor prefix '{vendor}'")

# The raw index into edt.compat2nodes[compat] is used for node
# instance numbering within a compatible.
#
# As a way to satisfy people's intuitions about instance numbers,
# we sort this list so enabled instances come first.
#
# This might look like a hack, but it keeps drivers and
# applications which don't use instance numbers carefully working
# as expected, since e.g. instance number 0 is always the
# singleton instance if there's just one enabled node of a
# particular compatible.
#
# This doesn't violate any devicetree.h API guarantees about
# instance ordering, since we make no promises that instance
# numbers are stable across builds.
for compat, nodes in self.compat2nodes.items():
self.compat2nodes[compat] = sorted(
nodes, key=lambda node: 0 if node.status == "okay" else 1
)

for nodeset in self.scc_order:
node = nodeset[0]
Expand Down

0 comments on commit b1c809e

Please sign in to comment.