libfdt: Add phandle APIs

This CL adds following APIs
  - Fdt::max_phandle(): Returns the max phandle
  - Fdt::node_with_phandle(): Returns the node with phandle

Bug: 277993056
Test: atest liblibfdt.integration_test
Change-Id: I155242718b09897e832834a621f9e244ed2d9807
diff --git a/libs/libfdt/tests/api_test.rs b/libs/libfdt/tests/api_test.rs
index ccbf9a5..5484185 100644
--- a/libs/libfdt/tests/api_test.rs
+++ b/libs/libfdt/tests/api_test.rs
@@ -16,7 +16,7 @@
 
 //! Integration tests of the library libfdt.
 
-use libfdt::{Fdt, FdtError};
+use libfdt::{Fdt, FdtError, Phandle};
 use std::ffi::CStr;
 use std::fs;
 use std::ops::Range;
@@ -32,6 +32,7 @@
     "data/test_tree_multiple_memory_ranges.dtb";
 const TEST_TREE_WITH_EMPTY_MEMORY_RANGE_PATH: &str = "data/test_tree_empty_memory_range.dtb";
 const TEST_TREE_WITH_NO_MEMORY_NODE_PATH: &str = "data/test_tree_no_memory_node.dtb";
+const TEST_TREE_PHANDLE_PATH: &str = "data/test_tree_phandle.dtb";
 
 #[test]
 fn retrieving_memory_from_fdt_with_one_memory_range_succeeds() {
@@ -138,3 +139,33 @@
         assert_eq!(supernode.name().unwrap().to_str().unwrap(), *expect);
     }
 }
+
+#[test]
+fn phandle_new() {
+    let phandle_u32 = 0x55;
+    let phandle = Phandle::new(phandle_u32).unwrap();
+
+    assert_eq!(u32::from(phandle), phandle_u32);
+}
+
+#[test]
+fn max_phandle() {
+    let data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
+    let fdt = Fdt::from_slice(&data).unwrap();
+
+    assert_eq!(fdt.max_phandle().unwrap(), Phandle::new(0xFF).unwrap());
+}
+
+#[test]
+fn node_with_phandle() {
+    let data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
+    let fdt = Fdt::from_slice(&data).unwrap();
+
+    // Test linux,phandle
+    let node = fdt.node_with_phandle(Phandle::new(0xFF).unwrap()).unwrap().unwrap();
+    assert_eq!(node.name().unwrap().to_str().unwrap(), "node_zz");
+
+    // Test phandle
+    let node = fdt.node_with_phandle(Phandle::new(0x22).unwrap()).unwrap().unwrap();
+    assert_eq!(node.name().unwrap().to_str().unwrap(), "node_abc");
+}