Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Simon Glass and committed by
Nathan Chancellor
26428e7d 621fd65a

+44 -8
+44 -8
scripts/make_fit.py
··· 10 10 Usage: 11 11 make_fit.py -A arm64 -n 'Linux-6.6' -O linux 12 12 -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 14 15 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. 17 21 18 22 Use -E to generate an external FIT (where the data is placed after the 19 23 FIT data structure). This allows parsing of the data without loading ··· 33 29 34 30 The resulting FIT can be booted by bootloaders which support FIT, such 35 31 as U-Boot, Linuxboot, Tianocore, etc. 36 - 37 - Note that this tool does not yet support adding a ramdisk / initrd. 38 32 """ 39 33 40 34 import argparse ··· 83 81 help='Specifies the operating system') 84 82 parser.add_argument('-k', '--kernel', type=str, required=True, 85 83 help='Specifies the (uncompressed) kernel input file (.itk)') 84 + parser.add_argument('-r', '--ramdisk', type=str, 85 + help='Specifies the ramdisk/initrd input file') 86 86 parser.add_argument('-v', '--verbose', action='store_true', 87 87 help='Enable verbose output') 88 88 parser.add_argument('dtbs', type=str, nargs='*', ··· 137 133 fsw.property_u32('entry', 0) 138 134 139 135 140 - def finish_fit(fsw, entries): 136 + def write_ramdisk(fsw, data, args): 137 + """Write out the ramdisk image 138 + 139 + Writes a ramdisk node along with the required properties 140 + 141 + Args: 142 + fsw (libfdt.FdtSw): Object to use for writing 143 + data (bytes): Data to write (possibly compressed) 144 + args (Namespace): Contains necessary strings: 145 + arch: FIT architecture, e.g. 'arm64' 146 + fit_os: Operating Systems, e.g. 'linux' 147 + """ 148 + with fsw.add_node('ramdisk'): 149 + fsw.property_string('description', 'Ramdisk') 150 + fsw.property_string('type', 'ramdisk') 151 + fsw.property_string('arch', args.arch) 152 + fsw.property_string('compression', 'none') 153 + fsw.property_string('os', args.os) 154 + fsw.property('data', data) 155 + 156 + 157 + def finish_fit(fsw, entries, has_ramdisk=False): 141 158 """Finish the FIT ready for use 142 159 143 160 Writes the /configurations node and subnodes ··· 168 143 entries (list of tuple): List of configurations: 169 144 str: Description of model 170 145 str: Compatible stringlist 146 + has_ramdisk (bool): True if a ramdisk is included in the FIT 171 147 """ 172 148 fsw.end_node() 173 149 seq = 0 ··· 180 154 fsw.property_string('description', model) 181 155 fsw.property('fdt', bytes(''.join(f'fdt-{x}\x00' for x in files), "ascii")) 182 156 fsw.property_string('kernel', 'kernel') 157 + if has_ramdisk: 158 + fsw.property_string('ramdisk', 'ramdisk') 183 159 fsw.end_node() 184 160 185 161 ··· 302 274 size += os.path.getsize(args.kernel) 303 275 write_kernel(fsw, comp_data, args) 304 276 277 + # Handle the ramdisk if provided. Compression is not supported as it is 278 + # already compressed. 279 + if args.ramdisk: 280 + with open(args.ramdisk, 'rb') as inf: 281 + data = inf.read() 282 + size += len(data) 283 + write_ramdisk(fsw, data, args) 284 + 305 285 for fname in args.dtbs: 306 286 # Ignore non-DTB (*.dtb) files 307 287 if os.path.splitext(fname)[1] != '.dtb': ··· 332 296 333 297 entries.append([model, compat, files_seq]) 334 298 335 - finish_fit(fsw, entries) 299 + finish_fit(fsw, entries, bool(args.ramdisk)) 336 300 337 301 # Include the kernel itself in the returned file count 338 302 fdt = fsw.as_fdt() 339 303 fdt.pack() 340 - return fdt.as_bytearray(), seq + 1, size 304 + return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size 341 305 342 306 343 307 def run_make_fit():