pub struct Fdt {
pub(crate) reserved_memory: Vec<FdtReserveEntry>,
pub(crate) root: FdtNode,
strings: FdtStrings,
boot_cpuid_phys: u32,
}
Expand description
Interface for creating and manipulating a Flattened Devicetree (FDT) and emitting a Devicetree Blob (DTB).
§Example
use cros_fdt::Fdt;
let mut fdt = Fdt::new(&[]);
let root_node = fdt.root_mut();
root_node.set_prop("compatible", "linux,dummy-virt")?;
root_node.set_prop("#address-cells", 0x2u32)?;
root_node.set_prop("#size-cells", 0x2u32)?;
let chosen_node = root_node.subnode_mut("chosen")?;
chosen_node.set_prop("linux,pci-probe-only", 1u32)?;
chosen_node.set_prop("bootargs", "panic=-1 console=hvc0 root=/dev/vda")?;
let dtb = fdt.finish().unwrap();
Fields§
§reserved_memory: Vec<FdtReserveEntry>
§root: FdtNode
§strings: FdtStrings
§boot_cpuid_phys: u32
Implementations§
source§impl Fdt
impl Fdt
sourcepub fn new(mem_reservations: &[FdtReserveEntry]) -> Self
pub fn new(mem_reservations: &[FdtReserveEntry]) -> Self
Create a new flattened device tree instance with an initialized root node.
§Arguments
mem_reservations
- reserved physical memory regions to list in the FDT header.
sourcepub fn set_boot_cpuid_phys(&mut self, boot_cpuid_phys: u32)
pub fn set_boot_cpuid_phys(&mut self, boot_cpuid_phys: u32)
fn parse_reserved_memory(input: &'_ [u8]) -> Result<Vec<FdtReserveEntry>>
fn write_reserved_memory(&self, writer: impl Write) -> Result<()>
sourcepub fn from_blob(input: &'_ [u8]) -> Result<Self>
pub fn from_blob(input: &'_ [u8]) -> Result<Self>
Load a flattened device tree from a byte slice.
§Arguments
input
- byte slice from which to load the FDT.
fn write_struct(&mut self, writer: impl Write) -> Result<()>
sourcepub fn finish(&mut self) -> Result<Vec<u8>>
pub fn finish(&mut self) -> Result<Vec<u8>>
Finish writing the Devicetree Blob (DTB).
Returns the DTB as a vector of bytes.
sourcepub fn root_mut(&mut self) -> &mut FdtNode
pub fn root_mut(&mut self) -> &mut FdtNode
Return a mutable reference to the root node of the FDT.
sourcepub fn get_node<T: TryInto<Path>>(&self, path: T) -> Option<&FdtNode>
pub fn get_node<T: TryInto<Path>>(&self, path: T) -> Option<&FdtNode>
Return a reference to the node the path points to, or None
if it doesn’t exist.
§Arguments
path
- device tree path of the target node.
Auto Trait Implementations§
impl RefUnwindSafe for Fdt
impl Send for Fdt
impl Sync for Fdt
impl Unpin for Fdt
impl UnwindSafe for Fdt
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more