From patchwork Sat Dec 17 21:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1716961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=X6IW2+b0; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NZJyJ4Lqnz240F for ; Sun, 18 Dec 2022 08:29:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A13885391; Sat, 17 Dec 2022 22:28:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="X6IW2+b0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 16E5A85395; Sat, 17 Dec 2022 22:28:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6161E85390 for ; Sat, 17 Dec 2022 22:28:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12d.google.com with SMTP id o8so3040017ilo.1 for ; Sat, 17 Dec 2022 13:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=eEF1l80COncM3W0eDa6+vYDUDxQ3QlqnH3Bcm5//Nv0=; b=X6IW2+b0cRFTkfDMxvn9oOhemKmuPJI5+R0o223qcwTpOecrUJ+WlUf/97yVo+B5xc l1wWHO8T7DxXlPHu+oUKLQYH/7WJhrIEjx7iFd5X/35xiS8VNDl4deFZvb0LhFm7gcH8 XGd8+GxjJkbeqmtYnLH280w6yTVTSJzyvz9+o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eEF1l80COncM3W0eDa6+vYDUDxQ3QlqnH3Bcm5//Nv0=; b=24F9cMn9VHKb8YUyynoBq4Oh76i69ginaKWl3ol9XOrftNLrHsod6QtZtZzIl37N2W Te5zK6SMgejrTUhxL6t4c2BFI82XVPwmgd58H6pdSsHXPmXxndIgOVAb+wEz/xPA/JR7 /0vp8mW97MLfkRT7VuEZVup+rvKzonzHhOB/x5CPmeZmrTCkhawhcYhz4DQVhqIrsg2s W1KpSty1nqpRNKKah7kSllA+R+j4X/7LrGPKCNDtanOt1WUexUp8sSnGKchSXiN0x3oR a79AsEtxWn9GNAjTaSWYC2JXJLLnT/CcAcTL/XfBO/h9MbGe3FYKexIJJlJBYsUCfJfd VXHw== X-Gm-Message-State: ANoB5pkv0eQ2xRMtQ0GdbWtKEel2xkxnNvr37Yu9YJki+TmGNY5yMe2g /uR4OxImZPJhSMlDbZctra7O8MXCDMyn0gKc X-Google-Smtp-Source: AA0mqf5TecjZIxqt7vNctqkuUbwqzFck0l+oG60HzK4Dyx3FnZNRX59kfTGihIN5ODg6YTIpYwQuDw== X-Received: by 2002:a05:6e02:806:b0:303:608d:b34d with SMTP id u6-20020a056e02080600b00303608db34dmr20274732ilm.18.1671312503732; Sat, 17 Dec 2022 13:28:23 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id e2-20020a02a502000000b00370decbbff3sm1949886jam.148.2022.12.17.13.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 13:28:23 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich , Peter Geis , Quentin Schulz , Alper Nebi Yasak , Ivan Mikhaylov , Philippe Reynes , Tom Rini , Jerome Forissier , Roger Quadros Subject: [PATCH v7 04/12] binman: Support optional entries Date: Sat, 17 Dec 2022 14:28:05 -0700 Message-Id: <20221217212813.89914-5-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221217212813.89914-1-sjg@chromium.org> References: <20221217212813.89914-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Support entries which can be optional depending on their contents. This allows special entry types which appear in the image only when needed. Signed-off-by: Simon Glass --- (no changes since v1) tools/binman/binman.rst | 22 ++++++++++++++++++++++ tools/binman/control.py | 1 + tools/binman/entry.py | 9 +++++++++ tools/binman/etype/_testing.py | 3 +++ tools/binman/etype/section.py | 7 +++++++ tools/binman/ftest.py | 5 +++++ tools/binman/test/262_absent.dts | 20 ++++++++++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 tools/binman/test/262_absent.dts diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index b091114fb91..1ab6d012b83 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -1012,6 +1012,28 @@ For the BSS case, a 'spl-bss-pad' entry arg controls whether it is present. All entry args are provided by the U-Boot Makefile. +Optional entries +---------------- + +Some entries need to exist only if certain conditions are met. For example, an +entry may want to appear in the image only if a file has a particular format. +Obviously the entry must exist in the image description for it to be processed +at all, so a way needs to be found to have the entry remove itself. + +To handle this, when entry.ObtainContents() is called, the entry can call +entry.mark_absent() to mark itself as absent, passing a suitable message as the +reason. + +Any absent entries are dropped immediately after ObtainContents() has been +called on all entries. + +It is not possible for an entry to mark itself absent at any other point in the +processing. It must happen in the ObtainContents() method. + +The effect is as if the entry had never been present at all, since the image +is packed without it and it disappears from the list of entries. + + Compression ----------- diff --git a/tools/binman/control.py b/tools/binman/control.py index 964c6984f9b..07225381146 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -552,6 +552,7 @@ def ProcessImage(image, update_fdt, write_map, get_contents=True, image.SetAllowMissing(allow_missing) image.SetAllowFakeBlob(allow_fake_blobs) image.GetEntryContents() + image.drop_absent() image.GetEntryOffsets() # We need to pack the entries to figure out where everything diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 1be31a05e00..637aece3705 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -91,6 +91,10 @@ class Entry(object): file, or is a binary file produced from an ELF file auto_write_symbols (bool): True to write ELF symbols into this entry's contents + absent (bool): True if this entry is absent. This can be controlled by + the entry itself, allowing it to vanish in certain circumstances. + An absent entry is removed during processing so that it does not + appear in the map """ fake_dir = None @@ -133,6 +137,7 @@ class Entry(object): self.comp_bintool = None self.elf_fname = None self.auto_write_symbols = auto_write_symbols + self.absent = False @staticmethod def FindEntryClass(etype, expanded): @@ -1281,3 +1286,7 @@ features to produce new behaviours. not_present.append(prop) if not_present: self.Raise(f"'{self.etype}' entry is missing properties: {' '.join(not_present)}") + + def mark_absent(self, msg): + tout.info("Entry '%s' marked absent: %s" % (self._node.path, msg)) + self.absent = True diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index 69600487814..1c1efb21a44 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -63,6 +63,7 @@ class Entry__testing(Entry): 'bad-update-contents-twice') self.return_contents_later = fdt_util.GetBool(self._node, 'return-contents-later') + self.set_to_absent = fdt_util.GetBool(self._node, 'set-to-absent') # Set to True when the entry is ready to process the FDT. self.process_fdt_ready = False @@ -119,6 +120,8 @@ class Entry__testing(Entry): if self.require_bintool_for_contents: if self.bintool_for_contents is None: self.Raise("Required bintool unusable in ObtainContents()") + if self.set_to_absent: + self.mark_absent('for testing purposes') return True def GetOffsets(self): diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 305155c8461..dcb7a062047 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -672,6 +672,9 @@ class Entry_section(Entry): def GetEntryContents(self, skip_entry=None): """Call ObtainContents() for each entry in the section + + Note that this may set entry.absent to True if the entry is not + actually needed """ def _CheckDone(entry): if entry != skip_entry: @@ -716,6 +719,10 @@ class Entry_section(Entry): todo) return True + def drop_absent(self): + """Drop entries which are absent""" + self._entries = {n: e for n, e in self._entries.items() if not e.absent} + def _SetEntryOffsetSize(self, name, offset, size): """Set the offset and size of an entry diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index c3cb32dca26..f47a745f1e1 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6090,6 +6090,11 @@ fdt fdtmap Extract the devicetree blob from the fdtmap sect_data = tools.read_file(sect_fname) self.assertEqual(U_BOOT_DATA, sect_data) + def testAbsent(self): + """Check handling of absent entries""" + data = self._DoReadFile('262_absent.dts') + self.assertEqual(U_BOOT_DATA + U_BOOT_IMG_DATA, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/262_absent.dts b/tools/binman/test/262_absent.dts new file mode 100644 index 00000000000..2ab8766c878 --- /dev/null +++ b/tools/binman/test/262_absent.dts @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + + _testing { + set-to-absent; + }; + + u-boot-img { + }; + }; +};