From nobody Wed Dec 17 00:15:46 2025 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 865C82C15A8 for ; Thu, 11 Dec 2025 14:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765461827; cv=none; b=QqZPmv1UDV9HsDUovb3LDz+4ibaAKXdu3BdbChnAeFr0LMgOJ0KroOK0oqkN2Cfi59fzuQ1OK/sKSD64EgO+9gX4BXPDolpXiACifTq34Y6+aLHVj96F1byhj4YoamdxtBdXpDTMaS0927zklA1ZpWmE/UabqHMcERdcDI7XRZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765461827; c=relaxed/simple; bh=JDHwg4UH314RvplNCRL91Oy7GIV8cCK8/8DcmuuMJd8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ej8iJT8inPpJWml+Wz+kLu/1JbYZbCzgIX5XAxAo4aWmJn1dJUF/+1Lk/TBwt03kYGreG0mzT9zyt6U/OdvOTMTpXqyap2aQd5bK45n74FbyBQiq1x5TW+4HxMVzakqvTPVyu0mBmggHVj0eTGKBBnyEI4GZajcMSq7MsUXUhT0= 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=ZLu7tJM7; arc=none smtp.client-ip=209.85.167.181 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="ZLu7tJM7" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-4503ee5c160so51600b6e.1 for ; Thu, 11 Dec 2025 06:03:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1765461824; x=1766066624; 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=uf5OzsvzLJF7JMEHMJOMsmKpYuDb1ZnOHsvKTOsoYw0=; b=ZLu7tJM7NeakSp9xvG0cVTMYjCcB/AKRHwB00GMsnc1mkvgH0gXT24ysLzTi+IM7j6 lFp7wx1Pr1b8nn0vNhENkYylrqUd3JlVSJNgARAXGQoX82w4ps40U0wDn9lgzZq7Cge3 3J7nPRclaoTokteoyMAIouc4f2z2UqhfIEXVQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765461824; x=1766066624; 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=uf5OzsvzLJF7JMEHMJOMsmKpYuDb1ZnOHsvKTOsoYw0=; b=vWuCHj84ukq41DbU2nnkW7gz2K8+sj72eWnpegzIISggDdpOvL1ND4hT/nf42hRgoE QubDqOpAGJVZLTDQNvn6NCvSANbu1/NGd1LmYqjb5TfnLGY3dQN5iL+8ew1BV1Og4Z8j eclq9C9NCf663DcgWnR+HdW2AFjbeKyFSsT3N7eAAZi0IIhHhVfB/S/8t0JGB1LDVfxi orncjlRGuejiercY16T2wRyGLbV5COE6aOu44j7i24f1Zzj+w6b0825V1M7TFALygVaw DyRkA6siOkJ78vi71H3Jk+ARNxA3QvdNjhCuR5imxRdUgxqJnxj8gKWLSctfeGMzYIXS cFaw== X-Forwarded-Encrypted: i=1; AJvYcCVJuKua+c+UQdrsJkBkP2p6l5YbqKlOCREnc7f53s+eyJvLefiCiWCxvMFhVmjzvUgTGZyTcOioWy3AiyA=@vger.kernel.org X-Gm-Message-State: AOJu0YzBW7FrvvLePNmb2NANd70nhHUzNR/0TkUQbEF2VBqMnACVytzQ 1drxjiu20sHTcDJt7m2XTBnAZldCnaSHa7G10gSSJvAvKIWV/LpwWwEVrRqiOlF6Fg== X-Gm-Gg: AY/fxX6A8G7NvYa+piogLxiIcE/NtI57rHIMa1eLoolqfaZt0Q8oCliW8MfokA4Krr5 jJHypFajp4h7yAg3mZgbogr0AyIcnEBOvJHRWpdcsZ9ewhzBE+vumU/+H4GeAFBVu4ZN6AL+P/s fAIawbb4CZYgh1EaF/3FAhUIsdCqx/wWB5UleUvSkJSIY0wIj3GsLKovR3gwS3+TUfU6SVfV0Rj aHmnKC7TFichCDboypGXr1aWyCt/TY38OELMv486/ygGZPlqCgdAURmkD4GY98TlibOpBc8Gh5M SQ02FA246yDqKueu1dJILhj/aTFu+T8zQwSg/2ACF1uRP5KZXBdQ/zt6y1fvLMilDTMKaZDaNaB f9DENqR0Zewdso8Be8dyb+EZtCfnpi13gGBXptwLysA0/w2fElC585+wjWTRAYnM6NvEWp+NQQR wey74V X-Google-Smtp-Source: AGHT+IGAhfe/8+QVBKrlzKF3W05U1ybOZGuxX3rXL5y843UymGBcnVJuY3dUEiFiCqu+eUImkPT9HA== X-Received: by 2002:a05:6808:1507:b0:450:d3af:ba4c with SMTP id 5614622812f47-45586723052mr3049979b6e.52.1765461823858; Thu, 11 Dec 2025 06:03:43 -0800 (PST) Received: from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id 5614622812f47-45598d6e789sm1130030b6e.22.2025.12.11.06.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:03:43 -0800 (PST) From: Simon Glass To: linux-arm-kernel@lists.infradead.org Cc: Nicolas Schier , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , =?UTF-8?q?J=20=2E=20Neusch=C3=A4fer?= , Masahiro Yamada , Tom Rini , Ahmad Fatoum , Chen-Yu Tsai , Simon Glass , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH v7 2/6] scripts/make_fit: Support an initial ramdisk Date: Thu, 11 Dec 2025 07:02:59 -0700 Message-ID: <20251211140309.1910613-3-sjg@chromium.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251211140309.1910613-1-sjg@chromium.org> References: <20251211140309.1910613-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. 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 Reviewed-by: Nicolas Schier Reviewed-by: Ahmad Fatoum --- (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-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('compression', 'none') + fsw.property_string('os', args.os) + fsw.property('data', data) + + +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