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>
impl<'dt> DevTree<'dt>
pub const MIN_HEADER_SIZE: usize = 40usize
Sourcepub unsafe fn verify_magic(buf: &[u8]) -> Result<()>
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.
Sourcepub unsafe fn read_totalsize(buf: &[u8]) -> Result<usize>
pub unsafe fn read_totalsize(buf: &[u8]) -> Result<usize>
Using the provided byte slice this method will:
- Verify that the slice begins with the magic Device Tree header
- 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 buffer is 32-bit aligned.
- The passed buffer is of at least
DevTree::MIN_HEADER_SIZE
bytes in length
The passed byte buffer will be interpreted as a Flattened Device Tree. For this reason this API is marked unsafe.
Sourcepub unsafe fn new(buf: &'dt [u8]) -> Result<Self>
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()
Sourcepub unsafe fn from_raw_pointer(addr: *const u8) -> Result<Self>
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.
Sourcepub fn totalsize(&self) -> usize
pub fn totalsize(&self) -> usize
Returns the totalsize field of the Device Tree. This is the number of bytes of the device tree structure.
Sourcepub fn off_mem_rsvmap(&self) -> usize
pub fn off_mem_rsvmap(&self) -> usize
Returns the rsvmap offset field of the Device Tree
Sourcepub fn off_dt_struct(&self) -> usize
pub fn off_dt_struct(&self) -> usize
Returns the dt_struct offset field of the Device Tree
Sourcepub fn off_dt_strings(&self) -> usize
pub fn off_dt_strings(&self) -> usize
Returns the dt_strings offset field of the Device Tree
Sourcepub fn boot_cpuid_phys(&self) -> u32
pub fn boot_cpuid_phys(&self) -> u32
Returns the boot_cpuid_phys field of the Device Tree
Sourcepub fn last_comp_version(&self) -> u32
pub fn last_comp_version(&self) -> u32
Returns the last_comp_version field of the Device Tree
Sourcepub fn size_dt_strings(&self) -> u32
pub fn size_dt_strings(&self) -> u32
Returns the size_dt_strings field of the Device Tree
Sourcepub fn size_dt_struct(&self) -> u32
pub fn size_dt_struct(&self) -> u32
Returns the size_dt_struct field of the Device Tree
Sourcepub fn reserved_entries(&self) -> DevTreeReserveEntryIter<'_, '_> ⓘ
pub fn reserved_entries(&self) -> DevTreeReserveEntryIter<'_, '_> ⓘ
Returns an iterator over the Dev Tree “5.3 Memory Reservation Blocks”
Sourcepub fn nodes(&self) -> DevTreeNodeIter<'_, 'dt>
pub fn nodes(&self) -> DevTreeNodeIter<'_, 'dt>
Returns an iterator over DevTreeNode
objects
pub fn props(&self) -> DevTreePropIter<'_, 'dt>
Sourcepub fn items(&self) -> DevTreeIter<'_, 'dt>
pub fn items(&self) -> DevTreeIter<'_, 'dt>
Returns an iterator over objects within the DevTreeItem
enum
Sourcepub fn parse_iter(&self) -> DevTreeParseIter<'_, 'dt>
pub fn parse_iter(&self) -> DevTreeParseIter<'_, 'dt>
Returns an iterator over low level parsing tokens, ParsedTok
.
Sourcepub fn compatible_nodes<'s, 'a: 's>(
&'a self,
string: &'s str,
) -> DevTreeCompatibleNodeIter<'s, 'a, 'dt>
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.
pub fn buf(&self) -> &'dt [u8] ⓘ
Sourcepub fn root(&self) -> Result<Option<DevTreeNode<'_, 'dt>>>
pub fn root(&self) -> Result<Option<DevTreeNode<'_, 'dt>>>
Returns the root DevTreeNode
object of the device tree (if it exists).