#device-tree #fdt #dtb #dt

no-std flat_device_tree

A pure-Rust #![no_std] crate for parsing Flattened Devicetrees

5 stable releases

3.1.1 Jun 7, 2024
3.1.0 May 19, 2024
3.0.0 Apr 28, 2024
2.1.1 Mar 12, 2024
2.1.0 Jan 27, 2024

#147 in Embedded development

Download history 21/week @ 2024-07-21 19/week @ 2024-07-28 14/week @ 2024-08-04 35/week @ 2024-08-11 105/week @ 2024-08-18 202/week @ 2024-08-25 201/week @ 2024-09-01 69/week @ 2024-09-08 6/week @ 2024-09-15 20/week @ 2024-09-22 36/week @ 2024-09-29 67/week @ 2024-10-06 50/week @ 2024-10-13 16/week @ 2024-10-20 13/week @ 2024-10-27 17/week @ 2024-11-03

121 downloads per month
Used in 2 crates

MPL-2.0 license

71KB
1.5K SLoC

flat_device_tree

NOTE Friendly fork of fdt.

A pure-Rust #![no_std] crate for parsing Flattened Devicetrees, with the goal of having a very ergonomic and idiomatic API.

crates.io Documentation Build

License

This crate is licensed under the Mozilla Public License 2.0 (see the LICENSE file).

Example

static MY_FDT: &[u8] = include_bytes!("../dtb/test.dtb");

fn main() {
    let fdt = fdt::Fdt::new(MY_FDT).unwrap();

    println!("This is a devicetree representation of a {}", fdt.root().model());
    println!("...which is compatible with at least: {}", fdt.root().compatible().first());
    println!("...and has {} CPU(s)", fdt.cpus().count());
    println!(
        "...and has at least one memory location at: {:#X}\n",
        fdt.memory().regions().next().unwrap().starting_address as usize
    );

    let chosen = fdt.chosen();
    if let Some(bootargs) = chosen.bootargs() {
        println!("The bootargs are: {:?}", bootargs);
    }

    if let Some(stdout) = chosen.stdout() {
        println!("It would write stdout to: {}", stdout.node().name);
    }

    let soc = fdt.find_node("/soc");
    println!("Does it have a `/soc` node? {}", if soc.is_some() { "yes" } else { "no" });
    if let Some(soc) = soc {
        println!("...and it has the following children:");
        for child in soc.children() {
            println!("    {}", child.name);
        }
    }
}

No runtime deps

Features