Struct FdtWriter

Source
pub struct FdtWriter { /* private fields */ }
Expand description

Interface for writing a Flattened Devicetree (FDT) and emitting a Devicetree Blob (DTB).

Implementations§

Source§

impl FdtWriter

Source

pub fn new() -> Result<Self>

Create a new Flattened Devicetree writer instance.

Source

pub fn new_with_mem_reserv(mem_reservations: &[FdtReserveEntry]) -> Result<Self>

Create a new Flattened Devicetree writer instance.

§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.

§Example
use vm_fdt::{Error, FdtWriter};

fn create_fdt() -> Result<Vec<u8>, Error> {
    let mut fdt = FdtWriter::new()?;
    fdt.set_boot_cpuid_phys(0x12345678);
    // ... add other nodes & properties
    fdt.finish()
}
Source

pub fn begin_node(&mut self, name: &str) -> Result<FdtWriterNode>

Open a new FDT node.

The node must be closed using end_node.

§Arguments

name - name of the node; must not contain any NUL bytes.

Source

pub fn end_node(&mut self, node: FdtWriterNode) -> Result<()>

Close a node previously opened with begin_node.

Source

pub fn property(&mut self, name: &str, val: &[u8]) -> Result<()>

Write a property.

§Arguments

name - name of the property; must not contain any NUL bytes. val - value of the property (raw byte array).

Source

pub fn property_null(&mut self, name: &str) -> Result<()>

Write an empty property.

Source

pub fn property_string(&mut self, name: &str, val: &str) -> Result<()>

Write a string property.

Source

pub fn property_string_list( &mut self, name: &str, values: Vec<String>, ) -> Result<()>

Write a stringlist property.

Source

pub fn property_u32(&mut self, name: &str, val: u32) -> Result<()>

Write a 32-bit unsigned integer property.

Source

pub fn property_u64(&mut self, name: &str, val: u64) -> Result<()>

Write a 64-bit unsigned integer property.

Source

pub fn property_array_u32(&mut self, name: &str, cells: &[u32]) -> Result<()>

Write a property containing an array of 32-bit unsigned integers.

Source

pub fn property_array_u64(&mut self, name: &str, cells: &[u64]) -> Result<()>

Write a property containing an array of 64-bit unsigned integers.

Source

pub fn property_phandle(&mut self, val: u32) -> Result<()>

Write a phandle property. The value is checked for uniqueness within the FDT. In the case of a duplicate Error::DuplicatePhandle is returned.

Source

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

Finish writing the Devicetree Blob (DTB).

Returns the DTB as a vector of bytes, consuming the FdtWriter.

Trait Implementations§

Source§

impl Debug for FdtWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

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.