psi_device_tree

Crates.iopsi_device_tree
lib.rspsi_device_tree
version2.2.0
sourcesrc
created_at2024-01-20 22:39:01.643267
updated_at2024-01-20 22:43:38.23037
descriptionReads and parses Linux device tree images
homepage
repositoryhttps://github.com/platform-system-interface/device_tree-rs
max_upload_size
id1106857
size40,611
Daniel Maslowski (orangecms)

documentation

https://docs.rs/psi_device_tree

README

psi_device_tree

Device trees are used to describe a lot of hardware, especially in the embedded world and are used in U-Boot, Linux and other boot loaders and kernels. A device tree enumerates addresses and other attributes for peripherals, hardware decoders, processing cores and external components attached to systems on chips (SoCs) on printed circuit boards (PCBs).

This library allows parsing the so-called flattened device trees (FDTs), which are the compiled binary forms of the corresponding device tree source (DTS) files that are commonly found in the respective project, e.g., Linux. Decice tree sources are often modular, bring preprocessed and then compiled to DTBs. Users can create these files using the dtc (device tree compiler) utility from the U-Boot project:

# If your DTS includes C pre-processor directives (e.g. #include <...>), run the `cpp` utillity
cpp -E -P -Wp,-I<include-dir> /path/to/some.dts > processed.dts

# Run the `dtc` utility to "flatten" the device tree
dtc -I dts -O [dts,dtb] -i <include-dir> -o flattened.[dts,dtb] processed.dts

To read more about device trees in Linux, check out the kernel docs.

Some example device trees to try out are the Raspberry Pi ones.

This library does not use std, just core.

Examples

use std::{fs, io::Read};
use psi_device_tree::DeviceTree as DT;

fn main() {
    // read file into memory
    let mut input = fs::File::open("examples/bcm2709-rpi-2-b.dtb").unwrap();
    let mut buf = Vec::new();
    input.read_to_end(&mut buf).unwrap();

    let dt = DT::load(buf.as_slice ()).unwrap();
    println!("{dt:?}");
}
Commit count: 0

cargo fmt