项目作者: ababo

项目描述 :
Device Tree Blob Support
高级语言: Rust
项目地址: git://github.com/ababo/dtb.git
创建时间: 2018-12-10T18:48:48Z
项目社区:https://github.com/ababo/dtb

开源协议:

下载


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:

  1. let mut buf = Vec::new();
  2. let mut file = File::open("example.dtb").unwrap();
  3. file.read_to_end(&mut buf).unwrap();
  4. let reader = Reader::read(buf.as_slice()).unwrap();
  5. for entry in reader.reserved_mem_entries() {
  6. println!("reserved: {:?}, {:?}", entry.address, entry.size);
  7. }
  8. let root = reader.struct_items();
  9. let (prop, _) =
  10. root.path_struct_items("/node/property").next().unwrap();
  11. println!("property: {:?}, {:?}", prop.name(), prop.value_str());
  12. let (node, node_iter) =
  13. root.path_struct_items("/node/node2").next().unwrap();
  14. println!("node: {:?}@{:?}", node.node_name(), node.unit_address());
  15. let mut buf = [0; 32];
  16. let (prop, _) = node_iter.path_struct_items("property").next().unwrap();
  17. println!(
  18. "property: {:?}, {:?}",
  19. prop.name(),
  20. prop.value_str_list(&mut buf)
  21. );
  22. let (prop, _) =
  23. node_iter.path_struct_items("property2").next().unwrap();
  24. println!(
  25. "property: {:?}, {:?}",
  26. prop.name(),
  27. prop.value_u32_list(&mut buf)
  28. );

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

To run a test sample execute:

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

  1. cargo fuzz run reader src/test_dtb