libfdt: Add phandle generation helper
The new fdt_generate_phandle() function can be used to generate a new,
unused phandle given a specific device tree blob. The implementation is
somewhat naive in that it simply walks the entire device tree to find
the highest phandle value and then returns a phandle value one higher
than that. A more clever implementation might try to find holes in the
current set of phandle values and fill them. But this implementation is
relatively simple and works reliably.
Also add a test that validates that phandles generated by this new API
are indeed unique.
Signed-off-by: Thierry Reding <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: David Gibson <[email protected]>
diff --git a/tests/references.dts b/tests/references.dts
index f783e8b..b390639 100644
--- a/tests/references.dts
+++ b/tests/references.dts
@@ -33,4 +33,9 @@
linux,phandle = <&n5>;
phandle = <&n5>;
};
+
+ node6 {
+ linux,phandle = <0xfffffffe>;
+ phandle = <0xfffffffe>;
+ };
};