Browse Source

feat: use latest serde-device-tree to rewrite parse

Signed-off-by: Woshiluo Luo <woshiluo.luo@outlook.com>
Woshiluo Luo 4 months ago
parent
commit
dfc10562a0
3 changed files with 11 additions and 22 deletions
  1. 1 1
      Cargo.lock
  2. 1 2
      prototyper/src/board.rs
  3. 9 19
      prototyper/src/dt.rs

+ 1 - 1
Cargo.lock

@@ -245,7 +245,7 @@ dependencies = [
 [[package]]
 name = "serde-device-tree"
 version = "0.0.1"
-source = "git+https://github.com/rustsbi/serde-device-tree#1ca431a23b70f9209caa3f72986f892508c17a69"
+source = "git+https://github.com/rustsbi/serde-device-tree#6d152e0160ff1dadd2f42638c3d85e0d6a2914bf"
 dependencies = [
  "serde",
 ]

+ 1 - 2
prototyper/src/board.rs

@@ -139,8 +139,7 @@ impl Board {
         // TODO: should remove `fail:device_tree_deserialize`.
         let root: serde_device_tree::buildin::Node = serde_device_tree::from_raw_mut(&dtb)
             .unwrap_or_else(fail::device_tree_deserialize_root);
-        let tree =
-            serde_device_tree::from_raw_mut(&dtb).unwrap_or_else(fail::device_tree_deserialize);
+        let tree: dt::Tree = root.deserialize();
 
         //  Get console device info
         for console_path in tree.chosen.stdout_path.iter() {

+ 9 - 19
prototyper/src/dt.rs

@@ -76,26 +76,16 @@ pub fn parse_device_tree(opaque: usize) -> Result<Dtb, ParseDeviceTreeError> {
 
 pub fn get_compatible_and_range<'de>(node: &Node) -> Option<(StrSeq<'de>, Range<usize>)> {
     let compatible = node
-        .props()
-        .map(|mut prop_iter| {
-            prop_iter
-                .find(|prop_item| prop_item.get_name() == "compatible")
-                .map(|prop_item| prop_item.deserialize::<serde_device_tree::buildin::StrSeq>())
-        })
-        .map_or_else(|| None, |v| v);
+        .get_prop("compatible")
+        .map(|prop_item| prop_item.deserialize::<StrSeq<'de>>());
     let regs = node
-        .props()
-        .map(|mut prop_iter| {
-            prop_iter
-                .find(|prop_item| prop_item.get_name() == "reg")
-                .map(|prop_item| {
-                    let reg = prop_item.deserialize::<serde_device_tree::buildin::Reg>();
-                    if let Some(range) = reg.iter().next() {
-                        return Some(range);
-                    }
-                    None
-                })
-                .map_or_else(|| None, |v| v)
+        .get_prop("reg")
+        .map(|prop_item| {
+            let reg = prop_item.deserialize::<serde_device_tree::buildin::Reg>();
+            if let Some(range) = reg.iter().next() {
+                return Some(range);
+            }
+            None
         })
         .map_or_else(|| None, |v| v);
     if let Some(compatible) = compatible {