libfdt_rs/lib.rs
1//! # libfdt-rs
2//!
3//! `libfdt-rs` is a library for handling FDT binaries.
4//! It uses [libfdt](https://github.com/dgibson/dtc) under the hood.
5//!
6//! ## Zero-copy
7//!
8//! As much as possible, the library avoids copying data.
9//! Nodes and properties are cheap references into the FDT binary in memory.
10//! Lifetime is property handled, avoiding some pitfalls met while manipulating FDT binaries.
11//!
12//! ## `Devicetree` compliant
13//!
14//! This crates aims at being compliant with [the devicetree specification](https://www.devicetree.org/specifications/)
15//! as much as possible.
16//!
17//! This crate officially supports the [devicetree specification v0.4](https://github.com/devicetree-org/devicetree-specification/releases/tag/v0.4).
18//!
19//! ## Linux special properties
20//!
21//! The crate handles special properties used by the Linux kernel.
22//! It makes it easy to retrieve phandle links between subnodes, as detected by the Linux kernel.
23//!
24//! ## `no_std` compatible
25//!
26//! The crate is fully compatible with no_std.
27//!
28//! # Example code
29//!
30//! ```
31//! use std::fs;
32//! use libfdt_rs::Fdt;
33//!
34//! let fdt_bin = fs::read("dtb/zuma-a0-foplp.dtb").unwrap();
35//! let fdt = Fdt::new(fdt_bin.into_boxed_slice()).unwrap();
36//! let root_node = fdt.get_node("/").unwrap();
37//!
38//! for subnode in root_node.subnodes_iter() {
39//! println!("subnode:?");
40//! }
41//!
42//! for property in root_node.properties_iter() {
43//! println!("subnode:?");
44//! }
45//! ```
46
47#![cfg_attr(not(feature = "std"), no_std)]
48
49#[cfg(not(feature = "std"))]
50extern crate alloc;
51
52mod fdt;
53pub use fdt::{Fdt, Offset, Phandle};
54
55mod node;
56pub use node::{FdtNode, FdtNodeRef};
57
58mod property;
59pub use property::{
60 FdtProperty, PHANDLE_LINKS_SIMPLE, PHANDLE_LINKS_SUFFIX, PhandleLink, PropertyCellParser,
61 PropertyParser, PropertyReader,
62};
63
64mod error;
65pub use error::Error;
66
67mod iter;
68pub use iter::{FdtNodeIter, FdtPropertyIter};