pub struct FdtWriter { /* private fields */ }
Expand description
Interface for writing a Flattened Devicetree (FDT) and emitting a Devicetree Blob (DTB).
Implementations§
Source§impl FdtWriter
impl FdtWriter
Sourcepub fn new_with_mem_reserv(mem_reservations: &[FdtReserveEntry]) -> Result<Self>
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.
Sourcepub fn set_boot_cpuid_phys(&mut self, boot_cpuid_phys: u32)
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()
}
Sourcepub fn begin_node(&mut self, name: &str) -> Result<FdtWriterNode>
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.
Sourcepub fn end_node(&mut self, node: FdtWriterNode) -> Result<()>
pub fn end_node(&mut self, node: FdtWriterNode) -> Result<()>
Close a node previously opened with begin_node
.
Sourcepub fn property(&mut self, name: &str, val: &[u8]) -> Result<()>
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).
Sourcepub fn property_null(&mut self, name: &str) -> Result<()>
pub fn property_null(&mut self, name: &str) -> Result<()>
Write an empty property.
Sourcepub fn property_string(&mut self, name: &str, val: &str) -> Result<()>
pub fn property_string(&mut self, name: &str, val: &str) -> Result<()>
Write a string property.
Sourcepub fn property_string_list(
&mut self,
name: &str,
values: Vec<String>,
) -> Result<()>
pub fn property_string_list( &mut self, name: &str, values: Vec<String>, ) -> Result<()>
Write a stringlist property.
Sourcepub fn property_u32(&mut self, name: &str, val: u32) -> Result<()>
pub fn property_u32(&mut self, name: &str, val: u32) -> Result<()>
Write a 32-bit unsigned integer property.
Sourcepub fn property_u64(&mut self, name: &str, val: u64) -> Result<()>
pub fn property_u64(&mut self, name: &str, val: u64) -> Result<()>
Write a 64-bit unsigned integer property.
Sourcepub fn property_array_u32(&mut self, name: &str, cells: &[u32]) -> Result<()>
pub fn property_array_u32(&mut self, name: &str, cells: &[u32]) -> Result<()>
Write a property containing an array of 32-bit unsigned integers.
Sourcepub fn property_array_u64(&mut self, name: &str, cells: &[u64]) -> Result<()>
pub fn property_array_u64(&mut self, name: &str, cells: &[u64]) -> Result<()>
Write a property containing an array of 64-bit unsigned integers.
Sourcepub fn property_phandle(&mut self, val: u32) -> Result<()>
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.