diff --git a/Cargo.toml b/Cargo.toml index e63a3f8..b2a7d6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] repository = "https://github.com/YdrMaster/dtb-walker.git" diff --git a/examples/qemu-virt.rs b/examples/qemu-virt.rs index 7d03fc3..e1aa65b 100644 --- a/examples/qemu-virt.rs +++ b/examples/qemu-virt.rs @@ -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; @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 79c0ee2..abb984d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;