[−][src]Struct fdt_rs::DevTree
A parseable Flattened Device Tree.
This parser was written according to the v0.3 specification provided at https://www.devicetree.org/
Implementations
impl<'a> DevTree<'a>
[src]
pub const MIN_HEADER_SIZE: usize
[src]
pub unsafe fn verify_magic(buf: &[u8]) -> Result<(), DevTreeError>
[src]
Verify the magic header of a Device Tree buffer
Safety
Callers of this method the must guarantee the following:
- The passed buffer is 32-bit aligned.
The passed byte buffer will be interpreted as a Flattened Device Tree. For this reason this API is marked unsafe.
pub unsafe fn read_totalsize(buf: &[u8]) -> Result<usize, DevTreeError>
[src]
Using the provided byte slice this method will:
- Verify that the slice begins with the magic Device Tree header
- Return the reported
totalsize
field of the Device Tree header
When one must parse a Flattened Device Tree, it's possible that the actual size of the device
tree may be unknown. For that reason, this method can be called before constructing the
DevTree
.
Once known, the user should resize the raw byte slice to this function's return value and
pass that slice to DevTree::new()
.
Example
let size = DevTree::read_totalsize(buf).unwrap(); let buf = buf[..size]; let dt = DevTree::new(buf).unwrap();
Safety
Callers of this method the must guarantee the following:
- The passed buffer is 32-bit aligned.
- The passed buffer is of at least
DevTree::MIN_HEADER_SIZE
bytes in length
The passed byte buffer will be interpreted as a Flattened Device Tree. For this reason this API is marked unsafe.
pub unsafe fn new(buf: &'a [u8]) -> Result<Self, DevTreeError>
[src]
Construct the parseable DevTree object from the provided byte slice.
Safety
Callers of this method the must guarantee the following:
- The passed buffer is 32-bit aligned.
- The passed buffer is exactly the length returned by
Self::read_totalsize()
#[must_use]pub fn totalsize(&self) -> usize
[src]
Returns the totalsize field of the Device Tree
#[must_use]pub fn off_mem_rsvmap(&self) -> usize
[src]
Returns the of rsvmap offset field of the Device Tree
#[must_use]pub fn off_dt_struct(&self) -> usize
[src]
Returns the of dt_struct offset field of the Device Tree
#[must_use]pub fn off_dt_strings(&self) -> usize
[src]
Returns the of dt_strings offset field of the Device Tree
#[must_use]pub fn reserved_entries(&self) -> DevTreeReserveEntryIter
[src]
Returns an iterator over the Dev Tree "5.3 Memory Reservation Blocks"
#[must_use]pub fn nodes(&self) -> DevTreeNodeIter
[src]
Returns an iterator over DevTreeNode
objects
#[must_use]pub fn items(&self) -> DevTreeIter
[src]
Returns an iterator over objects within the DevTreeItem
enum
pub fn find<F>(
&'a self,
predicate: F
) -> Option<(DevTreeItem<'a>, DevTreeIter<'a>)> where
F: Fn(&DevTreeItem) -> bool,
[src]
&'a self,
predicate: F
) -> Option<(DevTreeItem<'a>, DevTreeIter<'a>)> where
F: Fn(&DevTreeItem) -> bool,
Map the supplied predicate over the DevTreeItem
enum.
If the predicate returns true
, Some((DevTreeItem
, iters::DevTreeIter
)) will be returned.
The iters::DevTreeIter
may be used to continue searching through the tree.
The predicate function may return true to simply terminate the search.
Example
fn is_uart_compatible(item: &DevTreeItem) -> Bool { match item { DevTreeItem::Prop(p) => { (p.name().unwrap() == "compatible") && p.get_str(0) == "ns16550a") }, _ => false, } } let devtree = DevTree::new(buf).unwrap(); // Print the names of all compatible uarts if let Some((compatible_prop, mut iter)) = devtree.find(is_uart_compatible) { println!(compatible_prop.parent().name()?); } // Continue the search and keep printing their names. while let Some((compatible_prop, mut iter)) = iter.find(is_uart_compatible) { println!(compatible_prop.parent().name()?); }
pub fn find_prop<F>(
&'a self,
predicate: F
) -> Option<(DevTreeProp<'a>, DevTreePropIter<'a>)> where
F: Fn(&DevTreeProp) -> bool,
[src]
&'a self,
predicate: F
) -> Option<(DevTreeProp<'a>, DevTreePropIter<'a>)> where
F: Fn(&DevTreeProp) -> bool,
Map the supplied predicate over all DevTreeProp
objects
If the predicate returns true
, Some((DevTreeProp
, iters::DevTreePropIter
)) will be returned.
The iters::DevTreePropIter
may be used to continue searching through the tree.
Example
let devtree = DevTree::new(buf).unwrap(); // Print the name of a compatible node if let Some((compatible_prop, _)) = devtree.find_prop(|prop| (prop.name == "compatible") && (p.get_str(0) == "ns16550a")) { println!(compatible_prop.parent().name()?); }
pub fn find_node<F>(
&'a self,
predicate: F
) -> Option<(DevTreeNode<'a>, DevTreeNodeIter<'a>)> where
F: Fn(&DevTreeNode) -> bool,
[src]
&'a self,
predicate: F
) -> Option<(DevTreeNode<'a>, DevTreeNodeIter<'a>)> where
F: Fn(&DevTreeNode) -> bool,
Map the supplied predicate over all DevTreeNode
objects
If the predicate returns true
, Some((DevTreeItem
, iters::DevTreeNodeIter
)) will be returned.
The iters::DevTreeNodeIter
may be used to continue searching through the tree.
Trait Implementations
impl<'a> Clone for DevTree<'a>
[src]
fn clone(&self) -> DevTree<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Copy for DevTree<'a>
[src]
impl<'a> Debug for DevTree<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,