-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
658 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use super::{FallibleNode, Node}; | ||
use crate::parsing::{NoPanic, ParserWithMode}; | ||
|
||
/// [Devicetree 3.3. `/aliases` | ||
/// node](https://devicetree-specification.readthedocs.io/en/latest/chapter3-devicenodes.html#aliases-node) | ||
/// | ||
/// A devicetree may have an aliases node (`/aliases`) that defines one or more | ||
/// alias properties. The alias node shall be at the root of the devicetree and | ||
/// have the node name `/aliases`. | ||
/// | ||
/// Each property of the `/aliases` node defines an alias. The property name | ||
/// specifies the alias name. The property value specifies the full path to a | ||
/// node in the devicetree. For example, the property `serial0 = | ||
/// "/simple-bus@fe000000/serial@llc500"` defines the alias `serial0`. | ||
/// | ||
/// An alias value is a device path and is encoded as a string. The value | ||
/// represents the full path to a node, but the path does not need to refer to a | ||
/// leaf node. | ||
/// | ||
/// A client program may use an alias property name to refer to a full device | ||
/// path as all or part of its string value. A client program, when considering | ||
/// a string as a device path, shall detect and use the alias. | ||
/// | ||
/// ### Example | ||
/// | ||
/// ```norust | ||
/// aliases { | ||
/// serial0 = "/simple-bus@fe000000/serial@llc500"; | ||
/// ethernet0 = "/simple-bus@fe000000/ethernet@31c000"; | ||
/// }; | ||
/// ``` | ||
/// | ||
/// Given the alias `serial0`, a client program can look at the `/aliases` node | ||
/// and determine the alias refers to the device path | ||
/// `/simple-bus@fe000000/serial@llc500`. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct Aliases<'a, P: ParserWithMode<'a>> { | ||
pub(crate) node: FallibleNode<'a, P>, | ||
} | ||
|
||
impl<'a, P: ParserWithMode<'a>> Aliases<'a, P> { | ||
/// Attempt to resolve an alias to a node name. | ||
pub fn resolve_name(self, alias: &str) -> P::Output<Option<&'a str>> { | ||
P::to_output(crate::tryblock!({ | ||
self.node.properties()?.find(alias)?.map(|p| p.as_value().map_err(Into::into)).transpose() | ||
})) | ||
} | ||
|
||
/// Attempt resolve an alias to the aliased-to node. | ||
pub fn resolve(self, alias: &str) -> P::Output<Option<Node<'a, P>>> { | ||
P::to_output(crate::tryblock!({ | ||
let Some(path) = Aliases::<(_, NoPanic)> { node: self.node }.resolve_name(alias)? else { | ||
return Ok(None); | ||
}; | ||
|
||
self.node.make_root::<P::Parser>()?.find_node(path).map(|r| r.map(|n| n.alt())) | ||
})) | ||
} | ||
} |
Oops, something went wrong.