Skip to main content

Fdt

Struct Fdt 

Source
pub struct Fdt {
    pub boot_cpuid_phys: u32,
    pub memory_reservations: Vec<MemoryReservation>,
    /* private fields */
}
Expand description

An editable Flattened Device Tree (FDT).

All nodes are stored in a flat BTreeMap<NodeId, Node>. The tree structure is maintained through Vec<NodeId> children lists in each Node and an optional parent: Option<NodeId> back-pointer.

Fields§

§boot_cpuid_phys: u32

Boot CPU ID

§memory_reservations: Vec<MemoryReservation>

Memory reservation block entries

Implementations§

Source§

impl Fdt

Source

pub fn new() -> Self

Creates a new empty FDT with an empty root node.

Source

pub fn root_id(&self) -> NodeId

Returns the root node ID.

Source

pub fn parent_of(&self, id: NodeId) -> Option<NodeId>

Returns the parent node ID for the given node, if any.

Source

pub fn node(&self, id: NodeId) -> Option<&Node>

Returns a reference to the node with the given ID.

Source

pub fn node_mut(&mut self, id: NodeId) -> Option<&mut Node>

Returns a mutable reference to the node with the given ID.

Source

pub fn node_count(&self) -> usize

Returns the total number of nodes in the tree.

Source

pub fn add_node(&mut self, parent: NodeId, node: Node) -> NodeId

Adds a new node as a child of parent, returning the new node’s ID.

Sets the new node’s parent field and updates the parent’s children list and name cache.

Source

pub fn remove_node(&mut self, parent: NodeId, name: &str) -> Option<NodeId>

Removes a child node (by name) from the given parent, and recursively removes the entire subtree from the arena.

Returns the removed node’s ID if found.

Source

pub fn resolve_alias(&self, alias: &str) -> Option<&str>

Source

pub fn get_by_path_id(&self, path: &str) -> Option<NodeId>

Looks up a node by its full path (e.g. “/soc/uart@10000”), returning its NodeId.

The root node is matched by “/” or “”.

Source

pub fn get_by_phandle_id(&self, phandle: Phandle) -> Option<NodeId>

Looks up a node by its phandle value, returning its NodeId.

Source

pub fn path_of(&self, id: NodeId) -> String

Computes the full path string for a node by walking up parent links.

Source

pub fn remove_by_path(&mut self, path: &str) -> Option<NodeId>

Removes a node and its subtree by path.

Returns the removed node’s ID if found.

Source

pub fn iter_node_ids(&self) -> NodeDfsIter<'_>

Returns a depth-first iterator over all node IDs in the tree.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, FdtError>

Parses an FDT from raw byte data.

Source

pub unsafe fn from_ptr(ptr: *mut u8) -> Result<Self, FdtError>

Parses an FDT from a raw pointer.

§Safety

The caller must ensure that the pointer is valid and points to a valid FDT data structure.

Source

pub fn get_by_path(&self, path: &str) -> Option<NodeType<'_>>

Looks up a node by path and returns an immutable classified view.

Source

pub fn get_by_path_mut(&mut self, path: &str) -> Option<NodeTypeMut<'_>>

Looks up a node by path and returns a mutable classified view.

Source

pub fn get_by_phandle(&self, phandle: Phandle) -> Option<NodeType<'_>>

Looks up a node by phandle and returns an immutable classified view.

Source

pub fn get_by_phandle_mut( &mut self, phandle: Phandle, ) -> Option<NodeTypeMut<'_>>

Looks up a node by phandle and returns a mutable classified view.

Source

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

Returns a depth-first iterator over classified NodeTypes.

Source

pub fn root_mut(&mut self) -> NodeTypeMut<'_>

Source

pub fn find_compatible(&self, compatible: &[&str]) -> Vec<NodeType<'_>>

Finds nodes with matching compatible strings.

Source

pub fn encode(&self) -> FdtData

Encodes the FDT to DTB binary format.

Source§

impl Fdt

Source

pub fn view_typed(&self, id: NodeId) -> Option<NodeType<'_>>

Returns a classified NodeType for the given node ID.

Source

pub fn view_typed_mut(&mut self, id: NodeId) -> Option<NodeTypeMut<'_>>

Returns a classified NodeTypeMut for the given node ID.

Trait Implementations§

Source§

impl Clone for Fdt

Source§

fn clone(&self) -> Fdt

Returns a duplicate 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 Default for Fdt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Fdt

§

impl RefUnwindSafe for Fdt

§

impl Send for Fdt

§

impl Sync for Fdt

§

impl Unpin for Fdt

§

impl UnsafeUnpin for Fdt

§

impl UnwindSafe for Fdt

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.