5 releases

0.2.0 Dec 13, 2019
0.1.3 Sep 22, 2019
0.1.2 Dec 12, 2018
0.1.1 Dec 11, 2018
0.1.0 Dec 11, 2018

#296 in Programming languages

Download history 328/week @ 2023-11-20 403/week @ 2023-11-27 226/week @ 2023-12-04 451/week @ 2023-12-11 261/week @ 2023-12-18 30/week @ 2023-12-25 54/week @ 2024-01-01 93/week @ 2024-01-08 153/week @ 2024-01-15 111/week @ 2024-01-22 295/week @ 2024-01-29 96/week @ 2024-02-05 173/week @ 2024-02-12 224/week @ 2024-02-19 90/week @ 2024-02-26 296/week @ 2024-03-04

790 downloads per month

MIT license

46KB
1K SLoC

DTB

Device tree blob utilities

This no_std crate contains types for reading and writing DTBs. Here is a code showing how to read a DTB-file:

let mut buf = Vec::new();
let mut file = File::open("example.dtb").unwrap();
file.read_to_end(&mut buf).unwrap();
let reader = Reader::read(buf.as_slice()).unwrap();

for entry in reader.reserved_mem_entries() {
    println!("reserved: {:?}, {:?}", entry.address, entry.size);
}

let root = reader.struct_items();
let (prop, _) =
    root.path_struct_items("/node/property").next().unwrap();
println!("property: {:?}, {:?}", prop.name(), prop.value_str());

let (node, node_iter) =
    root.path_struct_items("/node/node2").next().unwrap();
println!("node: {:?}@{:?}", node.node_name(), node.unit_address());

let mut buf = [0; 32];

let (prop, _) = node_iter.path_struct_items("property").next().unwrap();
println!(
    "property: {:?}, {:?}",
    prop.name(),
    prop.value_str_list(&mut buf)
);

let (prop, _) =
    node_iter.path_struct_items("property2").next().unwrap();
println!(
    "property: {:?}, {:?}",
    prop.name(),
    prop.value_u32_list(&mut buf)
);

To read DTB directly from a memory address use Reader::read_from_address().

To run a test sample execute:

cargo run --example dump src/test_dtb/sample.dtb

Fuzzing instructions

The reader (and methods of read items) can be fuzzed with cargo-fuzz/libfuzzer which can be installed as cargo install cargo-fuzz. Note that the coverage is not yet complete but provides a straightforward harness. The baseline corpus is the directory of tests is src/test_dtb. Note that this command will require a nightly compiler.

cargo fuzz run reader src/test_dtb

No runtime deps