Crates.io | psi_device_tree |
lib.rs | psi_device_tree |
version | 2.2.0 |
source | src |
created_at | 2024-01-20 22:39:01.643267 |
updated_at | 2024-01-20 22:43:38.23037 |
description | Reads and parses Linux device tree images |
homepage | |
repository | https://github.com/platform-system-interface/device_tree-rs |
max_upload_size | |
id | 1106857 |
size | 40,611 |
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
.
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:?}");
}