Re: [PATCH v4 07/14] libpydt: Add DeviceTree live tree representation
From: Simon Glass
Date: Fri Nov 20 2026 - 10:20:44 EST
On 2026-11-16T20:52:57, Douglas Anderson <dianders@xxxxxxxxxxxx> wrote:
> libpydt: Add DeviceTree live tree representation
>
> `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/libpydt.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/libpydt_tests.py` covering `DeviceTree`
> round-tripping, subtree unflattening, duplicate-name and corrupt-tree
> rejection, and navigation helpers.
>
> Assisted-by: Gemini:gemini-pro-prerelease
> Signed-off-by: Douglas Anderson <dianders@xxxxxxxxxxxx>
>
> pylibfdt/libpydt.py | 184 +++++++++++++++++++++++++++++++++++++++++++++++++
> pylibfdt/meson.build | 2 +
> tests/libpydt_tests.py | 106 ++++++++++++++++++++++++++++
> tests/meson.build | 2 +-
> tests/run_tests.sh | 13 ++--
> 5 files changed, 302 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass <sjg@xxxxxxxxxxxx>