From nobody Tue Dec 2 02:30:04 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 03A1831062C for ; Wed, 19 Nov 2025 18:14:26 +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=1763576089; cv=none; b=TDUEsV0sbaDvloqE/PYIcRUL4SLvCX7RpnLDppkUy53tcPoQ5xkQv3AHEQT0I52IpHCPfxgOpqCxk4kfwaq1FPcLwZzbQ0dtw1H9kghR4ScwEsIEqzfSA/2l+rjzwZy5uwC5zMzvlRWo9MCkdiqo083LO/N0FOy7hKkT+u+VgAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763576089; c=relaxed/simple; bh=a8gdpWOOLE5LiK7plSUbvBIWdhXzlJGSmDcnpnDBAF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ih7Xvb1e7e10ubul6QIjXOyEE3xeSgAijpKyWm+QU/WThItiFumVJtYuLtAOiObG7ohA9KdtO3SC4OvZzkC4/S+ceK3mVbusa6ch4iQiL32YSAkxB2kHYicqkIg+U2ZF6bGk6PO7ApD6VyAuMmbTw8rY7hMwJCNrurX+jQPEshI= 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=K59a6naT; 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="K59a6naT" Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-948f9b5987dso556439f.0 for ; Wed, 19 Nov 2025 10:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1763576063; x=1764180863; 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=dHy+9knFfat2mLLa5PVf4uFPqoXtGTRpTYZkU+z6PsU=; b=K59a6naTiKD0Y7zFpdqf0UN9+H8FJjIYT6nASIlY2e/zILICwd5AHKivwHVtR1geT+ 9KcGmRNrKfj/z8z1bZ3iyiOZTFQcVOvFkbXrl+wm2RCUCggsb2T+k1rJ98UnMI4MCb/v A6AxF+qHb6pRpa7KWiX9a2oDSa/Sd4EhywCwE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763576063; x=1764180863; 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=dHy+9knFfat2mLLa5PVf4uFPqoXtGTRpTYZkU+z6PsU=; b=NuYSXcVxygs0YD5qOIVtd+h4yfND7y2oBhfRu+0rD6+OvLcv3g2z13ORwxWatHOmLW Z6cKQGNDRGC79CRfpLDMyrajaayupK5lLSzIa1Ls5gUqCtTfSfdiS68x+LXcJocIezYz Szoz8oHpP+ApiUbhzwVA8QNXFXhrj9jUmgqZwRYIsRfj+/Re2kSnnVOi7x1RtGLcDXXE KSWEt1LDUL5XP5UrCBpKa40l31TkhKCBqDkNogPauHkufgpMW/dvSW7KEO9aD7TE36p6 VtfmYNIdaPxGFApfaNpZW68339jv0bkA55bUpLs1vxT9SYckGjJwAiAVX87iv98RuA+w VNqw== X-Forwarded-Encrypted: i=1; AJvYcCVUaCwhOKqry+x8/9yIzwKwq30iOJOIdlzgs8q6Gxj0fFKFBrM2XM/rau0KAJ/LE72AuNxECYyfbcWScPI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3zBtP0R/BwnDNqV6d0WFuRLXZOQnMsvkuaYKYI9haXxpJMG2Q XCowjVCqPs28SMd0pUgzYKbXGAMJd+pPkZQ9M1na0oolmsAFRAGOsbps2cepDJvtFA== X-Gm-Gg: ASbGncuOadHZmk6ZO7eyI5XDQ8mHVPrkiNlg96m/WBbjYkSHFLZisBpfPMNXhMG4A0f Tr7rdHchrUtLahb5R+1Xv2FZIybbZLY6fyTzmfHLJfUeTq3twbgxfSXuPdfi3RQTVfVwjj8qggM 0fBAXZ9MvKrXLIjqTdL9ztghSmEf1ScvQl3SxSVYRGCK0zxAzVCUIjNYbhVUIqQ6EERqHOIKaFW L4FBQWwPjbbyiv9MGTJ+rnliO5vJ80Mj5tRRBdSJmnWW/o6m4k3fYZaRF/51WZiifNZtqz3MUau K+5vm8OwBBQDeLY1/ue3AaHNY9XEP7F+WxEO0Zd9VZORdW0OStRoxcu/1CwzP0/HoBQGef/YL+E Sln3+04pegj+W4XTbUQiP2qLubHDG2E1IktBlLFMK5O4IjpmwPFyWWNoTFMt8qSKt+pkNrLUzm2 v76X3A X-Google-Smtp-Source: AGHT+IGaRIx4ZLtKiudNzXMDULOFDlM2zIQYOJnUxhKiqXGAH6TvITMlqEdCQfP7NTjCb2mlaYsLtg== X-Received: by 2002:a05:6602:2b84:b0:948:a3ca:15a3 with SMTP id ca18e2360f4ac-948e0deae37mr2850382839f.18.1763576063169; Wed, 19 Nov 2025 10:14:23 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 10:14:21 -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 , linux-kernel@vger.kernel.org Subject: [PATCH v6 8/8] scripts/make_fit: Compress dtbs in parallel Date: Wed, 19 Nov 2025 11:13:29 -0700 Message-ID: <20251119181333.991099-9-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" When there are 1500 device tree files it takes quite a while to compress them. Do it in parallel. 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 64038f17a51e..0a58b5b378b0 100755 --- a/scripts/make_fit.py +++ b/scripts/make_fit.py @@ -43,6 +43,7 @@ as U-Boot, Linuxboot, Tianocore, etc. =20 import argparse import collections +import multiprocessing import os import shutil import subprocess @@ -237,15 +238,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)) @@ -253,9 +270,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 find_gen_initramfs(): @@ -395,6 +413,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': @@ -406,11 +429,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