public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts/make_fit: Support an initial ramdisk
@ 2025-09-19 21:09 Simon Glass
  2025-09-19 21:09 ` [PATCH 2/2] scripts/make_fit: Speed up operation Simon Glass
  2025-09-22  7:14 ` [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Ahmad Fatoum
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Glass @ 2025-09-19 21:09 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Chen-Yu Tsai, J . Neuschäfer, Masahiro Yamada, Tom Rini,
	Nicolas Schier, Ahmad Fatoum, Simon Glass, linux-kernel

FIT (Flat Image Tree) allows an 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.

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

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

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 1683e5ec6e67..c43fd9d60809 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -10,10 +10,12 @@
 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 -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 +31,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 +81,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 +135,30 @@ 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'
+            compress: Compression algorithm to use, e.g. 'gzip'
+    """
+    with fsw.add_node('ramdisk'):
+        fsw.property_string('description', 'Ramdisk')
+        fsw.property_string('type', 'ramdisk')
+        fsw.property_string('arch', args.arch)
+        fsw.property_string('os', args.os)
+        fsw.property_string('compression', args.compress)
+        fsw.property('data', data)
+        fsw.property_u32('load', 0)
+
+
+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,13 @@ def build_fit(args):
     size += os.path.getsize(args.kernel)
     write_kernel(fsw, comp_data, args)
 
+    # Handle the ramdisk if provided
+    if args.ramdisk:
+        with open(args.ramdisk, 'rb') as inf:
+            comp_data = compress_data(inf, args.compress)
+        size += os.path.getsize(args.ramdisk)
+        write_ramdisk(fsw, comp_data, args)
+
     for fname in args.dtbs:
         # Ignore non-DTB (*.dtb) files
         if os.path.splitext(fname)[1] != '.dtb':
-- 
2.43.0

base-commit: 846bd2225ec3cfa8be046655e02b9457ed41973e
branch: fit


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

* [PATCH 2/2] scripts/make_fit: Speed up operation
  2025-09-19 21:09 [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Simon Glass
@ 2025-09-19 21:09 ` Simon Glass
  2025-09-22  7:14 ` [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Ahmad Fatoum
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Glass @ 2025-09-19 21:09 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Chen-Yu Tsai, J . Neuschäfer, Masahiro Yamada, Tom Rini,
	Nicolas Schier, Ahmad Fatoum, Simon Glass, 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>

---

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

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index c43fd9d60809..a8ea41fdaf08 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -100,7 +100,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')
@@ -331,10 +331,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
-    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

base-commit: 846bd2225ec3cfa8be046655e02b9457ed41973e
branch: fit


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

* Re: [PATCH 1/2] scripts/make_fit: Support an initial ramdisk
  2025-09-19 21:09 [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Simon Glass
  2025-09-19 21:09 ` [PATCH 2/2] scripts/make_fit: Speed up operation Simon Glass
@ 2025-09-22  7:14 ` Ahmad Fatoum
  2025-09-22 13:58   ` Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Ahmad Fatoum @ 2025-09-22  7:14 UTC (permalink / raw)
  To: Simon Glass, linux-arm-kernel
  Cc: Chen-Yu Tsai, J . Neuschäfer, Masahiro Yamada, Tom Rini,
	linux-kernel, Pengutronix Kernel Team

Hello Simon,

On 19.09.25 23:09, Simon Glass wrote:
> FIT (Flat Image Tree) allows an 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.

AFAIK the kernel supports multiple concatenated separately compressed
initramfs just fine, so it may still be useful to add a target which
builds a cpio with all modules inside and the rest can be then
concatenated.

What do you think?

> +        fsw.property_string('compression', args.compress)

compression should be none as the kernel would take of decompression.

Both U-Boot and barebox should warn about ramdisk compression property
that is != "none".

Cheers,
Ahmad

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


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

* Re: [PATCH 1/2] scripts/make_fit: Support an initial ramdisk
  2025-09-22  7:14 ` [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Ahmad Fatoum
@ 2025-09-22 13:58   ` Tom Rini
  2025-09-22 22:49     ` Simon Glass
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Rini @ 2025-09-22 13:58 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Simon Glass, linux-arm-kernel, Chen-Yu Tsai, J . Neuschäfer,
	Masahiro Yamada, linux-kernel, Pengutronix Kernel Team

[-- Attachment #1: Type: text/plain, Size: 2284 bytes --]

On Mon, Sep 22, 2025 at 09:14:55AM +0200, Ahmad Fatoum wrote:
> Hello Simon,
> 
> On 19.09.25 23:09, Simon Glass wrote:
> > FIT (Flat Image Tree) allows an 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.
> 
> AFAIK the kernel supports multiple concatenated separately compressed
> initramfs just fine, so it may still be useful to add a target which
> builds a cpio with all modules inside and the rest can be then
> concatenated.
> 
> What do you think?
> 
> > +        fsw.property_string('compression', args.compress)
> 
> compression should be none as the kernel would take of decompression.
> 
> Both U-Boot and barebox should warn about ramdisk compression property
> that is != "none".

Agreed. In U-Boot we've been handling this correctly since:

commit bddd985734653c366c8da073650930fb2e9b5003
Author: Julius Werner <jwerner@chromium.org>
Date:   Fri Aug 2 15:52:28 2019 -0700

    fit: Do not automatically decompress ramdisk images
    
    The Linux ramdisk should always be decompressed by the kernel itself,
    not by U-Boot. Therefore, the 'compression' node in the FIT image should
    always be set to "none" for ramdisk images, since the only point of
    using that node is if you want U-Boot to do the decompression itself.
    
    Yet some systems populate the node to the compression algorithm used by
    the kernel instead. This used to be ignored, but now that we support
    decompression of all image types it becomes a problem. Since ramdisks
    should never be decompressed by U-Boot anyway, this patch adds a special
    exception for them to avoid these issues. Still, setting the
    'compression' node like that is wrong in the first place, so we still
    want to print out a warning so that third-party distributions doing this
    can notice and fix it.
    
    Signed-off-by: Julius Werner <jwerner@chromium.org>
    Reviewed-by: Heiko Schocher <hs@denx.de>
    Tested-by: Heiko Schocher <hs@denx.de>
    Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 1/2] scripts/make_fit: Support an initial ramdisk
  2025-09-22 13:58   ` Tom Rini
@ 2025-09-22 22:49     ` Simon Glass
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2025-09-22 22:49 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ahmad Fatoum, linux-arm-kernel, Chen-Yu Tsai, J . Neuschäfer,
	Masahiro Yamada, linux-kernel, Pengutronix Kernel Team

Hi Tom,

On Mon, 22 Sept 2025 at 07:58, Tom Rini <trini@konsulko.com> wrote:
>
> On Mon, Sep 22, 2025 at 09:14:55AM +0200, Ahmad Fatoum wrote:
> > Hello Simon,
> >
> > On 19.09.25 23:09, Simon Glass wrote:
> > > FIT (Flat Image Tree) allows an 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.
> >
> > AFAIK the kernel supports multiple concatenated separately compressed
> > initramfs just fine, so it may still be useful to add a target which
> > builds a cpio with all modules inside and the rest can be then
> > concatenated.

OK I will have a try.

> >
> > What do you think?
> >
> > > +        fsw.property_string('compression', args.compress)
> >
> > compression should be none as the kernel would take of decompression.
> >
> > Both U-Boot and barebox should warn about ramdisk compression property
> > that is != "none".
>
> Agreed. In U-Boot we've been handling this correctly since:

Yes, I sent a v2 with that. But I'll send a v3 with the cpio idea.

>
> commit bddd985734653c366c8da073650930fb2e9b5003
> Author: Julius Werner <jwerner@chromium.org>
> Date:   Fri Aug 2 15:52:28 2019 -0700
>
>     fit: Do not automatically decompress ramdisk images
>
>     The Linux ramdisk should always be decompressed by the kernel itself,
>     not by U-Boot. Therefore, the 'compression' node in the FIT image should
>     always be set to "none" for ramdisk images, since the only point of
>     using that node is if you want U-Boot to do the decompression itself.
>
>     Yet some systems populate the node to the compression algorithm used by
>     the kernel instead. This used to be ignored, but now that we support
>     decompression of all image types it becomes a problem. Since ramdisks
>     should never be decompressed by U-Boot anyway, this patch adds a special
>     exception for them to avoid these issues. Still, setting the
>     'compression' node like that is wrong in the first place, so we still
>     want to print out a warning so that third-party distributions doing this
>     can notice and fix it.
>
>     Signed-off-by: Julius Werner <jwerner@chromium.org>
>     Reviewed-by: Heiko Schocher <hs@denx.de>
>     Tested-by: Heiko Schocher <hs@denx.de>
>     Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
>
> --
> Tom

Regards,
Simon


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

end of thread, other threads:[~2025-09-22 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19 21:09 [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Simon Glass
2025-09-19 21:09 ` [PATCH 2/2] scripts/make_fit: Speed up operation Simon Glass
2025-09-22  7:14 ` [PATCH 1/2] scripts/make_fit: Support an initial ramdisk Ahmad Fatoum
2025-09-22 13:58   ` Tom Rini
2025-09-22 22:49     ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox