From nobody Wed Dec 17 00:15:45 2025 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 2E6752D0C62 for ; Thu, 11 Dec 2025 14:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765461836; cv=none; b=BHZMOoVC0lMbyeG5a+aVgaEFpQgnebWFe6IC7lmeDu9/GDLoS/TrRSSO94nW1tSi1yDJfqQHJPvlBgsEWXwgwN1eAQeA1UFl9wLk3ypaY3gAgk0dF1HUiWcLFA5G+eNWQmTDcNfT3PoGHEgAYWfC4pFxgGGXeXgUsG/i9nMQ+Qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765461836; c=relaxed/simple; bh=qFAoyq72kc1ep7bQhDi6ZfBb7dgniIZQAAK+V+ilCKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=geRILAjzBDHhYPL7TIvQAIM1N5976rmK74mib6IyLYrh40oAl1hBlQnvRmHI+Y/Y071aH79xM6kMpIM+E/V56JFzLRyMwnD18IcGzvykO4EjExVG+npJuyyLhC11SX/uWYAr7hS5alnboLN/RW42CSTUGSdL0glAtgc4/TpMrVA= 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=Wz0YYk65; arc=none smtp.client-ip=209.85.210.44 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="Wz0YYk65" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7c6d13986f8so109868a34.0 for ; Thu, 11 Dec 2025 06:03:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1765461834; x=1766066634; 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=YrEZrghrc2EX7rimqehQ8Km0GewP4FP/AwInEozlUrg=; b=Wz0YYk65B0tuvrtHUK2wf3/EBvDut8fnTfM/9T6g/1AnXQEinJBvrNA5E6OjlS1YY5 HNjMxnKXYcpgKvJSEokpXbz8EiqIgVMLh1taFOIpQOGuSMTlB0erVWMLPjtJYV8SwrCP Gzer7UCDycAtgKFlONhqmmEE87BzQNEc/wzsg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765461834; x=1766066634; 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=YrEZrghrc2EX7rimqehQ8Km0GewP4FP/AwInEozlUrg=; b=dUbtzOTrwXUDSoAwSE7tZFR8a7Tj2pNwCsOxyqxzD6cmrhMnf2FcNzBjgaIyHF45e9 M+fIwGlyEaNCpajnb6t3HjvdztPvHINWHw6ap2e/sLE8pmTH041mp1kIsyfhuz0CmGKu J2EEdKDnR1kTU5qq/ayjhjdtGMeD+G9DI5p2SQmCZQJ2W4mbhnd05qb4N23utSptFG70 yx2tezdfErSbKmIjnQfbPQVz0SdVBOxPLMBQ2SADTVGoOOZ7qn5Tc6cd6W4NYQqW/k5q 4UiLF4JPlpptDHR15u6JX9fwJbcp3/zKnMqc3TE58MupIGST2i7PS5VQK+BXpPj0teV4 fTwg== X-Forwarded-Encrypted: i=1; AJvYcCXEtutgq9RkTeK1LrbwWYwGQFRbZZZbH3vy7fJT92oV+EoDLzXR8kH88DipYepXwZKDt5MOyeODj5n9NZU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4ccgJTxKKsIWQ5pInq86OF6c1r5KURJYoXZcY0nHAPXGApVWL OVGoO+NOT1cEiopXyAucukwsIGtTWj6Zukzsfwh6/izr+V6qrcKL8i41j8yLoourzDkN0dMv8IT zKbg= X-Gm-Gg: AY/fxX6vchHb0AFWXXwK9kxnBuheTbz7Y7XQj9t2lacJMTlAYtBzUtGH3xf+VkGEdBJ MA/nancn+bBAHUsnJG03WZcEKJRG1gE1+RoWlpCJedvjOZxNfO7qTNEHtjH1GOlDXSu/QdsMyvB WslQyIraZEydgicVKpkNA65fNyogapGI2xcIeZ5iYse/odcRfUCHbMZgn6IAKHVPk7BSgD81Q+X 4ajN8kg55PArzs5GdzEG+lQ7q9rSfLpPV1pPKB3/YUAGW8Wco98rwZy5khIm91yGw4eTmYBFMte GUGIkAX1dgWZ21R2k4u0AQXW2OdFFahrmndtr8OrA/Vklob7rE6ZTM65wrgj6xw+DL/wcwBwmQ6 pTg7Nknf0zE7jb6vBu+oDqXdGHY9BM1ClkVGx/GcZTWzmdgt0WamULgElFP3g92VFciUAxgdadM /XxEVZ X-Google-Smtp-Source: AGHT+IGdhTYXa00yC9lHlR47tVgHZ0qHU5gLHDx5CEQuAyMBzVTh1Mkta8Jby7+utQw5FLyd4TFLDg== X-Received: by 2002:a05:6808:c2bf:b0:43f:68b:acb3 with SMTP id 5614622812f47-4559befdfa3mr681670b6e.17.1765461833902; Thu, 11 Dec 2025 06:03:53 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:03:52 -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 , linux-kernel@vger.kernel.org Subject: [PATCH v7 6/6] scripts/make_fit: Compress dtbs in parallel Date: Thu, 11 Dec 2025 07:03:03 -0700 Message-ID: <20251211140309.1910613-7-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" When there are 1500 device tree files it takes quite a while to compress them. Do it in parallel. kbuild: Allow adding modules into the FIT ramdisk Signed-off-by: Simon Glass --- (no changes since v1) scripts/make_fit.py | 56 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/scripts/make_fit.py b/scripts/make_fit.py index defb87f223d7..e923cc8b05b7 100755 --- a/scripts/make_fit.py +++ b/scripts/make_fit.py @@ -37,6 +37,7 @@ as U-Boot, Linuxboot, Tianocore, etc. =20 import argparse import collections +import multiprocessing import os import subprocess import sys @@ -225,15 +226,31 @@ def compress_data(inf, compress): return comp_data =20 =20 -def output_dtb(fsw, seq, fname, arch, compress): +def compress_dtb(fname, compress): + """Compress a single DTB file + + Args: + fname (str): Filename containing the DTB + compress (str): Compression algorithm, e.g. 'gzip' + + Returns: + tuple: (str: fname, bytes: compressed_data) + """ + with open(fname, 'rb') as inf: + compressed =3D compress_data(inf, compress) + return fname, compressed + + +def output_dtb(fsw, seq, fname, arch, compress, data=3DNone): """Write out a single devicetree to the FIT =20 Args: fsw (libfdt.FdtSw): Object to use for writing seq (int): Sequence number (1 for first) fname (str): Filename containing the DTB - arch: FIT architecture, e.g. 'arm64' + arch (str): FIT architecture, e.g. 'arm64' compress (str): Compressed algorithm, e.g. 'gzip' + data (bytes): Pre-compressed data (optional) """ with fsw.add_node(f'fdt-{seq}'): fsw.property_string('description', os.path.basename(fname)) @@ -241,9 +258,10 @@ def output_dtb(fsw, seq, fname, arch, compress): fsw.property_string('arch', arch) fsw.property_string('compression', compress) =20 - with open(fname, 'rb') as inf: - compressed =3D compress_data(inf, compress) - fsw.property('data', compressed) + if data is None: + with open(fname, 'rb') as inf: + data =3D compress_data(inf, compress) + fsw.property('data', data) =20 =20 def process_dtb(fname, args): @@ -300,6 +318,11 @@ def _process_dtbs(args, fsw, entries, fdts): """ seq =3D 0 size =3D 0 + + # First figure out the unique DTB files that need compression + todo =3D [] + file_info =3D [] # List of (fname, model, compat, files) tuples + for fname in args.dtbs: # Ignore non-DTB (*.dtb) files if os.path.splitext(fname)[1] !=3D '.dtb': @@ -311,11 +334,32 @@ def _process_dtbs(args, fsw, entries, fdts): sys.stderr.write(f'Error processing {fname}:\n') raise e =20 + file_info.append((fname, model, compat, files)) + for fn in files: + if fn not in fdts and fn not in todo: + todo.append(fn) + + # Compress all DTBs in parallel + cache =3D {} + if todo and args.compress !=3D 'none': + if args.verbose: + print(f'Compressing {len(todo)} DTBs...') + + with multiprocessing.Pool() as pool: + compress_args =3D [(fn, args.compress) for fn in todo] + # unpacks each tuple, calls compress_dtb(fn, compress) in para= llel + results =3D pool.starmap(compress_dtb, compress_args) + + cache =3D dict(results) + + # Now write all DTBs to the FIT using pre-compressed data + for fname, model, compat, files in file_info: for fn in files: if fn not in fdts: seq +=3D 1 size +=3D os.path.getsize(fn) - output_dtb(fsw, seq, fn, args.arch, args.compress) + output_dtb(fsw, seq, fn, args.arch, args.compress, + cache.get(fn)) fdts[fn] =3D seq =20 files_seq =3D [fdts[fn] for fn in files] --=20 2.43.0