From nobody Mon Feb 9 16:33:21 2026 Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49248326D51 for ; Fri, 14 Nov 2025 14:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763130488; cv=none; b=G043EAAWvdqqvq75JURFPMWUSE/xMt2/VZSnn/3JKKTeC9icGXiFN9/4FUQS60HAFFWDwsgaoJ/9/KEu17c12HfjVPKV2x5BI88abfj4+rxMm9iulULuAJUay4sbM03sgmMaSJWdZxDqEj6VYiS07SB1arq5saPhzoSWFMNHQEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763130488; c=relaxed/simple; bh=w8LHtzEq1PNAXKD5/lQkltdJlt5cI5xPZVrdBhE0b0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JEqGKAIj4OM0mIyd/Cao/QOvoHIV9kDAanAddf7RECGq/qiodgYpbA8oebkMJTBff7EgGgrzly7RA+eycb/1jdOSCsB5Ee+ksl09RudUH2+X11XsyvYzCz4D8TsKaK8DJmUdqZiYpVJX5Z+23tk0qeD5Wdiq3hCgg/yeHjpWKAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=hVWh1jEL; arc=none smtp.client-ip=209.85.166.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hVWh1jEL" Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-434709e7cc9so9991545ab.1 for ; Fri, 14 Nov 2025 06:28:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1763130485; x=1763735285; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SbwiEPUMKFzWHVRkANDWXLiE9C+Y1AwxTIo0xTKShXQ=; b=hVWh1jELsMk9IdS13E5PuSZx6zgDq6+hPOUwLkzRZTk4t4LdX1OLMZSxRw0WBdSPis R1zR1ZCv4M/srcV55tjTH2kKseUXckuhyUZIAUcuusiWM8Hw+qDonhlUIq4DfjA++y3R uohfT9BZQveSgZJUQD0Kieebqr99eCVEXRG9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763130485; x=1763735285; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SbwiEPUMKFzWHVRkANDWXLiE9C+Y1AwxTIo0xTKShXQ=; b=KHQAuqzDPGKPM7oWk6DxMek08GnqAxJb2ya+Sx/YPBGzz/lYzj2k2nxealLyE68/6r S5hprbFLQCxSiexzyEEq8SrLXhzD2jmSrxfkzu0rQqLUGGISxGZjBQbrd43UIqLNX9+b ZA4Ks0XJ/1xn46kgavkvXC6F7iOe4JBZoZUideLb5gY6yr3QhDEgVgcGm9AjRv+ZOpPX OHVa0jR7UDAr6yCdcF2SWBnLfLjEqFXUyoW+fWJY3V4OUTLQKjSKhmE5UsimXvRlNi3q u6PGVdF7rqc/sCKgJswhr+7nqtn3uPkY7F6IgeUj90ylKFUSjJFeap0nnFOYI72ZsYPc 2bZw== X-Forwarded-Encrypted: i=1; AJvYcCVMt8zNL/Mu9WGy8ETC2HCdGI9T3WW0Ws3La/uIaAhI9ng5TBWWJ8jn0Nsy/uNzvEGuCYj+wu8yU3r8oJs=@vger.kernel.org X-Gm-Message-State: AOJu0YzGOXjUIZIgCRvIqGvohPP+ZBxP2+yOX+Xkzk4oQ859cAErHSsB gwfhtwpb0uk0GYaMlo5HZVta49AQKiLv0hnDyxn3C9EkXcjs2cu6xKjj5k37f7vEkA== X-Gm-Gg: ASbGnctCakW5KJ/lW6m+iVlI9Qx1RrzlfMU225wNC8jM9lBHTrnI4LOS2tMt9V+0hge vcH9z2Gf+Me49RBwSz5C1vBd+1QczA4XI2TklCZ2Ji4/GFrD4ebBYS9CfXbzY8tXP/QtEBSRvQe gmpDlJzsKAtFlnfYiSP6jCRSN2uUqR4IqsfL7YTlwoXOIFbRzgg26ArHyn2okxo1b7ahH2w16E7 VOUTDtQVPy/ppFb5XjiAFJW+0UNtgRykxbFiLmlvU456bPA/vnPA4/8GKYkgISQK6yaWRfc/fZU B3HqQx6TXps3gbtFST2NU8/b1uMkCuObRp3HgLwZUvu9x/1CaxaNOIk+f0sLlDDI3AAPOfiqM+s 9jNn8vGYhMyTc2t3tbQpJVN55+5zAd1u+opa7PZPJvpnWXKPO+vcxx50K9C+Iq52UmnJUsF3OQz QOZfwP X-Google-Smtp-Source: AGHT+IGsFSLfQsHTQySP1q0sttqWWUuCQB9YY1khd7e5giMT7AMOylsJY1uQiJSgSiyY72LImJOkkQ== X-Received: by 2002:a05:6e02:3090:b0:433:7a94:6fcc with SMTP id e9e14a558f8ab-4348c8503camr48779555ab.2.1763130485241; Fri, 14 Nov 2025 06:28:05 -0800 (PST) Received: from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-434839cdb10sm27500205ab.32.2025.11.14.06.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 06:28:04 -0800 (PST) From: Simon Glass To: linux-arm-kernel@lists.infradead.org Cc: Nicolas Schier , Masahiro Yamada , Chen-Yu Tsai , Tom Rini , Ahmad Fatoum , =?UTF-8?q?J=20=2E=20Neusch=C3=A4fer?= , Simon Glass , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH v5 2/8] scripts/make_fit: Support an initial ramdisk Date: Fri, 14 Nov 2025 07:27:28 -0700 Message-ID: <20251114142741.1919072-3-sjg@chromium.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251114142741.1919072-1-sjg@chromium.org> References: <20251114142741.1919072-1-sjg@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. A later patch in this series provides 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 Reviewed-by: Nicolas Schier --- 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..984371f505bc 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-li= st + -E -c gzip =20 -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 s= et of +devicetree files, either specified individually or listed in a file (with = an +'@' prefix). + +Use -r to specify an existing ramdisk/initrd file. =20 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. =20 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. """ =20 import argparse @@ -81,6 +83,8 @@ def parse_args(): help=3D'Specifies the operating system') parser.add_argument('-k', '--kernel', type=3Dstr, required=3DTrue, help=3D'Specifies the (uncompressed) kernel input file (.itk)') + parser.add_argument('-r', '--ramdisk', type=3Dstr, + help=3D'Specifies the ramdisk/initrd input file') parser.add_argument('-v', '--verbose', action=3D'store_true', help=3D'Enable verbose output') parser.add_argument('dtbs', type=3Dstr, nargs=3D'*', @@ -133,7 +137,28 @@ def write_kernel(fsw, data, args): fsw.property_u32('entry', 0) =20 =20 -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('os', args.os) + fsw.property('data', data) + fsw.property_u32('load', 0) + + +def finish_fit(fsw, entries, has_ramdisk=3DFalse): """Finish the FIT ready for use =20 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 =3D 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() =20 =20 @@ -274,6 +302,14 @@ def build_fit(args): size +=3D os.path.getsize(args.kernel) write_kernel(fsw, comp_data, args) =20 + # 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 =3D inf.read() + size +=3D len(data) + write_ramdisk(fsw, data, args) + for fname in args.dtbs: # Ignore non-DTB (*.dtb) files if os.path.splitext(fname)[1] !=3D '.dtb': @@ -296,12 +332,12 @@ def build_fit(args): =20 entries.append([model, compat, files_seq]) =20 - finish_fit(fsw, entries) + finish_fit(fsw, entries, bool(args.ramdisk)) =20 # Include the kernel itself in the returned file count fdt =3D fsw.as_fdt() fdt.pack() - return fdt.as_bytearray(), seq + 1, size + return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size =20 =20 def run_make_fit(): --=20 2.43.0