libfdt: Add CompatibleIterator
Add an iterator over FDT nodes sharing a compatible string, to be used
by drivers to locate their devices.
Bug: 237249743
Bug: 255521657
Test: atest vmbase_example.integration_test
Change-Id: I012bb6e93c286189d763685e9be7eba6952022f0
diff --git a/vmbase/example/src/main.rs b/vmbase/example/src/main.rs
index 3d74168..dcff6e1 100644
--- a/vmbase/example/src/main.rs
+++ b/vmbase/example/src/main.rs
@@ -33,6 +33,7 @@
};
use alloc::{vec, vec::Vec};
use buddy_system_allocator::LockedHeap;
+use core::ffi::CStr;
use libfdt::Fdt;
use log::{info, LevelFilter};
use vmbase::{logger, main, println};
@@ -154,6 +155,13 @@
info!("memory @ {reg:#x?}");
}
+ let compatible = CStr::from_bytes_with_nul(b"ns16550a\0").unwrap();
+
+ for c in reader.compatible_nodes(compatible).unwrap() {
+ let reg = c.reg().unwrap().next().unwrap();
+ info!("node compatible with '{}' at {reg:?}", compatible.to_str().unwrap());
+ }
+
info!("FDT checks done.");
}