Struct cros_fdt::fdt::Fdt

source ·
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

source

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.

source

pub fn set_boot_cpuid_phys(&mut self, boot_cpuid_phys: u32)

Set the boot_cpuid_phys field of the devicetree header.

§Arguments

boot_cpuid_phys - CPU ID

source

fn parse_reserved_memory(input: &'_ [u8]) -> Result<Vec<FdtReserveEntry>>

source

fn write_reserved_memory(&self, writer: impl Write) -> Result<()>

source

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.

source

fn write_struct(&mut self, writer: impl Write) -> Result<()>

source

pub fn finish(&mut self) -> Result<Vec<u8>>

Finish writing the Devicetree Blob (DTB).

Returns the DTB as a vector of bytes.

source

pub fn root_mut(&mut self) -> &mut FdtNode

Return a mutable reference to the root node of the FDT.

source

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.

source

pub fn get_node_mut<T: TryInto<Path>>( &mut self, path: T ) -> Option<&mut FdtNode>

Return a mutable reference to the node the path points to, or None if it doesn’t exist.

§Arguments

path - device tree path of the target node.

source

pub fn symbol_to_path(&self, symbol: &str) -> Result<Path>

Find a device tree path to the symbol exported by the FDT. The symbol must be a node label.

§Arguments

symbol - symbol to search for.

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.