From nobody Tue Dec 2 02:30:06 2025 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 A168030DD22 for ; Wed, 19 Nov 2025 18:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763576064; cv=none; b=KdGAzTBRlEkCihEgKeSkrc3Nmow+OrnqBu4SkAET6qYjaWGYrr/WoMmfVslnQzAzL5DD7rEgjX2bw9wHEGwwXTOBgggsbYBn3+Cb6t2I8EwJYbNZ0j1QeLroTBLYWVwz6zoLSmVwQmqu/zzFvaWR8JzufT5/sRHLlpfu9GsqnOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763576064; c=relaxed/simple; bh=bIhJcMaNr2LuLFf95ViTv9PAdwNxqqzPJpRV+yf7Mgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i+HQpCpw5HVq+Y7J7myC0ZdeSyvgCRDCPWbsgAhivZh5iHNtJ1dFSOroBf4HdTFgFnufvodIAez+DX2OsOl42un7153P9tK3B90JiTZx/u6ZOKzSPSbtCA0NO81v7d4xcdEmNKrf2OO6oP2qdvlGhplwSUcmZPNDihRDup4yg70= 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=NP74OFrj; arc=none smtp.client-ip=209.85.166.49 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="NP74OFrj" Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-94880a46f3fso223670039f.2 for ; Wed, 19 Nov 2025 10:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1763576045; x=1764180845; 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=vGHNU0Y9qZ5AJfcI+Hz5PCDOOAK0uiMHY3/rFUZcMgQ=; b=NP74OFrjpknweEr1EM+zl1BAWDoKJiP3AtXNpnEUgbZOXs6BNJPE4By+KqzU9N1mXq fnQ/eFSlViVrAR0MtvJg5B3STdiywzS0YHKFNdRsMUS0G2xfslg/K7rigdiIKLULZsfo 2WO70hi0tIgkfSbPiQnWUHun7cbdHCHLVZtQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763576045; x=1764180845; 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=vGHNU0Y9qZ5AJfcI+Hz5PCDOOAK0uiMHY3/rFUZcMgQ=; b=uDL3xRVXnGPmCH6Rv+NjtDhxlZ8kjkH/hmU6HPras5KZrGKCiKcQG4WVPCPIhbLpD/ fC8XWfgk4Po1i6m2knK9dKUaYcHTs+HGXDMHazzOJp6QJxaiDPMQywY3YUHWWMxwWhhc m/Iu335Y3QuuuLbbn3XA8UK+9Ji4e2f/TprQLkhMFFX1+o/BPdqpO73bhZKnB/RQyYxA DDB+N7qg/cu9eUpBGHrjGMDfaYNbLp/l7j185UIMeaQOkebg1gZtLIp/lhr1ekc5Dl1P rHN8Pn4ftr5BeNlS/IQCvkqgCqcPpzXGApgWcArocXyjI9WlXPtlGwq+rwjsrVqp7uXW f+tw== X-Forwarded-Encrypted: i=1; AJvYcCV7PPtXdUvwvRW6aJyPXeg277Qds/Gg7EdJ+8y3IQ1qD4lAcbjs09e0i5ngibQTWPI20BJWKX2f2smXIMw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5HkH98hD44YzkNQt1fFxjiDaRv0dolGckS5r6Gopsa8/q6rVo nEN6wMVAxvVo0D7WzBarQo5I/mRkMf9EdKE8hcnm5PDJnzwtLULnWPEUlpiERkDCUw== X-Gm-Gg: ASbGncsoWheccz83BpF9/2pvQti9aQA+adY2gB3zfFmb7IlNY01Zz3qoiveQtVjyKcB irMdd1ypEsPRwhzYbfy3k+UMlCceGnVlRnNjpveWitnDw9rwzMoGEetCZR9oPM2SScuL6QtMDnH bBu0d0+9bZO8R9JG4sDXDE5XAMbg4FUQ8JVxodw85hoO+ugcAjhzLxXKdt3yfER24DdmgKVf4b+ EhGFkpwYaqp9f4gTnVbo4TWHAHjtNi8HDr4I5U2hkbvJYTmYbC7nZfu0eygytY4jA3WNgGqPxQX b0S9hqzfvW30hjhVRxr2e/XgJ5/+myn0L86lyZnyF+6kG5v1tHZuoQCvMSX4uz1H1+ALqn0ezX6 7TcHRIaW9YM48lf5uUhgJ6Yubjv0tY625OU1tunIz4La0NDioqc0wxSvUXmzU0OK3HyiLt8V2MX 1HksCov2hWxpZ/xu8= X-Google-Smtp-Source: AGHT+IFizsIKzcR3jkJP4zRDwTEP7H8DQprwvCzIj1bXPI84SnGAVfnAaADLyypxEJkbDennAkqXxw== X-Received: by 2002:a6b:4e19:0:b0:949:3623:dc25 with SMTP id ca18e2360f4ac-9493623efc5mr107582639f.13.1763576045401; Wed, 19 Nov 2025 10:14:05 -0800 (PST) Received: from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-949385ae254sm4838639f.1.2025.11.19.10.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 10:14:04 -0800 (PST) From: Simon Glass To: linux-arm-kernel@lists.infradead.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Masahiro Yamada , Tom Rini , Ahmad Fatoum , =?UTF-8?q?J=20=2E=20Neusch=C3=A4fer?= , Nicolas Schier , Chen-Yu Tsai , Simon Glass , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH v6 2/8] scripts/make_fit: Support an initial ramdisk Date: Wed, 19 Nov 2025 11:13:23 -0700 Message-ID: <20251119181333.991099-3-sjg@chromium.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251119181333.991099-1-sjg@chromium.org> References: <20251119181333.991099-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 Reviewed-by: Ahmad Fatoum --- (no changes since v5) 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