Sfoglia il codice sorgente

Parse FDT and dump nodes.

Andrew Walbran 2 anni fa
parent
commit
af9b93083f
2 ha cambiato i file con 31 aggiunte e 2 eliminazioni
  1. 1 0
      examples/aarch64/Cargo.toml
  2. 30 2
      examples/aarch64/src/main.rs

+ 1 - 0
examples/aarch64/Cargo.toml

@@ -5,6 +5,7 @@ authors = ["Andrew Walbran <qwandor@google.com>"]
 edition = "2021"
 
 [dependencies]
+fdt = "0.1.4"
 log = "0.4.17"
 psci = "0.1.1"
 spin = "0.9.4"

+ 30 - 2
examples/aarch64/src/main.rs

@@ -6,13 +6,41 @@ mod logger;
 mod pl011;
 
 use core::panic::PanicInfo;
-use log::{error, info, LevelFilter};
+use fdt::{standard_nodes::Compatible, Fdt};
+use log::{debug, error, info, trace, LevelFilter};
 use psci::system_off;
 
 #[no_mangle]
-extern "C" fn main(_x0: u64, _x1: u64, _x2: u64, _x3: u64) {
+extern "C" fn main(x0: u64, x1: u64, x2: u64, x3: u64) {
     logger::init(LevelFilter::Debug).unwrap();
     info!("virtio-drivers example started.");
+    debug!(
+        "x0={:#018x}, x1={:#018x}, x2={:#018x}, x3={:#018x}",
+        x0, x1, x2, x3
+    );
+
+    info!("Loading FDT from {:#018x}", x0);
+    // Safe because the pointer is a valid pointer to unaliased memory.
+    let fdt = unsafe { Fdt::from_ptr(x0 as *const u8).unwrap() };
+
+    for node in fdt.all_nodes() {
+        // Dump information about the node for debugging.
+        trace!(
+            "{}: {:?}",
+            node.name,
+            node.compatible().map(Compatible::first),
+        );
+        if let Some(reg) = node.reg() {
+            for range in reg {
+                trace!(
+                    "  {:#018x?}, length {:?}",
+                    range.starting_address,
+                    range.size
+                );
+            }
+        }
+    }
+
     system_off().unwrap();
 }