Re: [PATCH v2 07/10] fdtfactor: Add tool to split DTBs into a base DTB and overlays
From: Simon Glass
Date: Fri Oct 30 2026 - 08:53:00 EST
On 2026-10-28T21:46:49, Douglas Anderson <dianders@xxxxxxxxxxxx> wrote:
> fdtfactor: Add tool to split DTBs into a base DTB and overlays
>
> When shipping a single firmware or kernel image that supports many
> closely related board variants or SKUs, bundling a full compiled .dtb
> for every variant results in substantial duplication.
>
> Add `fdtfactor`, a Python tool built on `pylibfdt` that takes a set of
> compiled device tree blobs (.dtb) compiled with `-@ -L` (`/__symbols__`
> and `/__local_fixups__`) and splits them into a single common
> `base.dtb` and per-board `.dtbo` overlays:
>
> - Common nodes present across all input DTBs are placed in `base.dtb`,
> with each common property assigned the value shared by at least two
> boards that maximizes byte savings across overlays.
> - Using `/__local_fixups__`, phandle references inside property values
> are normalized to target node paths so common properties referencing
> common nodes match even when numeric phandles differ across input
> DTBs.
> - Any common node that carries a phandle in any input DTB receives its
> phandle in `base.dtb` so overlays only emit `phandle` properties on
> newly added subnodes, matching the requirements of `libfdt`, Linux's
> `drivers/of/overlay.c`, and coreboot's `dt_apply_overlay()`.
>
> Add a `fdtfactor` test suite in `tests/run_tests.sh` verifying that
> applying each generated `.dtbo` to `base.dtb` with `fdtoverlay`
> reconstructs the original DTB (verified via `dtbs_equal_unordered`,
> including across input DTBs with shifted phandle numbers).
>
> Assisted-by: Gemini:gemini-pro-prerelease
> Signed-off-by: Douglas Anderson <dianders@xxxxxxxxxxxx>
>
> Makefile | 2 +-
> README.md | 43 ++
> fdtfactor | 814 +++++++++++++++++++++++++++++++++++++
> meson.build | 1 +
> tests/Makefile.tests | 4 +-
> tests/fdtfactor_board1.dts | 38 ++
> tests/fdtfactor_board2.dts | 36 ++
> tests/fdtfactor_board3.dts | 34 ++
> tests/fdtfactor_board3_shifted.dts | 34 ++
> tests/meson.build | 2 +-
> tests/run_tests.sh | 65 ++-
> tests/testutils.sh | 1 +
> 12 files changed, 1067 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass <sjg@xxxxxxxxxxxx>