Struct DeviceTree

Source
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

Source

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");
Source

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");
Source

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");
Source

pub fn from_dts_bytes(dts: &[u8]) -> Self

Create a Tree from DTS text byte array.

Source

pub fn generate_dts(&self) -> String

Generate the DTS text of a Tree.

Source

pub fn from_dtb_bytes(dtb: &[u8]) -> Self

Create a Tree from DTB binary byte array.

Source

pub fn generate_dtb(&self) -> Vec<u8>

Generate the DTB binary of a Tree.

Trait Implementations§

Source§

impl Display for DeviceTree

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.