Re: [PATCH 3/4] fdtfactor: Support compressed DTB inputs and outputs

From: Doug Anderson

Date: Wed Oct 28 2026 - 17:59:52 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.
> > +LZ4_MAGIC = b'\x04\x22\x4d\x18'
> > +LZ4_LEGACY_MAGIC = b'\x02\x21\x4c\x18'
>
> Legacy lz4 input is detected here, but compress_blob() always runs
> 'lz4 -12 -z', which writes the frame format. So a legacy-format
> board.dtb.lz4 comes out as a frame-format board.dtbo.lz4. I checked:
> 'lz4 -l -9' output starts with 02 21 4c 18, while the compress_blob()
> command gives 04 22 4d 18. The kernel's cmd_lz4 uses 'lz4 -l', and
> lib/decompress_unlz4.c only accepts the legacy format. So a consumer
> that handles only one of the two formats cannot read the result. This
> doesn't match 'Preserve the input compression format' in the commit
> message. Please can you track legacy as its own compression type (and
> pass -l when compressing), or else reject legacy input?

Done.


> > +def decompress_blob(raw_bytes, filename='', comp=None):
> ...
> > + if comp == 'lz4':
> > + try:
> > + res = subprocess.run(
> > + ['lz4', '-d', '-q', '-c'],
> > + input=raw_bytes,
> > + capture_output=True,
> > + check=False,
> > + )
> > + except FileNotFoundError as exc:
> > + raise RuntimeError(
> > + 'lz4 command not found; install lz4 to process .lz4 files'
> > + ) from exc
>
> compress_blob() repeats this block almost exactly, so it should be in
> a helper. If the helper takes the filename, compression errors can
> also say which file failed.

Done.