generating a phandle w/libfdt?

David Gibson david at gibson.dropbear.id.au
Mon Oct 27 10:44:41 EST 2008


On Fri, Oct 24, 2008 at 08:11:33AM -0500, Kumar Gala wrote:
> In some work I'm doing I noticed we don't have any APIs to generate a  
> phandle via libfdt.
>
> was wondering if anyone had ideas on this.
>
> In first thought it seems we have to scan through the whole blob looking 
> for the largest phandle id and than +1 it to generate the next "valid" 
> id.  Any other ideas on how to do this more efficiently?

I don't think it can be done more efficiently, without assuming things
about how any existing phandles are allocated, which I don't think is
wise.

Heck, even that's more efficient (theoretically, anyway) than the
method used internally in dtc.  There, we have a "next phandle"
counter which starts at one.  When we want to allocate a phandle we
try counter values, testing them with find_node_by_phandle() one by
one until we reach an unused one.  Of course, because all the phandles
are usually allocated by dtc, in practice that usually only results in
one pass through the tree, although it can be many in principle.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson



More information about the devicetree-discuss mailing list