linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations
@ 2025-12-27 14:21 Simon Glass
  2025-12-27 14:21 ` [PATCH v8 1/6] scripts/make_fit: Speed up operation Simon Glass
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, Alice Ryhl, Ard Biesheuvel, David Sterba,
	Ingo Molnar, Josh Poimboeuf, Kees Cook, Nathan Chancellor,
	Nick Terrell, Nicolas Schier, Oleh Zadorozhnyi, Petr Mladek,
	linux-kbuild, linux-kernel

This series updates 'make image.fit' to support adding a ramdisk to the
FIT, provided as a parameter.

It also includes a few performance improvement, so that building a FIT
from ~450MB of kernel/module/devicetree files only takes a few seconds
on a modern machine.

For this version I have dropped inclusion of built modules, as there is
still more discussion to happen in that area.

Changes in v8:
- Drop erroneous line 'kbuild: Allow adding modules into the FIT ...'

Changes in v7:
- Add a note about the " -> ' change
- Add a new patch with the MAKE_FIT_FLAGS change
- Mention xz as well, in the commit message
- Drop patch 'scripts/make_fit: Provide a way to add built modules'
- Drop patch 'kbuild: Split out module targets into a variable'
- Drop patch 'kbuild: Allow adding modules into the FIT ramdisk'

Changes in v6:
- Drop the load address for ramdisk, as it is not needed
- Bring back the ramdisk 'compression' property, set to 'none'

Changes in v5:
- Fix 'use' typo

Changes in v4:
- Update the commit message

Changes in v3:
- Move the ramdisk chunk into the correct patch
- Add a comment at the top of the file about the -r option
- Count the ramdisk in the total files
- Update the commit message

Changes in v2:
- Don't compress the ramdisk as it is already compressed

Simon Glass (6):
  scripts/make_fit: Speed up operation
  scripts/make_fit: Support an initial ramdisk
  scripts/make_fit: Move dtb processing into a function
  kbuild: Support a MAKE_FIT_FLAGS environment variable
  scripts/make_fit: Support a few more parallel compressors
  scripts/make_fit: Compress dtbs in parallel

 scripts/Makefile.lib |   2 +-
 scripts/make_fit.py  | 179 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 145 insertions(+), 36 deletions(-)

-- 
2.43.0

base-commit: c53f467229a78287efa5b9f65bd22de64416660f
branch: fita8


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v8 1/6] scripts/make_fit: Speed up operation
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  2025-12-27 14:21 ` [PATCH v8 2/6] scripts/make_fit: Support an initial ramdisk Simon Glass
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, Nicolas Schier, linux-kernel

The kernel is likely at least 16MB so we may as well use that as a step
size when reallocating space for the FIT in memory. Pack the FIT at the
end, so there is no wasted space.

This reduces the time to pack by an order of magnitude, or so.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Tested-by: Chen-Yu Tsai <wenst@chromium.org>
---

(no changes since v3)

Changes in v3:
- Move the ramdisk chunk into the correct patch

 scripts/make_fit.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 1683e5ec6e67..0f5e7c4b8aed 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -98,7 +98,7 @@ def setup_fit(fsw, name):
         fsw (libfdt.FdtSw): Object to use for writing
         name (str): Name of kernel image
     """
-    fsw.INC_SIZE = 65536
+    fsw.INC_SIZE = 16 << 20
     fsw.finish_reservemap()
     fsw.begin_node('')
     fsw.property_string('description', f'{name} with devicetree set')
@@ -299,7 +299,9 @@ def build_fit(args):
     finish_fit(fsw, entries)
 
     # Include the kernel itself in the returned file count
-    return fsw.as_fdt().as_bytearray(), seq + 1, size
+    fdt = fsw.as_fdt()
+    fdt.pack()
+    return fdt.as_bytearray(), seq + 1, size
 
 
 def run_make_fit():
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 2/6] scripts/make_fit: Support an initial ramdisk
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
  2025-12-27 14:21 ` [PATCH v8 1/6] scripts/make_fit: Speed up operation Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  2025-12-27 14:21 ` [PATCH v8 3/6] scripts/make_fit: Move dtb processing into a function Simon Glass
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, Nicolas Schier, linux-kernel

FIT (Flat Image Tree) allows a ramdisk to be included in each
configuration. Add support for this to the script.

This feature is not available via 'make image.fit' since the ramdisk
likely needs to be built separately anyway, e.g. using modules from
the kernel build. Future work may provide support for doing that.

Note that the uncompressed size is not correct when a ramdisk is used,
since it is too expensive to decompress the ramdisk.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---

(no changes since v6)

Changes in v6:
- Drop the load address for ramdisk, as it is not needed
- Bring back the ramdisk 'compression' property, set to 'none'

Changes in v5:
- Fix 'use' typo

Changes in v4:
- Update the commit message

Changes in v3:
- Add a comment at the top of the file about the -r option
- Count the ramdisk in the total files
- Update the commit message

Changes in v2:
- Don't compress the ramdisk as it is already compressed

 scripts/make_fit.py | 52 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 0f5e7c4b8aed..66cd73711506 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -10,10 +10,14 @@
 Usage:
     make_fit.py -A arm64 -n 'Linux-6.6' -O linux
         -o arch/arm64/boot/image.fit -k /tmp/kern/arch/arm64/boot/image.itk
-        @arch/arm64/boot/dts/dtbs-list -E -c gzip
+        -r /boot/initrd.img-6.14.0-27-generic @arch/arm64/boot/dts/dtbs-list
+        -E -c gzip
 
-Creates a FIT containing the supplied kernel and a set of devicetree files,
-either specified individually or listed in a file (with an '@' prefix).
+Creates a FIT containing the supplied kernel, an optional ramdisk, and a set of
+devicetree files, either specified individually or listed in a file (with an
+'@' prefix).
+
+Use -r to specify an existing ramdisk/initrd file.
 
 Use -E to generate an external FIT (where the data is placed after the
 FIT data structure). This allows parsing of the data without loading
@@ -29,8 +33,6 @@ looks at the .cmd files produced by the kernel build.
 
 The resulting FIT can be booted by bootloaders which support FIT, such
 as U-Boot, Linuxboot, Tianocore, etc.
-
-Note that this tool does not yet support adding a ramdisk / initrd.
 """
 
 import argparse
@@ -81,6 +83,8 @@ def parse_args():
           help='Specifies the operating system')
     parser.add_argument('-k', '--kernel', type=str, required=True,
           help='Specifies the (uncompressed) kernel input file (.itk)')
+    parser.add_argument('-r', '--ramdisk', type=str,
+          help='Specifies the ramdisk/initrd input file')
     parser.add_argument('-v', '--verbose', action='store_true',
                         help='Enable verbose output')
     parser.add_argument('dtbs', type=str, nargs='*',
@@ -133,7 +137,28 @@ def write_kernel(fsw, data, args):
         fsw.property_u32('entry', 0)
 
 
-def finish_fit(fsw, entries):
+def write_ramdisk(fsw, data, args):
+    """Write out the ramdisk image
+
+    Writes a ramdisk node along with the required properties
+
+    Args:
+        fsw (libfdt.FdtSw): Object to use for writing
+        data (bytes): Data to write (possibly compressed)
+        args (Namespace): Contains necessary strings:
+            arch: FIT architecture, e.g. 'arm64'
+            fit_os: Operating Systems, e.g. 'linux'
+    """
+    with fsw.add_node('ramdisk'):
+        fsw.property_string('description', 'Ramdisk')
+        fsw.property_string('type', 'ramdisk')
+        fsw.property_string('arch', args.arch)
+        fsw.property_string('compression', 'none')
+        fsw.property_string('os', args.os)
+        fsw.property('data', data)
+
+
+def finish_fit(fsw, entries, has_ramdisk=False):
     """Finish the FIT ready for use
 
     Writes the /configurations node and subnodes
@@ -143,6 +168,7 @@ def finish_fit(fsw, entries):
         entries (list of tuple): List of configurations:
             str: Description of model
             str: Compatible stringlist
+        has_ramdisk (bool): True if a ramdisk is included in the FIT
     """
     fsw.end_node()
     seq = 0
@@ -154,6 +180,8 @@ def finish_fit(fsw, entries):
                 fsw.property_string('description', model)
                 fsw.property('fdt', bytes(''.join(f'fdt-{x}\x00' for x in files), "ascii"))
                 fsw.property_string('kernel', 'kernel')
+                if has_ramdisk:
+                    fsw.property_string('ramdisk', 'ramdisk')
     fsw.end_node()
 
 
@@ -274,6 +302,14 @@ def build_fit(args):
     size += os.path.getsize(args.kernel)
     write_kernel(fsw, comp_data, args)
 
+    # Handle the ramdisk if provided. Compression is not supported as it is
+    # already compressed.
+    if args.ramdisk:
+        with open(args.ramdisk, 'rb') as inf:
+            data = inf.read()
+        size += len(data)
+        write_ramdisk(fsw, data, args)
+
     for fname in args.dtbs:
         # Ignore non-DTB (*.dtb) files
         if os.path.splitext(fname)[1] != '.dtb':
@@ -296,12 +332,12 @@ def build_fit(args):
 
         entries.append([model, compat, files_seq])
 
-    finish_fit(fsw, entries)
+    finish_fit(fsw, entries, bool(args.ramdisk))
 
     # Include the kernel itself in the returned file count
     fdt = fsw.as_fdt()
     fdt.pack()
-    return fdt.as_bytearray(), seq + 1, size
+    return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size
 
 
 def run_make_fit():
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 3/6] scripts/make_fit: Move dtb processing into a function
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
  2025-12-27 14:21 ` [PATCH v8 1/6] scripts/make_fit: Speed up operation Simon Glass
  2025-12-27 14:21 ` [PATCH v8 2/6] scripts/make_fit: Support an initial ramdisk Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  2025-12-27 14:21 ` [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable Simon Glass
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, Nicolas Schier, linux-kernel

Since build_fit() is getting quite long, move the dtb processing into a
separate function.

Change the double quotes in the write() call to single, to match the
rest of the script.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
---

(no changes since v7)

Changes in v7:
- Add a note about the " -> ' change

 scripts/make_fit.py | 67 +++++++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 23 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 66cd73711506..7ddaf3c0d783 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -277,6 +277,47 @@ def process_dtb(fname, args):
 
     return (model, compat, files)
 
+
+def _process_dtbs(args, fsw, entries, fdts):
+    """Process all DTB files and add them to the FIT
+
+    Args:
+        args: Program arguments
+        fsw: FIT writer object
+        entries: List to append entries to
+        fdts: Dictionary of processed DTBs
+
+    Returns:
+        tuple:
+            Number of files processed
+            Total size of files processed
+    """
+    seq = 0
+    size = 0
+    for fname in args.dtbs:
+        # Ignore non-DTB (*.dtb) files
+        if os.path.splitext(fname)[1] != '.dtb':
+            continue
+
+        try:
+            (model, compat, files) = process_dtb(fname, args)
+        except Exception as e:
+            sys.stderr.write(f'Error processing {fname}:\n')
+            raise e
+
+        for fn in files:
+            if fn not in fdts:
+                seq += 1
+                size += os.path.getsize(fn)
+                output_dtb(fsw, seq, fn, args.arch, args.compress)
+                fdts[fn] = seq
+
+        files_seq = [fdts[fn] for fn in files]
+        entries.append([model, compat, files_seq])
+
+    return seq, size
+
+
 def build_fit(args):
     """Build the FIT from the provided files and arguments
 
@@ -289,7 +330,6 @@ def build_fit(args):
             int: Number of configurations generated
             size: Total uncompressed size of data
     """
-    seq = 0
     size = 0
     fsw = libfdt.FdtSw()
     setup_fit(fsw, args.name)
@@ -310,34 +350,15 @@ def build_fit(args):
         size += len(data)
         write_ramdisk(fsw, data, args)
 
-    for fname in args.dtbs:
-        # Ignore non-DTB (*.dtb) files
-        if os.path.splitext(fname)[1] != '.dtb':
-            continue
-
-        try:
-            (model, compat, files) = process_dtb(fname, args)
-        except Exception as e:
-            sys.stderr.write(f"Error processing {fname}:\n")
-            raise e
-
-        for fn in files:
-            if fn not in fdts:
-                seq += 1
-                size += os.path.getsize(fn)
-                output_dtb(fsw, seq, fn, args.arch, args.compress)
-                fdts[fn] = seq
-
-        files_seq = [fdts[fn] for fn in files]
-
-        entries.append([model, compat, files_seq])
+    count, fdt_size = _process_dtbs(args, fsw, entries, fdts)
+    size += fdt_size
 
     finish_fit(fsw, entries, bool(args.ramdisk))
 
     # Include the kernel itself in the returned file count
     fdt = fsw.as_fdt()
     fdt.pack()
-    return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size
+    return fdt.as_bytearray(), count + 1 + bool(args.ramdisk), size
 
 
 def run_make_fit():
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
                   ` (2 preceding siblings ...)
  2025-12-27 14:21 ` [PATCH v8 3/6] scripts/make_fit: Move dtb processing into a function Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  2025-12-27 16:36   ` Nicolas Schier
  2025-12-29 11:16   ` Thomas Weißschuh
  2025-12-27 14:21 ` [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors Simon Glass
  2025-12-27 14:21 ` [PATCH v8 6/6] scripts/make_fit: Compress dtbs in parallel Simon Glass
  5 siblings, 2 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, Alice Ryhl, Ard Biesheuvel, Ingo Molnar,
	Josh Poimboeuf, Kees Cook, Nathan Chancellor, Nicolas Schier,
	Oleh Zadorozhnyi, Petr Mladek, linux-kbuild, linux-kernel

In some cases it is useful to be able to pass additional flags to the
make_fit.py script. For example, since ramdisks are typically large,
passing -E to use external data can be helpful.

Add a new MAKE_FIT_FLAGS variable for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v7)

Changes in v7:
- Add a new patch with the MAKE_FIT_FLAGS change

 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 28a1c08e3b22..a5641a6538b1 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -400,7 +400,7 @@ FIT_COMPRESSION ?= gzip
 
 quiet_cmd_fit = FIT     $@
       cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \
-		--name '$(UIMAGE_NAME)' \
+		--name '$(UIMAGE_NAME)' $(MAKE_FIT_FLAGS) \
 		$(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \
 		$(if $(FIT_DECOMPOSE_DTBS),--decompose-dtbs) \
 		--compress $(FIT_COMPRESSION) -k $< @$(word 2,$^)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
                   ` (3 preceding siblings ...)
  2025-12-27 14:21 ` [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  2025-12-27 16:34   ` Nicolas Schier
  2025-12-27 14:21 ` [PATCH v8 6/6] scripts/make_fit: Compress dtbs in parallel Simon Glass
  5 siblings, 1 reply; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, David Sterba, Nick Terrell, linux-kernel

Add support for pbzip2, xz and plzip which can compress in parallel.
This speeds up the ramdisk compression.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v7)

Changes in v7:
- Mention xz as well, in the commit message

 scripts/make_fit.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 7ddaf3c0d783..defb87f223d7 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -50,11 +50,12 @@ import libfdt
 CompTool = collections.namedtuple('CompTool', 'ext,tools')
 
 COMP_TOOLS = {
-    'bzip2': CompTool('.bz2', 'bzip2'),
+    'bzip2': CompTool('.bz2', 'pbzip2,bzip2'),
     'gzip': CompTool('.gz', 'pigz,gzip'),
     'lz4': CompTool('.lz4', 'lz4'),
-    'lzma': CompTool('.lzma', 'lzma'),
+    'lzma': CompTool('.lzma', 'plzip,lzma'),
     'lzo': CompTool('.lzo', 'lzop'),
+    'xz': CompTool('.xz', 'xz'),
     'zstd': CompTool('.zstd', 'zstd'),
 }
 
@@ -207,7 +208,12 @@ def compress_data(inf, compress):
             done = False
             for tool in comp.tools.split(','):
                 try:
-                    subprocess.call([tool, '-c'], stdin=inf, stdout=outf)
+                    # Add parallel flags for tools that support them
+                    cmd = [tool]
+                    if tool in ('zstd', 'xz'):
+                        cmd.extend(['-T0'])  # Use all available cores
+                    cmd.append('-c')
+                    subprocess.call(cmd, stdin=inf, stdout=outf)
                     done = True
                     break
                 except FileNotFoundError:
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 6/6] scripts/make_fit: Compress dtbs in parallel
  2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
                   ` (4 preceding siblings ...)
  2025-12-27 14:21 ` [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors Simon Glass
@ 2025-12-27 14:21 ` Simon Glass
  5 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2025-12-27 14:21 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Masahiro Yamada, Chen-Yu Tsai, Thomas Weißschuh,
	Nicolas Schier, J . Neuschäfer, Ahmad Fatoum, Tom Rini,
	Simon Glass, linux-kernel

When there are 1500 device tree files it takes quite a while to compress
them. Do it in parallel.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v8:
- Drop erroneous line 'kbuild: Allow adding modules into the FIT ...'

 scripts/make_fit.py | 56 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 6 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index defb87f223d7..e923cc8b05b7 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -37,6 +37,7 @@ as U-Boot, Linuxboot, Tianocore, etc.
 
 import argparse
 import collections
+import multiprocessing
 import os
 import subprocess
 import sys
@@ -225,15 +226,31 @@ def compress_data(inf, compress):
     return comp_data
 
 
-def output_dtb(fsw, seq, fname, arch, compress):
+def compress_dtb(fname, compress):
+    """Compress a single DTB file
+
+    Args:
+        fname (str): Filename containing the DTB
+        compress (str): Compression algorithm, e.g. 'gzip'
+
+    Returns:
+        tuple: (str: fname, bytes: compressed_data)
+    """
+    with open(fname, 'rb') as inf:
+        compressed = compress_data(inf, compress)
+    return fname, compressed
+
+
+def output_dtb(fsw, seq, fname, arch, compress, data=None):
     """Write out a single devicetree to the FIT
 
     Args:
         fsw (libfdt.FdtSw): Object to use for writing
         seq (int): Sequence number (1 for first)
         fname (str): Filename containing the DTB
-        arch: FIT architecture, e.g. 'arm64'
+        arch (str): FIT architecture, e.g. 'arm64'
         compress (str): Compressed algorithm, e.g. 'gzip'
+        data (bytes): Pre-compressed data (optional)
     """
     with fsw.add_node(f'fdt-{seq}'):
         fsw.property_string('description', os.path.basename(fname))
@@ -241,9 +258,10 @@ def output_dtb(fsw, seq, fname, arch, compress):
         fsw.property_string('arch', arch)
         fsw.property_string('compression', compress)
 
-        with open(fname, 'rb') as inf:
-            compressed = compress_data(inf, compress)
-        fsw.property('data', compressed)
+        if data is None:
+            with open(fname, 'rb') as inf:
+                data = compress_data(inf, compress)
+        fsw.property('data', data)
 
 
 def process_dtb(fname, args):
@@ -300,6 +318,11 @@ def _process_dtbs(args, fsw, entries, fdts):
     """
     seq = 0
     size = 0
+
+    # First figure out the unique DTB files that need compression
+    todo = []
+    file_info = []  # List of (fname, model, compat, files) tuples
+
     for fname in args.dtbs:
         # Ignore non-DTB (*.dtb) files
         if os.path.splitext(fname)[1] != '.dtb':
@@ -311,11 +334,32 @@ def _process_dtbs(args, fsw, entries, fdts):
             sys.stderr.write(f'Error processing {fname}:\n')
             raise e
 
+        file_info.append((fname, model, compat, files))
+        for fn in files:
+            if fn not in fdts and fn not in todo:
+                todo.append(fn)
+
+    # Compress all DTBs in parallel
+    cache = {}
+    if todo and args.compress != 'none':
+        if args.verbose:
+            print(f'Compressing {len(todo)} DTBs...')
+
+        with multiprocessing.Pool() as pool:
+            compress_args = [(fn, args.compress) for fn in todo]
+            # unpacks each tuple, calls compress_dtb(fn, compress) in parallel
+            results = pool.starmap(compress_dtb, compress_args)
+
+        cache = dict(results)
+
+    # Now write all DTBs to the FIT using pre-compressed data
+    for fname, model, compat, files in file_info:
         for fn in files:
             if fn not in fdts:
                 seq += 1
                 size += os.path.getsize(fn)
-                output_dtb(fsw, seq, fn, args.arch, args.compress)
+                output_dtb(fsw, seq, fn, args.arch, args.compress,
+                           cache.get(fn))
                 fdts[fn] = seq
 
         files_seq = [fdts[fn] for fn in files]
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors
  2025-12-27 14:21 ` [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors Simon Glass
@ 2025-12-27 16:34   ` Nicolas Schier
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Schier @ 2025-12-27 16:34 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-arm-kernel, Masahiro Yamada, Chen-Yu Tsai,
	Thomas Weißschuh, J . Neuschäfer, Ahmad Fatoum,
	Tom Rini, David Sterba, Nick Terrell, linux-kernel

On Sat, Dec 27, 2025 at 07:21:49AM -0700, Simon Glass wrote:
> Add support for pbzip2, xz and plzip which can compress in parallel.
> This speeds up the ramdisk compression.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> (no changes since v7)
> 
> Changes in v7:
> - Mention xz as well, in the commit message
> 
>  scripts/make_fit.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable
  2025-12-27 14:21 ` [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable Simon Glass
@ 2025-12-27 16:36   ` Nicolas Schier
  2025-12-29 11:16   ` Thomas Weißschuh
  1 sibling, 0 replies; 10+ messages in thread
From: Nicolas Schier @ 2025-12-27 16:36 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-arm-kernel, Masahiro Yamada, Chen-Yu Tsai,
	Thomas Weißschuh, J . Neuschäfer, Ahmad Fatoum,
	Tom Rini, Alice Ryhl, Ard Biesheuvel, Ingo Molnar, Josh Poimboeuf,
	Kees Cook, Nathan Chancellor, Oleh Zadorozhnyi, Petr Mladek,
	linux-kbuild, linux-kernel

On Sat, Dec 27, 2025 at 07:21:48AM -0700, Simon Glass wrote:
> In some cases it is useful to be able to pass additional flags to the
> make_fit.py script. For example, since ramdisks are typically large,
> passing -E to use external data can be helpful.
> 
> Add a new MAKE_FIT_FLAGS variable for this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> (no changes since v7)
> 
> Changes in v7:
> - Add a new patch with the MAKE_FIT_FLAGS change
> 
>  scripts/Makefile.lib | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable
  2025-12-27 14:21 ` [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable Simon Glass
  2025-12-27 16:36   ` Nicolas Schier
@ 2025-12-29 11:16   ` Thomas Weißschuh
  1 sibling, 0 replies; 10+ messages in thread
From: Thomas Weißschuh @ 2025-12-29 11:16 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-arm-kernel, Masahiro Yamada, Chen-Yu Tsai, Nicolas Schier,
	J . Neuschäfer, Ahmad Fatoum, Tom Rini, Alice Ryhl,
	Ard Biesheuvel, Ingo Molnar, Josh Poimboeuf, Kees Cook,
	Nathan Chancellor, Nicolas Schier, Oleh Zadorozhnyi, Petr Mladek,
	linux-kbuild, linux-kernel

On Sat, Dec 27, 2025 at 07:21:48AM -0700, Simon Glass wrote:
> In some cases it is useful to be able to pass additional flags to the
> make_fit.py script. For example, since ramdisks are typically large,
> passing -E to use external data can be helpful.
> 
> Add a new MAKE_FIT_FLAGS variable for this.

The new variable's name is a bit inconsistent with the other ones.
I would have used `FIT_EXTRA_ARGUMENTS` or such.

> Signed-off-by: Simon Glass <sjg@chromium.org>

In any case:
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-12-29 11:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-27 14:21 [PATCH v8 0/6] scripts/make_fit: Support ramdisks and faster operations Simon Glass
2025-12-27 14:21 ` [PATCH v8 1/6] scripts/make_fit: Speed up operation Simon Glass
2025-12-27 14:21 ` [PATCH v8 2/6] scripts/make_fit: Support an initial ramdisk Simon Glass
2025-12-27 14:21 ` [PATCH v8 3/6] scripts/make_fit: Move dtb processing into a function Simon Glass
2025-12-27 14:21 ` [PATCH v8 4/6] kbuild: Support a MAKE_FIT_FLAGS environment variable Simon Glass
2025-12-27 16:36   ` Nicolas Schier
2025-12-29 11:16   ` Thomas Weißschuh
2025-12-27 14:21 ` [PATCH v8 5/6] scripts/make_fit: Support a few more parallel compressors Simon Glass
2025-12-27 16:34   ` Nicolas Schier
2025-12-27 14:21 ` [PATCH v8 6/6] scripts/make_fit: Compress dtbs in parallel Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).