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 <treding@nvidia.com>
Message-Id: <20190320151003.28941-1-thierry.reding@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Thierry Reding
2019-03-20 16:10:03 +01:00
committed by David Gibson
parent 4762ad051e
commit 54ea41c224
9 changed files with 114 additions and 3 deletions

View File

@@ -39,6 +39,11 @@ m1: mq: /memreserve/ 0 0x1000;
n2 = &n2;
n3 = &n3;
};
node6 {
linux,phandle = <0xfffffffe>;
phandle = <0xfffffffe>;
};
};
/ {