pub struct DeviceTree {
pub reservations: Vec<Arc<Mutex<Reservation>>>,
pub root: Arc<Mutex<Node>>,
}
Expand description
A device tree.
The Tree
struct consists of:
- The root node of the device tree (mandatory)
- And the memory reservation blocks (optional)
Fields§
§reservations: Vec<Arc<Mutex<Reservation>>>
§root: Arc<Mutex<Node>>
Implementations§
Source§impl DeviceTree
impl DeviceTree
Sourcepub fn new(reservations: Vec<Reservation>, root: Node) -> Self
pub fn new(reservations: Vec<Reservation>, root: Node) -> Self
Create a new device tree with a vector of reservation block and the root node. If there is not any reservation block, the vector should be empty.
Example:
use devicetree_tool::Reservation;
use devicetree_tool::Node;
use devicetree_tool::DeviceTree;
let tree = DeviceTree::new(vec![], Node::new(""));
assert_eq!(format!("{}", tree), "/dts-v1/;\n\n/ {\n};\n\n");
Sourcepub fn find_node_by_label(&self, label: &str) -> Option<Arc<Mutex<Node>>>
pub fn find_node_by_label(&self, label: &str) -> Option<Arc<Mutex<Node>>>
Find a ‘Node’ by label.
Example:
use devicetree_tool::Node;
use devicetree_tool::DeviceTree;
let mut root = Node::new("");
// Add some nodes
root.add_sub_node(Node::new_with_label("node1", "label1"));
root.add_sub_node(Node::new_with_label("node2", "label2"));
let tree = DeviceTree::new(vec![], root);
// Find the nodes by their labels
let node1 = tree.find_node_by_label("label1").unwrap();
assert_eq!(node1.lock().unwrap().name, "node1");
let node2 = tree.find_node_by_label("label2").unwrap();
assert_eq!(node2.lock().unwrap().name, "node2");
Sourcepub fn find_node_by_path(&self, path: &str) -> Option<Arc<Mutex<Node>>>
pub fn find_node_by_path(&self, path: &str) -> Option<Arc<Mutex<Node>>>
Find a ‘Node’ by path.
Example:
use devicetree_tool::Node;
use devicetree_tool::DeviceTree;
let mut root = Node::new("");
// Create a node with sub node
let mut node_l1 = Node::new("node_l1");
node_l1.add_sub_node(Node::new("node_l2"));
root.add_sub_node(node_l1);
let tree = DeviceTree::new(vec![], root);
let node_l2 = tree.find_node_by_path("/node_l1/node_l2").unwrap();
assert_eq!(node_l2.lock().unwrap().name, "node_l2");
Sourcepub fn from_dts_bytes(dts: &[u8]) -> Self
pub fn from_dts_bytes(dts: &[u8]) -> Self
Create a Tree
from DTS text byte array.
Sourcepub fn generate_dts(&self) -> String
pub fn generate_dts(&self) -> String
Generate the DTS text of a Tree
.
Sourcepub fn from_dtb_bytes(dtb: &[u8]) -> Self
pub fn from_dtb_bytes(dtb: &[u8]) -> Self
Create a Tree
from DTB binary byte array.
Sourcepub fn generate_dtb(&self) -> Vec<u8> ⓘ
pub fn generate_dtb(&self) -> Vec<u8> ⓘ
Generate the DTB binary of a Tree
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DeviceTree
impl RefUnwindSafe for DeviceTree
impl Send for DeviceTree
impl Sync for DeviceTree
impl Unpin for DeviceTree
impl UnwindSafe for DeviceTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more