Skip to content

zephyr-build: Simplify dt-yaml syntax #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 25 additions & 43 deletions dt-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
# few instances were we can actually just match on a property.
- name: gpio-controller
rules:
- type: has_prop
value: gpio-controller
- !HasProp gpio-controller
actions:
- type: instance
value:
raw:
type: myself
- !Instance
raw: !Myself
device: crate::device::gpio::Gpio
static_type: crate::device::gpio::GpioStatic

Expand All @@ -22,68 +19,53 @@
# with each gpio.
- name: gpio-leds
rules:
- type: compatible
value:
names:
- gpio-leds
- !Compatible
names: [gpio-leds]
level: 1
actions:
- type: instance
value:
raw:
type: phandle
value: gpios
- !Instance
raw: !Phandle gpios
device: crate::device::gpio::GpioPin

# Flash controllers don't have any particular property to identify them, so we need a list of
# compatible values that should match.
- name: flash-controller
rules:
- type: compatible
value:
- !Compatible
names:
- "nordic,nrf52-flash-controller"
- "nordic,nrf51-flash-controller"
- "raspberrypi,pico-flash-controller"
- "zephyr,sim-flash"
- "nordic,nrf52-flash-controller"
- "nordic,nrf51-flash-controller"
- "raspberrypi,pico-flash-controller"
- "zephyr,sim-flash"
level: 0
actions:
- type: instance
value:
raw:
type: myself
- !Instance
raw: !Myself
device: crate::device::flash::FlashController

# Flash partitions exist as children of a node compatible with "soc-nv-flash" that itself is a child
# of the controller itself.
# TODO: Get the write and erase property from the DT if present.
- name: flash-partition
rules:
- type: compatible
value:
- !Compatible
names:
- "fixed-partitions"
- "fixed-partitions"
level: 1
- type: compatible
value:
- !Compatible
names:
- "soc-nv-flash"
- "soc-nv-flash"
level: 2
actions:
- type: instance
value:
raw:
type: parent
value:
level: 3
args:
- type: reg
- !Instance
raw: !Parent
level: 3
args:
- !Reg
device: "crate::device::flash::FlashPartition"

# Generate a pseudo node that matches all of the labels across the tree with their nodes.
- name: labels
rules:
- type: root
rules: !Root
actions:
- type: labels

- !Labels
4 changes: 0 additions & 4 deletions zephyr-build/src/devicetree/augment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl Augment for Augmentation {

/// A matching rule.
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", content = "value")]
pub enum Rule {
/// A set of "or" matches.
Or(Vec<Rule>),
Expand Down Expand Up @@ -121,7 +120,6 @@ fn parent_compatible(node: &Node, names: &[String], level: usize) -> bool {

/// An action to perform
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", content = "value")]
pub enum Action {
/// Generate an "instance" with a specific device name.
Instance {
Expand Down Expand Up @@ -171,7 +169,6 @@ impl Action {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", content = "value")]
pub enum RawInfo {
/// Get the raw device directly from this node.
Myself,
Expand Down Expand Up @@ -270,7 +267,6 @@ impl RawInfo {
///
/// At this point, we assume these all come from the current node.
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", content = "value")]
pub enum ArgInfo {
/// The arguments come from a 'reg' property.
Reg,
Expand Down