Re: [PATCH 2/4] fdtfactor: Add tool to split DTBs into a base DTB and overlays
From: Doug Anderson
Date: Wed Oct 28 2026 - 17:58:50 EST
Hi Simon,
On Mon, Oct 26, 2026 at 8:31 AM Simon Glass <sjg@xxxxxxxxxxxx> wrote:
>
> > diff --git a/fdtfactor b/fdtfactor
> > @@ -11,31 +11,195 @@ original device tree.
> > + if comp == 'xz':
> > + return lzma.compress(raw_bytes, format=lzma.FORMAT_XZ)
>
> Python's default integrity check for FORMAT_XZ is CRC64, but embedded
> xz decoders often support only CRC32. The kernel's lib/xz is one of
> them, which is why scripts/xz_wrap.sh passes --check=crc32 to xz. So a
> firmware-friendly .dtb.xz input could produce a .dtbo.xz that the same
> firmware cannot read. Please can you pass check=lzma.CHECK_CRC32 here?
Done. compress_blob() now passes check=lzma.CHECK_CRC32 for FORMAT_XZ.
> > diff --git a/fdtfactor b/fdtfactor
> > @@ -1167,20 +1349,24 @@ def factor_dtb_files(args):
> > d, base_dtb_blob, dtbo_blob, args.strip_local_fixups
> > )
> >
> > + base_dtb_file_bytes = compress_blob(base_dtb_blob, base_dtb_comp)
>
> If you keep --verify in the tool (David suggests it belongs in the
> test suite), it would be worth running the compressed bytes back
> through decompress_blob() and comparing them, since at present only
> the uncompressed blobs are checked. That is cheap and would catch a
> problem with the lz4 command or the compression options.
I removed the --verify and made sure things were well-tested in
the test suites.
> > diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> > @@ -1147,6 +1147,36 @@ fdtoverlay_tests() {
> > + run_wrap_test $PYTHON "$FDTFACTOR" -v --verify \
> > + -b "fdtfactor_base.test.dtb.$ext" \
>
> In these tests the base output always uses the same compression as the
> inputs, and the input extension always matches the file contents. Two
> extra cases would be good, perhaps as a follow-up: a compressed blob
> in a plain '.dtb' file (to exercise the magic-byte detection) and, if
> -b stays, an uncompressed -b alongside compressed inputs.
Done. Added a test case in tests/run_tests.sh that passes a gzip-compressed
blob with a plain '.dtb' extension alongside '.dtb.gz' inputs and writes an
uncompressed '-b' output (plus another test exercising --base-compression).