Expand description
This crate provides the ability to manipulate Flattened Devicetree blobs.
Example
In the following example we create an FDT blob with a root node, and 2 children nodes. More details about this example are available in the readme.
use vm_fdt::{Error, FdtWriter};
fn create_fdt() -> Result<Vec<u8>, Error> {
let mut fdt = FdtWriter::new()?;
let root_node = fdt.begin_node("root")?;
fdt.property_string("compatible", "linux,dummy-virt")?;
fdt.property_u32("#address-cells", 0x2)?;
fdt.property_u32("#size-cells", 0x2)?;
let chosen_node = fdt.begin_node("chosen")?;
fdt.property_u32("linux,pci-probe-only", 1)?;
fdt.property_string("bootargs", "panic=-1 console=hvc0")?;
fdt.end_node(chosen_node)?;
let memory_node = fdt.begin_node("memory")?;
fdt.property_string("device_type", "memory")?;
fdt.end_node(memory_node)?;
fdt.end_node(root_node)?;
fdt.finish()
}
By default the FDT does not have any memory reservations. If the user needs to add memory reservations as well, then a different constructor can be used as follows:
use vm_fdt::{Error, FdtReserveEntry, FdtWriter};
fn create_fdt() -> Result<Vec<u8>, Error> {
let mut fdt = FdtWriter::new_with_mem_reserv(&[
FdtReserveEntry::new(0x12345678AABBCCDD, 0x1234).unwrap(),
FdtReserveEntry::new(0x1020304050607080, 0x5678).unwrap(),
])?;
let root_node = fdt.begin_node("root")?;
// ... add other nodes & properties
fdt.end_node(root_node)?;
fdt.finish()
}
The phandle
property should be set using FdtWriter::property_phandle
,
so that the value is checked for uniqueness within the devicetree.
use vm_fdt::{Error, FdtWriter};
fn create_fdt() -> Result<Vec<u8>, Error> {
let mut fdt = FdtWriter::new()?;
let root_node = fdt.begin_node("root")?;
fdt.property_phandle(1)?;
fdt.end_node(root_node)?;
fdt.finish()
}
Structs
- Reserved physical memory region.
- Interface for writing a Flattened Devicetree (FDT) and emitting a Devicetree Blob (DTB).
- Handle to an open node created by
FdtWriter::begin_node
.
Enums
- Errors associated with creating the Flattened Device Tree.
Type Aliases
- Result of a FDT writer operation.