Skip to content

Commit 26428e7

Browse files
sjg20nathanchance
authored andcommitted
scripts/make_fit: Support an initial ramdisk
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> Link: https://patch.msgid.link/20260106162738.2605574-3-sjg@chromium.org Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 621fd65 commit 26428e7

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

scripts/make_fit.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
Usage:
1111
make_fit.py -A arm64 -n 'Linux-6.6' -O linux
1212
-o arch/arm64/boot/image.fit -k /tmp/kern/arch/arm64/boot/image.itk
13-
@arch/arm64/boot/dts/dtbs-list -E -c gzip
13+
-r /boot/initrd.img-6.14.0-27-generic @arch/arm64/boot/dts/dtbs-list
14+
-E -c gzip
1415
15-
Creates a FIT containing the supplied kernel and a set of devicetree files,
16-
either specified individually or listed in a file (with an '@' prefix).
16+
Creates a FIT containing the supplied kernel, an optional ramdisk, and a set of
17+
devicetree files, either specified individually or listed in a file (with an
18+
'@' prefix).
19+
20+
Use -r to specify an existing ramdisk/initrd file.
1721
1822
Use -E to generate an external FIT (where the data is placed after the
1923
FIT data structure). This allows parsing of the data without loading
@@ -29,8 +33,6 @@
2933
3034
The resulting FIT can be booted by bootloaders which support FIT, such
3135
as U-Boot, Linuxboot, Tianocore, etc.
32-
33-
Note that this tool does not yet support adding a ramdisk / initrd.
3436
"""
3537

3638
import argparse
@@ -81,6 +83,8 @@ def parse_args():
8183
help='Specifies the operating system')
8284
parser.add_argument('-k', '--kernel', type=str, required=True,
8385
help='Specifies the (uncompressed) kernel input file (.itk)')
86+
parser.add_argument('-r', '--ramdisk', type=str,
87+
help='Specifies the ramdisk/initrd input file')
8488
parser.add_argument('-v', '--verbose', action='store_true',
8589
help='Enable verbose output')
8690
parser.add_argument('dtbs', type=str, nargs='*',
@@ -133,7 +137,28 @@ def write_kernel(fsw, data, args):
133137
fsw.property_u32('entry', 0)
134138

135139

136-
def finish_fit(fsw, entries):
140+
def write_ramdisk(fsw, data, args):
141+
"""Write out the ramdisk image
142+
143+
Writes a ramdisk node along with the required properties
144+
145+
Args:
146+
fsw (libfdt.FdtSw): Object to use for writing
147+
data (bytes): Data to write (possibly compressed)
148+
args (Namespace): Contains necessary strings:
149+
arch: FIT architecture, e.g. 'arm64'
150+
fit_os: Operating Systems, e.g. 'linux'
151+
"""
152+
with fsw.add_node('ramdisk'):
153+
fsw.property_string('description', 'Ramdisk')
154+
fsw.property_string('type', 'ramdisk')
155+
fsw.property_string('arch', args.arch)
156+
fsw.property_string('compression', 'none')
157+
fsw.property_string('os', args.os)
158+
fsw.property('data', data)
159+
160+
161+
def finish_fit(fsw, entries, has_ramdisk=False):
137162
"""Finish the FIT ready for use
138163
139164
Writes the /configurations node and subnodes
@@ -143,6 +168,7 @@ def finish_fit(fsw, entries):
143168
entries (list of tuple): List of configurations:
144169
str: Description of model
145170
str: Compatible stringlist
171+
has_ramdisk (bool): True if a ramdisk is included in the FIT
146172
"""
147173
fsw.end_node()
148174
seq = 0
@@ -154,6 +180,8 @@ def finish_fit(fsw, entries):
154180
fsw.property_string('description', model)
155181
fsw.property('fdt', bytes(''.join(f'fdt-{x}\x00' for x in files), "ascii"))
156182
fsw.property_string('kernel', 'kernel')
183+
if has_ramdisk:
184+
fsw.property_string('ramdisk', 'ramdisk')
157185
fsw.end_node()
158186

159187

@@ -274,6 +302,14 @@ def build_fit(args):
274302
size += os.path.getsize(args.kernel)
275303
write_kernel(fsw, comp_data, args)
276304

305+
# Handle the ramdisk if provided. Compression is not supported as it is
306+
# already compressed.
307+
if args.ramdisk:
308+
with open(args.ramdisk, 'rb') as inf:
309+
data = inf.read()
310+
size += len(data)
311+
write_ramdisk(fsw, data, args)
312+
277313
for fname in args.dtbs:
278314
# Ignore non-DTB (*.dtb) files
279315
if os.path.splitext(fname)[1] != '.dtb':
@@ -296,12 +332,12 @@ def build_fit(args):
296332

297333
entries.append([model, compat, files_seq])
298334

299-
finish_fit(fsw, entries)
335+
finish_fit(fsw, entries, bool(args.ramdisk))
300336

301337
# Include the kernel itself in the returned file count
302338
fdt = fsw.as_fdt()
303339
fdt.pack()
304-
return fdt.as_bytearray(), seq + 1, size
340+
return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size
305341

306342

307343
def run_make_fit():

0 commit comments

Comments
 (0)