Struct Fdt

Source
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>

Source

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

Source

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

Source

pub fn aliases(&self) -> Option<Aliases<'_, 'a>>

Return the /aliases node, if one exists

Source

pub fn chosen(&self) -> Chosen<'_, 'a>

Searches for the /chosen node, which is always available

Source

pub fn cpus(&self) -> impl Iterator<Item = Cpu<'_, 'a>>

Return the /cpus node, which is always available

Source

pub fn memory(&self) -> Memory<'_, 'a>

Returns the memory node, which is always available

Source

pub fn memory_reservations( &self, ) -> impl Iterator<Item = MemoryReservation> + 'a

Returns an iterator over the memory reservations

Source

pub fn root(&self) -> Root<'_, 'a>

Return the root (/) node, which is always available

Source

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.

Source

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

Source

pub fn find_phandle(&self, phandle: u32) -> Option<FdtNode<'_, 'a>>

Searches for the given phandle

Source

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
Source

pub fn all_nodes(&self) -> impl Iterator<Item = FdtNode<'_, 'a>>

Returns an iterator over all of the nodes in the devicetree, depth-first

Source

pub fn strings(&self) -> impl Iterator<Item = &'a str>

Returns an iterator over all of the strings inside of the strings block

Source

pub fn total_size(&self) -> usize

Total size of the devicetree in bytes

Trait Implementations§

Source§

impl<'a> Clone for Fdt<'a>

Source§

fn clone(&self) -> Fdt<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fdt<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for Fdt<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Fdt<'a>

§

impl<'a> RefUnwindSafe for Fdt<'a>

§

impl<'a> Send for Fdt<'a>

§

impl<'a> Sync for Fdt<'a>

§

impl<'a> Unpin for Fdt<'a>

§

impl<'a> UnwindSafe for Fdt<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.