pub struct Fdt<'a> { /* private fields */ }Expand description
A parsed Flattened Device Tree (FDT).
This is the main type for working with device tree blobs. It provides methods for traversing the tree, finding nodes by path, translating addresses, and accessing special nodes like /chosen and /memory.
The Fdt holds a reference to the underlying device tree data and
performs zero-copy parsing where possible.
Implementations§
Source§impl<'a> Fdt<'a>
impl<'a> Fdt<'a>
Sourcepub fn from_bytes(data: &'a [u8]) -> Result<Fdt<'a>, FdtError>
pub fn from_bytes(data: &'a [u8]) -> Result<Fdt<'a>, FdtError>
Create a new Fdt from a byte slice.
Parses the FDT header and validates the magic number. The slice must contain a complete, valid device tree blob.
§Errors
Returns FdtError if the header is invalid, the magic number
doesn’t match, or the buffer is too small.
Sourcepub unsafe fn from_ptr(ptr: *mut u8) -> Result<Fdt<'a>, FdtError>
pub unsafe fn from_ptr(ptr: *mut u8) -> Result<Fdt<'a>, FdtError>
Create a new Fdt from a raw pointer.
Parses an FDT from the memory location pointed to by ptr.
This is useful when working with device trees loaded by bootloaders.
§Safety
The caller must ensure that the pointer is valid and points to a
memory region of at least totalsize bytes that contains a valid
device tree blob. The memory must remain valid for the lifetime 'a.
§Errors
Returns FdtError if the header is invalid or the magic number
doesn’t match.
Sourcepub fn find_by_path(&self, path: &str) -> Option<Node<'a>>
pub fn find_by_path(&self, path: &str) -> Option<Node<'a>>
Sourcepub fn find_children_by_path(&self, path: &str) -> ChildrenIter<'a>
pub fn find_children_by_path(&self, path: &str) -> ChildrenIter<'a>
Find all direct children of a node at the given path.
Returns an iterator over all direct child nodes (one level deeper)
of the node at the specified path. Returns None if the node is
not found.
Only direct children are yielded — grandchildren and deeper descendants are skipped.
§Example
// List all direct children of /soc
if let Some(children) = fdt.find_children_by_path("/soc") {
for child in children {
println!("{}", child.name());
}
}Sourcepub fn translate_address(&self, path: &'a str, address: u64) -> u64
pub fn translate_address(&self, path: &'a str, address: u64) -> u64
Translate a device address to a CPU physical address.
This function implements address translation similar to Linux’s
of_translate_address. It walks up the device tree hierarchy,
applying each parent’s ranges property to translate the child
address space to the parent address space.
The translation starts from the node at path and walks up through
each parent, applying the ranges property until reaching the root.
§Arguments
path- Node path (absolute path starting with ‘/’ or alias name)address- Device address from the node’sregproperty
§Returns
The translated CPU physical address. If translation fails at any
point (e.g., a parent node has no ranges property), the original
address is returned.
Sourcepub fn translate_addresses(&self, path: &'a str, addresses: &mut [u64])
pub fn translate_addresses(&self, path: &'a str, addresses: &mut [u64])
Translate multiple device addresses to CPU physical addresses in a single pass.
This is more efficient than calling translate_address multiple times
for the same node path, because the tree is walked only once. Each
parent node’s ranges property is looked up once and applied to all
addresses in the batch.
§Arguments
path- Node path (absolute path starting with ‘/’ or alias name)addresses- Mutable slice of device addresses to translate in place. The addresses are modified with the translated CPU physical addresses.
If translation fails for any address at any level, the original address value is preserved for that address.
Sourcepub fn memory_reservations(&self) -> MemoryReservationIter<'a>
pub fn memory_reservations(&self) -> MemoryReservationIter<'a>
Returns an iterator over memory reservation entries.
Sourcepub fn memory(&self) -> impl Iterator<Item = Memory<'a>> + 'a
pub fn memory(&self) -> impl Iterator<Item = Memory<'a>> + 'a
Returns an iterator over all memory nodes.
Sourcepub fn reserved_memory(&self) -> impl Iterator<Item = Node<'a>> + 'a
pub fn reserved_memory(&self) -> impl Iterator<Item = Node<'a>> + 'a
Returns an iterator over nodes in the /reserved-memory region.