pub struct Fdt<'a> { /* private fields */ }
Expand description
A flattened devicetree located somewhere in memory
Note on Debug
impl: by default the Debug
impl of this struct will not
print any useful information, if you would like a best-effort tree print
which looks similar to dtc
’s output, enable the pretty-printing
feature
Implementations§
Source§impl<'a> Fdt<'a>
impl<'a> Fdt<'a>
Sourcepub fn new(data: &'a [u8]) -> Result<Self, FdtError>
pub fn new(data: &'a [u8]) -> Result<Self, FdtError>
Construct a new Fdt
from a byte buffer
Note: this function does not require that the data be 4-byte aligned
Sourcepub unsafe fn from_ptr(ptr: *const u8) -> Result<Self, FdtError>
pub unsafe fn from_ptr(ptr: *const u8) -> Result<Self, FdtError>
§Safety
This function performs a read to verify the magic value. If the pointer is invalid this can result in undefined behavior.
Note: this function does not require that the data be 4-byte aligned
Sourcepub fn chosen(&self) -> Chosen<'_, 'a>
pub fn chosen(&self) -> Chosen<'_, 'a>
Searches for the /chosen
node, which is always available
Sourcepub fn cpus(&self) -> impl Iterator<Item = Cpu<'_, 'a>>
pub fn cpus(&self) -> impl Iterator<Item = Cpu<'_, 'a>>
Return the /cpus
node, which is always available
Sourcepub fn memory_reservations(
&self,
) -> impl Iterator<Item = MemoryReservation> + 'a
pub fn memory_reservations( &self, ) -> impl Iterator<Item = MemoryReservation> + 'a
Returns an iterator over the memory reservations
Sourcepub fn find_node(&self, path: &str) -> Option<FdtNode<'_, 'a>>
pub fn find_node(&self, path: &str) -> Option<FdtNode<'_, 'a>>
Returns the first node that matches the node path, if you want all that
match the path, use find_all_nodes
. This will automatically attempt to
resolve aliases if path
is not found.
Node paths must begin with a leading /
and are ASCII only. Passing in
an invalid node path or non-ASCII node name in the path will return
None
, as they will not be found within the devicetree structure.
Note: if the address of a node name is left out, the search will find the first node that has a matching name, ignoring the address portion if it exists.
Sourcepub fn find_compatible(&self, with: &[&str]) -> Option<FdtNode<'_, 'a>>
pub fn find_compatible(&self, with: &[&str]) -> Option<FdtNode<'_, 'a>>
Searches for a node which contains a compatible
property and contains
one of the strings inside of with
Sourcepub fn find_phandle(&self, phandle: u32) -> Option<FdtNode<'_, 'a>>
pub fn find_phandle(&self, phandle: u32) -> Option<FdtNode<'_, 'a>>
Searches for the given phandle
Sourcepub fn find_all_nodes(
&self,
path: &'a str,
) -> impl Iterator<Item = FdtNode<'_, 'a>>
pub fn find_all_nodes( &self, path: &'a str, ) -> impl Iterator<Item = FdtNode<'_, 'a>>
Returns an iterator over all of the available nodes with the given path.
This does not attempt to find any node with the same name as the
provided path, if you’re looking to do that, Fdt::all_nodes
will
allow you to iterate over each node’s name and filter for the desired
node(s).
For example:
static MY_FDT: &[u8] = include_bytes!("../dtb/test.dtb");
let fdt = fdt::Fdt::new(MY_FDT).unwrap();
for node in fdt.find_all_nodes("/soc/virtio_mmio") {
println!("{}", node.name);
}
prints:
virtio_mmio@10008000
virtio_mmio@10007000
virtio_mmio@10006000
virtio_mmio@10005000
virtio_mmio@10004000
virtio_mmio@10003000
virtio_mmio@10002000
virtio_mmio@10001000
Sourcepub fn all_nodes(&self) -> impl Iterator<Item = FdtNode<'_, 'a>>
pub fn all_nodes(&self) -> impl Iterator<Item = FdtNode<'_, 'a>>
Returns an iterator over all of the nodes in the devicetree, depth-first
Sourcepub fn strings(&self) -> impl Iterator<Item = &'a str>
pub fn strings(&self) -> impl Iterator<Item = &'a str>
Returns an iterator over all of the strings inside of the strings block
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Total size of the devicetree in bytes