Struct DevTree

Source
pub struct DevTree<'dt> { /* private fields */ }
Expand description

A parseable Flattened Device Tree.

This parser was written according to the v0.3 specification provided at https://www.devicetree.org/

Implementations§

Source§

impl<'dt> DevTree<'dt>

Source

pub const MIN_HEADER_SIZE: usize = 40usize

Source

pub unsafe fn verify_magic(buf: &[u8]) -> Result<()>

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.

Source

pub unsafe fn read_totalsize(buf: &[u8]) -> Result<usize>

Using the provided byte slice this method will:

  1. Verify that the slice begins with the magic Device Tree header
  2. Return the reported totalsize field of the Device Tree header

When parsing a FDT, 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. For this read to take place, the provided buffer must be at least Self::MIN_HEADER_SIZE long.

Once known, the user should resize the raw byte slice to this function’s return value and pass that slice to DevTree::new().

§Example

TODO

§Safety

Callers of this method the must guarantee the following:

The passed byte buffer will be interpreted as a Flattened Device Tree. For this reason this API is marked unsafe.

Source

pub unsafe fn new(buf: &'dt [u8]) -> Result<Self>

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

pub unsafe fn from_raw_pointer(addr: *const u8) -> Result<Self>

Construct the parseable DevTree object from a raw byte pointer

§Safety

Callers of this method the must guarantee the following:

  • The passed address is 32-bit aligned.
Source

pub fn totalsize(&self) -> usize

Returns the totalsize field of the Device Tree. This is the number of bytes of the device tree structure.

Source

pub fn off_mem_rsvmap(&self) -> usize

Returns the rsvmap offset field of the Device Tree

Source

pub fn off_dt_struct(&self) -> usize

Returns the dt_struct offset field of the Device Tree

Source

pub fn off_dt_strings(&self) -> usize

Returns the dt_strings offset field of the Device Tree

Source

pub fn magic(&self) -> u32

Returns the magic field of the Device Tree

Source

pub fn version(&self) -> u32

Returns the version field of the Device Tree

Source

pub fn boot_cpuid_phys(&self) -> u32

Returns the boot_cpuid_phys field of the Device Tree

Source

pub fn last_comp_version(&self) -> u32

Returns the last_comp_version field of the Device Tree

Source

pub fn size_dt_strings(&self) -> u32

Returns the size_dt_strings field of the Device Tree

Source

pub fn size_dt_struct(&self) -> u32

Returns the size_dt_struct field of the Device Tree

Source

pub fn reserved_entries(&self) -> DevTreeReserveEntryIter<'_, '_>

Returns an iterator over the Dev Tree “5.3 Memory Reservation Blocks”

Source

pub fn nodes(&self) -> DevTreeNodeIter<'_, 'dt>

Returns an iterator over DevTreeNode objects

Source

pub fn props(&self) -> DevTreePropIter<'_, 'dt>

Source

pub fn items(&self) -> DevTreeIter<'_, 'dt>

Returns an iterator over objects within the DevTreeItem enum

Source

pub fn parse_iter(&self) -> DevTreeParseIter<'_, 'dt>

Returns an iterator over low level parsing tokens, ParsedTok.

Source

pub fn compatible_nodes<'s, 'a: 's>( &'a self, string: &'s str, ) -> DevTreeCompatibleNodeIter<'s, 'a, 'dt>

Returns the first DevTreeNode object with the provided compatible device tree property or None if none exists.

Source

pub fn buf(&self) -> &'dt [u8]

Source

pub fn root(&self) -> Result<Option<DevTreeNode<'_, 'dt>>>

Returns the root DevTreeNode object of the device tree (if it exists).

Trait Implementations§

Source§

impl<'dt> Clone for DevTree<'dt>

Source§

fn clone(&self) -> DevTree<'dt>

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<'dt> Debug for DevTree<'dt>

Source§

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

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

impl<'dt> PartialEq for DevTree<'dt>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'dt> Copy for DevTree<'dt>

Auto Trait Implementations§

§

impl<'dt> Freeze for DevTree<'dt>

§

impl<'dt> RefUnwindSafe for DevTree<'dt>

§

impl<'dt> Send for DevTree<'dt>

§

impl<'dt> Sync for DevTree<'dt>

§

impl<'dt> Unpin for DevTree<'dt>

§

impl<'dt> UnwindSafe for DevTree<'dt>

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.