#device-tree #parser #dt #flattened #memory #devicetrees

no-std fdt

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

6 releases

0.1.5 Feb 5, 2023
0.1.4 Jul 31, 2022
0.1.3 Jun 15, 2021
0.1.0 Mar 25, 2021
0.0.1 Mar 15, 2018

#67 in Embedded development

Download history 1080/week @ 2023-11-20 1247/week @ 2023-11-27 1316/week @ 2023-12-04 1969/week @ 2023-12-11 1350/week @ 2023-12-18 476/week @ 2023-12-25 1087/week @ 2024-01-01 2680/week @ 2024-01-08 1292/week @ 2024-01-15 1456/week @ 2024-01-22 1894/week @ 2024-01-29 2235/week @ 2024-02-05 1919/week @ 2024-02-12 2126/week @ 2024-02-19 2320/week @ 2024-02-26 1975/week @ 2024-03-04

8,412 downloads per month
Used in 2 crates

MPL-2.0 license

56KB
1K SLoC

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.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