@@ -27,13 +27,13 @@ impl<const N: usize> Display for StringInline<N> {
2727
2828/// 解析设备树。
2929pub ( crate ) fn parse ( opaque : usize ) -> BoardInfo {
30- use dtb_walker:: { Dtb , DtbObj , Property , WalkOperation :: * } ;
31- const CPUS : & [ u8 ] = b "cpus";
32- const MEMORY : & [ u8 ] = b "memory";
33- const SOC : & [ u8 ] = b "soc";
34- const UART : & [ u8 ] = b "uart";
35- const TEST : & [ u8 ] = b "test";
36- const CLINT : & [ u8 ] = b "clint";
30+ use dtb_walker:: { Dtb , DtbObj , HeaderError as E , Property , Str , WalkOperation :: * } ;
31+ const CPUS : & str = "cpus" ;
32+ const MEMORY : & str = "memory" ;
33+ const SOC : & str = "soc" ;
34+ const UART : & str = "uart" ;
35+ const TEST : & str = "test" ;
36+ const CLINT : & str = "clint" ;
3737
3838 let mut ans = BoardInfo {
3939 dtb : opaque..opaque,
@@ -44,37 +44,42 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
4444 test : 0 ..0 ,
4545 clint : 0 ..0 ,
4646 } ;
47- let dtb = unsafe { Dtb :: from_raw_parts ( opaque as _ ) } . unwrap ( ) ;
47+ let dtb = unsafe {
48+ Dtb :: from_raw_parts_filtered ( opaque as _ , |e| {
49+ matches ! ( e, E :: Misaligned ( 4 ) | E :: LastCompVersion ( 16 ) )
50+ } )
51+ }
52+ . unwrap ( ) ;
4853 ans. dtb . end += dtb. total_size ( ) ;
49- dtb. walk ( |path , obj| match obj {
54+ dtb. walk ( |ctx , obj| match obj {
5055 DtbObj :: SubNode { name } => {
51- let current = path . last ( ) ;
52- if current . is_empty ( ) {
53- if name == CPUS || name == SOC || name. starts_with ( MEMORY ) {
56+ let current = ctx . name ( ) ;
57+ if ctx . is_root ( ) {
58+ if name == Str :: from ( CPUS ) || name == Str :: from ( SOC ) || name. starts_with ( MEMORY ) {
5459 StepInto
5560 } else {
5661 StepOver
5762 }
58- } else if current == SOC {
63+ } else if current == Str :: from ( SOC ) {
5964 if name. starts_with ( UART ) || name. starts_with ( TEST ) || name. starts_with ( CLINT ) {
6065 StepInto
6166 } else {
6267 StepOver
6368 }
6469 } else {
65- if current == CPUS && name. starts_with ( b "cpu@") {
70+ if current == Str :: from ( CPUS ) && name. starts_with ( "cpu@" ) {
6671 ans. smp += 1 ;
6772 }
6873 StepOver
6974 }
7075 }
71- DtbObj :: Property ( Property :: Model ( model) ) if path . last ( ) . is_empty ( ) => {
76+ DtbObj :: Property ( Property :: Model ( model) ) if ctx . is_root ( ) => {
7277 ans. model . 0 = model. as_bytes ( ) . len ( ) ;
7378 ans. model . 1 [ ..ans. model . 0 ] . copy_from_slice ( model. as_bytes ( ) ) ;
7479 StepOver
7580 }
7681 DtbObj :: Property ( Property :: Reg ( mut reg) ) => {
77- let node = path . last ( ) ;
82+ let node = ctx . name ( ) ;
7883 if node. starts_with ( UART ) {
7984 ans. uart = reg. next ( ) . unwrap ( ) ;
8085 StepOut
0 commit comments