Re: [PATCH v3 07/15] devicetree: Add DeviceTree live tree representation
From: David Gibson
Date: Wed Nov 11 2026 - 21:38:11 EST
On Wed, Nov 11, 2026 at 08:15:06PM +0000, Simon Glass wrote:
> Hi,
>
> On Tue, 10 Nov 2026 at 21:16, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > On Fri, Nov 06, 2026 at 06:43:18PM -0800, Doug Anderson wrote:
> > > Hi Simon,
> > >
> > > On Wed, Nov 4, 2026 at 6:08 AM Simon Glass <sjg@xxxxxxxxxxxx> wrote:
> > > >
> > > > Hi Doug,
> > > >
> > > > On Sun, Nov 1, 2026 at 4:02 PM Douglas Anderson <dianders@xxxxxxxxxxxx> wrote:
> > > > >
> > > > > Add `devicetree.py` providing `DeviceTree`, a non-flattened in-memory
> > > > > representation of a devicetree node and its subtree:
> > > >
> > > > Please can you start with the motivation, i.e. why a live tree is
> > > > needed and what will use it? The list below mostly repeats the
> > > > docstrings.
> > >
> > > Makes sense. In my draft v4 I've updated the commit message to lead
> > > with the motivation and condensed the summary so it doesn't repeat the
> > > docstrings:
> > >
> > > `pylibfdt`'s `Fdt` and `FdtRo` classes operate directly on flattened
> > > device tree blobs, where inserting or deleting nodes and properties
> > > shifts subsequent node offsets. That works well for in-place queries and
> > > localized edits, but makes multi-tree comparison, structural diffing,
> > > and bottom-up tree construction (as needed by the upcoming `fdtfactor`
> > > tool) awkward and error-prone.
> > >
> > > Add `pylibfdt/devicetree.py` providing `DeviceTree`, an in-memory live
> > > tree representation where each node holds `props` (a dict mapping
> > > property name to `libfdt.Property`) and `children` (a dict mapping child
> > > node name to child `DeviceTree`), along with `unflatten()` and
> > > `flatten()` to convert between `FdtRo`/`Fdt` blobs and live trees, and
> > > helpers for path lookup, node creation, and pre-order traversal.
> > >
> > > Add unit tests in `tests/devicetree_tests.py` covering `DeviceTree`
> > > round-tripping, subtree unflattening, duplicate-name and corrupt-tree
> > > rejection, and navigation helpers.
> > >
> > > > > diff --git a/devicetree.py b/devicetree.py
> > > > > new file mode 100644
> > > > > index 0000000..f81b8fc
> > > > > --- /dev/null
> > > > > +++ b/devicetree.py
> > > > > @@ -0,0 +1,226 @@
> > > > > +# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
> > > > > +"""devicetree - Non-flattened in-memory device tree representation in Python."""
> > > >
> > > > I'd forgotten about this but PyPI has Zephyr's python-devicetree
> > > > [1][2], which installs a top-level 'devicetree' package.
> > > >
> > > > I'm not sure what to suggest. Would libfdt_devicetree be too awful?
> > >
> > > Right. I'm OK with libfdt_devicetree. David: do you have any
> > > objections?
> >
> > Don't love it, but can't quickly think of a better option.
>
> Would libfdt_tree be better?
Not really. The problem with all of the above is that they're making
this library which is about managing a non-flattened device tree a
part of the library/project/namespace that's explicitly about
flattened device trees.
--
David Gibson (he or they) | 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
Attachment:
signature.asc
Description: PGP signature