pvmfw: refactor: Generalize BCC DT node creation
As we expect to pass more data to the next stage than the BCC alone,
introduce a way for main() to collect the various settings influencing
the final DT operations.
Note: No functional change intended.
Bug: 268307476
Test: atest MicrodroidHostTests
Change-Id: I7b8f812ffc622c2cd527e1c3247267cc87be1b9e
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index 927bf50..1d295eb 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -405,6 +405,24 @@
fdt_err_expect_zero(ret)
}
+ /// Create or change a flag-like empty property.
+ pub fn setprop_empty(&mut self, name: &CStr) -> Result<()> {
+ self.setprop(name, &[])
+ }
+
+ /// Delete the given property.
+ pub fn delprop(&mut self, name: &CStr) -> Result<()> {
+ // SAFETY - Accesses are constrained to the DT totalsize (validated by ctor) when the
+ // library locates the node's property. Removing the property may shift the offsets of
+ // other nodes and properties but the borrow checker should prevent this function from
+ // being called when FdtNode instances are in use.
+ let ret = unsafe {
+ libfdt_bindgen::fdt_delprop(self.fdt.as_mut_ptr(), self.offset, name.as_ptr())
+ };
+
+ fdt_err_expect_zero(ret)
+ }
+
/// Get reference to the containing device tree.
pub fn fdt(&mut self) -> &mut Fdt {
self.fdt
@@ -561,6 +579,11 @@
self.node(CStr::from_bytes_with_nul(b"/chosen\0").unwrap())
}
+ /// Retrieve the standard /chosen node as mutable.
+ pub fn chosen_mut(&mut self) -> Result<Option<FdtNodeMut>> {
+ self.node_mut(CStr::from_bytes_with_nul(b"/chosen\0").unwrap())
+ }
+
/// Get the root node of the tree.
pub fn root(&self) -> Result<FdtNode> {
self.node(CStr::from_bytes_with_nul(b"/\0").unwrap())?.ok_or(FdtError::Internal)