Skip to content

Commit

Permalink
fix: export HeaderError
Browse files Browse the repository at this point in the history
  • Loading branch information
YdrMaster committed Jun 18, 2022
1 parent b749e23 commit 3d70e37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dtb-walker"
description = "A simple package for DTB depth-first walking."
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["YdrMaster <[email protected]>"]
repository = "https://github.com/YdrMaster/dtb-walker.git"
Expand Down
11 changes: 9 additions & 2 deletions examples/qemu-virt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dtb_walker::{utils::indent, Dtb, DtbObj, WalkOperation};
use dtb_walker::{utils::indent, Dtb, DtbObj, HeaderError, WalkOperation};

const DEVICE_TREE: &[u8] = include_bytes!("qemu-virt.dtb");
const INDENT_WIDTH: usize = 4;
Expand All @@ -11,7 +11,14 @@ fn main() {
.copy_from_nonoverlapping(DEVICE_TREE.as_ptr() as _, aligned.len());
}

let dtb = unsafe { Dtb::from_raw_parts(aligned.as_ptr() as _) }.unwrap();
let dtb = match unsafe { Dtb::from_raw_parts(aligned.as_ptr() as _) } {
Ok(ans) => ans,
Err(HeaderError::LastCompVersion) => {
// ignore!
unsafe { Dtb::from_raw_parts_unchecked(aligned.as_ptr() as _) }
}
Err(e) => panic!("Verify dtb header failed: {e:?}"),
};
dtb.walk(|path, obj| match obj {
DtbObj::SubNode { name } => {
println!("{}{path}/{}", indent(path.level(), INDENT_WIDTH), unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub use property::{PHandle, Property, Reg, Str, StrList};
pub mod utils {
pub use crate::indent::indent;
}
pub use header::HeaderError;

use header::{FdtHeader, HeaderError};
use header::FdtHeader;
use property::RegCfg;
use structure_block::StructureBlock;
use walker::Walker;
Expand Down

0 comments on commit 3d70e37

Please sign in to comment.