Skip to content

Devicetree DTS alias support#483

Merged
KenVanHoeylandt merged 8 commits intomainfrom
dts-alias-support
Feb 5, 2026
Merged

Devicetree DTS alias support#483
KenVanHoeylandt merged 8 commits intomainfrom
dts-alias-support

Conversation

@KenVanHoeylandt
Copy link
Contributor

@KenVanHoeylandt KenVanHoeylandt commented Feb 5, 2026

Added support for device aliases and phandle type.,

Summary by CodeRabbit

  • New Features

    • Phandle support for device-to-device property references.
    • Recognition of #define-style declarations in device trees.
    • Device nodes may include optional aliases alongside node names.
  • Improvements

    • Flatter, consistent device hierarchy processing for generation.
    • Error and log messages now reference node names for clearer diagnostics.
  • Other

    • Added a static ESP32-based device tree and minor DTS comment updates.

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

The PR adds node aliases, phandle support, and C #define handling across the DTS toolchain. The grammar gains NODE_NAME, NODE_ALIAS, PHANDLE, and DEFINE_C tokens. The Device model now has node_name and node_alias; transformer emits PHANDLE and DEFINE_C nodes. The generator adds write_define, gather_devices, find_phandle, and get_device_node_name_safe, and propagates a flattened devices list through property resolution and all write functions to resolve phandles and use node-based naming. Sample DTS and generated C were updated accordingly.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Devicetree DTS alias support' accurately summarizes the main changes, which add device alias syntax and phandle support throughout the compiler and grammar.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dts-alias-support

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
Buildscripts/DevicetreeCompiler/source/models.py (1)

8-12: Make node_alias optional to reflect missing-alias cases.

Aliases are optional in the grammar/transformer flow, so node_alias can be None. Consider typing it as optional (with a default) to match actual usage and avoid misleading type hints.

🔧 Suggested typing adjustment
-from dataclasses import dataclass
+from dataclasses import dataclass
+from typing import Optional
@@
 class Device:
     node_name: str
-    node_alias: str
+    node_alias: Optional[str] = None
     properties: list
     devices: list
Buildscripts/DevicetreeCompiler/source/generator.py (1)

13-17: Consider defensive sanitization if node names may contain special characters in future.

Current DTS files in this codebase use only simple identifiers (alphanumeric, hyphens, underscores), so the current implementation is sufficient. However, if DTS node names may contain characters like @ or / in the future (or from external device trees), the function should normalize all non-identifier characters. Using node_alias as a fallback would also be safer where available.

🔧 Optional defensive normalization
+import re
@@
 def get_device_node_name_safe(device: Device):
     if device.node_name == "/":
         return "root"
-    else:
-        return device.node_name.replace("-", "_")
+    name = device.node_alias or device.node_name
+    return re.sub(r"[^A-Za-z0-9_]", "_", name)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
Buildscripts/DevicetreeCompiler/source/models.py (1)

8-11: Make node_alias optional to match the grammar.

Aliases are optional and the transformer can pass None. Typing it as optional (with a default) avoids type-checker noise and clarifies intent.

♻️ Suggested typing tweak
-from dataclasses import dataclass
+from dataclasses import dataclass
+from typing import Optional
@@
 class Device:
     node_name: str
-    node_alias: str
+    node_alias: Optional[str] = None
     properties: list
     devices: list
Buildscripts/DevicetreeCompiler/source/transformer.py (1)

33-41: Drop the unused loop index in device().

index is unused; a direct iteration (or renaming to _) avoids the B007 warning.

♻️ Suggested cleanup
-        for index, item in enumerate(tokens):
+        for item in tokens:

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
Buildscripts/DevicetreeCompiler/source/transformer.py (1)

14-17: Remove NodeNameAndAlias — it's unused across the repository.

This dataclass is defined but never referenced anywhere in the codebase. Removing it eliminates dead code and avoids maintaining an unused public API surface.

@KenVanHoeylandt KenVanHoeylandt merged commit 626d0d9 into main Feb 5, 2026
52 checks passed
@KenVanHoeylandt KenVanHoeylandt deleted the dts-alias-support branch February 5, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant