From patchwork Sun Mar 27 15:31:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609895 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qHUEQDka; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKZp4j66z9sBJ for ; Mon, 28 Mar 2022 02:32:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A9FC68394E; Sun, 27 Mar 2022 17:32:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qHUEQDka"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D6A8583937; Sun, 27 Mar 2022 17:32:12 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 1FA6A83919 for ; Sun, 27 Mar 2022 17:32:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x62a.google.com with SMTP id r13so23973780ejd.5 for ; Sun, 27 Mar 2022 08:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wqc9BIw+9InuFUKR233B49RU2i4BJUydgQOjGqEwg08=; b=qHUEQDkauAO+IKh1v1/nO7AUsMdm5NMcbuu2IclM6d30LUKhLqbEVguM+l63RRp/Rf Tv7YoASxZ5qA6oqTVm3AlEnhV2t6D1SZQ8vYOXTo0RdTjY5PKjgdudvVspbQSiNJXIsW InHCQzHHTITuDg5jAZ37O9Lu1/hy7OoVcR6LP62jqIM/SFI2/ynXb2byaNMQz1AwkkH+ gJ9ufpxIQjqhw6gLI4htohwakG/YNid8aTbTyAOSO3lRTvoMGeoeWfFPjRI7Fgj6Kk5H F6iHU4PqZig8qjEzIr0JcS4LvKcF6nAtZCICtdubqgJfSlUm1BPMtGW8anveWCZj6Fey 2dhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wqc9BIw+9InuFUKR233B49RU2i4BJUydgQOjGqEwg08=; b=dteOZwnAfzLoRcHRo+EXzQ0m+PNL8VQneJaH/Y68i6CchJeoTU9gooGhXDw6iJwjvV JX0kZhlhO7Oovgdq0KdfkOC+rUdzMWL+4uAhYacJ7dEnfPm7qgVv0BIyc0/f84xNuGZL DAjv+NEXu0y38501vYuCgfiMqKlTN68b4Nj/1kaGD3/FgK5kIiPYm5uew3IAonhu9Ah7 ibwhmW1Arltrb7wjxFL50qMb9rv+A1K9qfgkMGZ0yayDwRSgq4GAJD+gsPlP4NeySkLW 9aJXx2vw+Hh3uluU2OBgsX32EiOeXPuTm7POikBybrPg6JYq7ujkNGvp1x/i8x9e8rpC eu3A== X-Gm-Message-State: AOAM530UlsiIr4tekCYLeiQxsY5OX924h8NW7HxZ8u6SZ4zNk2MFnAS1 g1AFZ182tFtQT32GHJl4bKKs4fSAKwI= X-Google-Smtp-Source: ABdhPJw7vHKvtNnkHtM8Plco9pwCsZJDFbRYswpLX9brpHQBaDnfyQuZ0Ts8e96RuWrzMPxnn/86Jg== X-Received: by 2002:a17:906:7304:b0:6e0:6918:ef6f with SMTP id di4-20020a170906730400b006e06918ef6fmr22272362ejc.370.1648395128746; Sun, 27 Mar 2022 08:32:08 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:08 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 1/7] binman: Fix unique names having '/.' for images read from files Date: Sun, 27 Mar 2022 18:31:44 +0300 Message-Id: <20220327153151.15912-2-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean Binman can embed a copy of the image description into the images it builds as a fdtmap entry, but it omits the /binman/ prefix from the node paths while doing so. When reading an already-built image file, entries are reconstructed using this fdtmap and their associated nodes still lack that prefix. Some entries like fit and vblock create intermediate files whose names are based on an entry unique name. This name is constructed from their node's path by concatenating the parents with dots up to the binman node, e.g. /binman/image/foo/bar becomes 'image.foo.bar'. However, we don't have this /binman/image prefix when replacing entries in such an image. The /foo/bar entry we read when doing so erroneously has the unique name of '/.foo.bar', causing permission errors when the entry attempts to create files based on that. Fix the unique-name generation by stopping at the '/' node like how it stops at the binman node. As the unique names are used as filenames, add tests that check if they're safe to use as filenames. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/entry.py | 2 +- tools/binman/ftest.py | 31 ++++++++++++++++ tools/binman/test/230_unique_names.dts | 34 ++++++++++++++++++ tools/binman/test/231_unique_names_multi.dts | 38 ++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/230_unique_names.dts create mode 100644 tools/binman/test/231_unique_names_multi.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 18a7a3510548..a07a5888643a 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -775,7 +775,7 @@ def GetUniqueName(self): node = self._node while node.parent: node = node.parent - if node.name == 'binman': + if node.name in ('binman', '/'): break name = '%s.%s' % (node.name, name) return name diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 876953f11324..e6f0159a229f 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5471,6 +5471,37 @@ def testFitSplitElfFaked(self): err, "Image '.*' is missing external blobs and is non-functional: .*") + def _CheckSafeUniqueNames(self, *images): + """Check all entries of given images for unsafe unique names""" + for image in images: + entries = {} + image._CollectEntries(entries, {}, image) + for entry in entries.values(): + uniq = entry.GetUniqueName() + + # Used as part of a filename, so must not be absolute paths. + self.assertFalse(os.path.isabs(uniq)) + + def testSafeUniqueNames(self): + """Test entry unique names are safe in single image configuration""" + data = self._DoReadFileRealDtb('230_unique_names.dts') + + orig_image = control.images['image'] + image_fname = tools.get_output_filename('image.bin') + image = Image.FromFile(image_fname) + + self._CheckSafeUniqueNames(orig_image, image) + + def testSafeUniqueNamesMulti(self): + """Test entry unique names are safe with multiple images""" + data = self._DoReadFileRealDtb('231_unique_names_multi.dts') + + orig_image = control.images['image'] + image_fname = tools.get_output_filename('image.bin') + image = Image.FromFile(image_fname) + + self._CheckSafeUniqueNames(orig_image, image) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/230_unique_names.dts b/tools/binman/test/230_unique_names.dts new file mode 100644 index 000000000000..6780d37f71f4 --- /dev/null +++ b/tools/binman/test/230_unique_names.dts @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + allow-repack; + + u-boot { + }; + + fdtmap { + }; + + u-boot2 { + type = "u-boot"; + }; + + text { + text = "some text"; + }; + + u-boot-dtb { + }; + + image-header { + location = "end"; + }; + }; +}; diff --git a/tools/binman/test/231_unique_names_multi.dts b/tools/binman/test/231_unique_names_multi.dts new file mode 100644 index 000000000000..db63afb445e0 --- /dev/null +++ b/tools/binman/test/231_unique_names_multi.dts @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + + image { + size = <0xc00>; + allow-repack; + + u-boot { + }; + + fdtmap { + }; + + u-boot2 { + type = "u-boot"; + }; + + text { + text = "some text"; + }; + + u-boot-dtb { + }; + + image-header { + location = "end"; + }; + }; + }; +}; From patchwork Sun Mar 27 15:31:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609896 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RHKso1ou; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKb06nkXz9sBJ for ; Mon, 28 Mar 2022 02:32:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A3D6083990; Sun, 27 Mar 2022 17:32:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RHKso1ou"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EA45383950; Sun, 27 Mar 2022 17:32:16 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) (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 4E87680F68 for ; Sun, 27 Mar 2022 17:32:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x629.google.com with SMTP id bq8so10010931ejb.10 for ; Sun, 27 Mar 2022 08:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NC7rrcVwWUFymfOcWnj9paCQuRjnlH87CeFqMQdVKac=; b=RHKso1ougOdWLN5SaJKdl2urH6OLfZKihptnr9uVWH84At4JjdUXHg2wRJBSFSas1w C1zH6KuXarotKa4B5xNysTQ3qA7uDiopEedDkyqkSFk6z3f5S4YbiqLR66mRYhz2gbp/ CnGunHRg/5ApYwrCM24jRn3ChkkfkIuAIwGYa6c9NnN1+jSJGdhsiYNzu5DappaS6/47 kmEmUjNfo9dtFRZ1sdNHWNbyg9nJnY/jeswCZf1TOy8moq/DGaMJkc3R0zuIk+FfF3B9 +4ZXSg/XluGDsqjIEIZXX2oZ6vCS1+GBXABvLRTjRJG85oOmbygbcjQOyc+Sf5Kn6vPM L6DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NC7rrcVwWUFymfOcWnj9paCQuRjnlH87CeFqMQdVKac=; b=avLxmH6bpkB1tSbwbLLZ+Vjcr0IEJAwUkKd+px6t44W+t220BTm4k8auCE+HJ1LrE8 4R4LuzKqxqjjIPG46F04OALk6oVWfc6JxCpfMVBHyxQ/YH4V5/8APitK68Kw0CuI+X2Z D6If6agj3ai5/IW9vQsWrG1pGztb6Pyg31bspG9vJDMTkYdW5Cheqx2bSnypm32HXlRY gPShPtOHWQLuMfoF8lHd4QY9r8doE0WOAM33qBIIgQVaWxSb2PguXIQFglr+O/BkoLsv 1xN7O5DlOabL83LYHs0KFEhkLkSWGMyh7HMytskplgxlZSMyDm+g3sgI9z08trN+XPlP ah0w== X-Gm-Message-State: AOAM531VmolSv9/d4bauLL1s7+zTa0VyN4a5zCA+uSdwvldoCxQYQs05 dg+IKzmz+vMS8mWNITiNysPc8Zfa1Wk= X-Google-Smtp-Source: ABdhPJwG9UVgXGvQWmS37Ph40Zr9GUwJ6sKJPJgb0fYcl8GlARTjgfvgQzfJfEfumQK3K8sLMnnpCQ== X-Received: by 2002:a17:907:a0c9:b0:6e1:46:5918 with SMTP id hw9-20020a170907a0c900b006e100465918mr3054636ejc.366.1648395131810; Sun, 27 Mar 2022 08:32:11 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:11 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 2/7] binman: Collect bintools for images when replacing entries Date: Sun, 27 Mar 2022 18:31:45 +0300 Message-Id: <20220327153151.15912-3-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean Binman entries can use other executables to compute their data, usually in their ObtainContents() methods. Subclasses of Entry_section would use bintools in their BuildSectionData() method instead, which is called from several places including their Pack(). These binary tools are resolved correctly while building an image from a device-tree description so that they can be used from these methods. However, this is not being done when replacing entries in an image, which can result in an error as the Pack() methods attempt to use them. Collect and resolve entries' bintools also when replacing entries to fix Pack() errors. Add a way to mock bintool usage in the testing entry type and tests that check bintools are being resolved for such an entry. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/control.py | 1 + tools/binman/etype/_testing.py | 36 +++++++++++++++++ tools/binman/ftest.py | 38 ++++++++++++++++++ .../binman/test/232_replace_with_bintool.dts | 39 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tools/binman/test/232_replace_with_bintool.dts diff --git a/tools/binman/control.py b/tools/binman/control.py index d4c8dc89201b..e170aeae4fab 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -299,6 +299,7 @@ def BeforeReplace(image, allow_resize): """ state.PrepareFromLoadedData(image) image.LoadData() + image.CollectBintools() # If repacking, drop the old offset/size values except for the original # ones, so we are only left with the constraints. diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index 5089de364294..696004878147 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -39,6 +39,10 @@ class Entry__testing(Entry): error if not) force-bad-datatype: Force a call to GetEntryArgsOrProps() with a bad data type (generating an error) + require-bintool-for-contents: Raise an error if the specified + bintool isn't usable in ObtainContents() + require-bintool-for-pack: Raise an error if the specified + bintool isn't usable in Pack() """ def __init__(self, section, etype, node): super().__init__(section, etype, node) @@ -82,6 +86,26 @@ def ReadNode(self): self.return_contents = True self.contents = b'aa' + # Set to the required bintool when collecting bintools. + self.bintool_for_contents = None + self.require_bintool_for_contents = fdt_util.GetString(self._node, + 'require-bintool-for-contents') + if self.require_bintool_for_contents == '': + self.require_bintool_for_contents = '_testing' + + self.bintool_for_pack = None + self.require_bintool_for_pack = fdt_util.GetString(self._node, + 'require-bintool-for-pack') + if self.require_bintool_for_pack == '': + self.require_bintool_for_pack = '_testing' + + def Pack(self, offset): + """Figure out how to pack the entry into the section""" + if self.require_bintool_for_pack: + if self.bintool_for_pack is None: + self.Raise("Required bintool unusable in Pack()") + return super().Pack(offset) + def ObtainContents(self, fake_size=0): if self.return_unknown_contents or not self.return_contents: return False @@ -92,6 +116,9 @@ def ObtainContents(self, fake_size=0): self.contents_size = len(self.data) if self.return_contents_once: self.return_contents = False + if self.require_bintool_for_contents: + if self.bintool_for_contents is None: + self.Raise("Required bintool unusable in ObtainContents()") return True def GetOffsets(self): @@ -127,3 +154,12 @@ def ProcessFdt(self, fdt): if not self.never_complete_process_fdt: self.process_fdt_ready = True return ready + + def AddBintools(self, btools): + """Add the bintools used by this entry type""" + if self.require_bintool_for_contents is not None: + self.bintool_for_contents = self.AddBintool(btools, + self.require_bintool_for_contents) + if self.require_bintool_for_pack is not None: + self.bintool_for_pack = self.AddBintool(btools, + self.require_bintool_for_pack) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index e6f0159a229f..da9733d39a6a 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5502,6 +5502,44 @@ def testSafeUniqueNamesMulti(self): self._CheckSafeUniqueNames(orig_image, image) + def testReplaceCmdWithBintool(self): + """Test replacing an entry that needs a bintool to pack""" + data = self._DoReadFileRealDtb('232_replace_with_bintool.dts') + expected = U_BOOT_DATA + b'aa' + self.assertEqual(expected, data[:len(expected)]) + + try: + tmpdir, updated_fname = self._SetupImageInTmpdir() + fname = os.path.join(tmpdir, 'update-testing.bin') + tools.write_file(fname, b'zz') + self._DoBinman('replace', '-i', updated_fname, + '_testing', '-f', fname) + + data = tools.read_file(updated_fname) + expected = U_BOOT_DATA + b'zz' + self.assertEqual(expected, data[:len(expected)]) + finally: + shutil.rmtree(tmpdir) + + def testReplaceCmdOtherWithBintool(self): + """Test replacing an entry when another needs a bintool to pack""" + data = self._DoReadFileRealDtb('232_replace_with_bintool.dts') + expected = U_BOOT_DATA + b'aa' + self.assertEqual(expected, data[:len(expected)]) + + try: + tmpdir, updated_fname = self._SetupImageInTmpdir() + fname = os.path.join(tmpdir, 'update-u-boot.bin') + tools.write_file(fname, b'x' * len(U_BOOT_DATA)) + self._DoBinman('replace', '-i', updated_fname, + 'u-boot', '-f', fname) + + data = tools.read_file(updated_fname) + expected = b'x' * len(U_BOOT_DATA) + b'aa' + self.assertEqual(expected, data[:len(expected)]) + finally: + shutil.rmtree(tmpdir) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/232_replace_with_bintool.dts b/tools/binman/test/232_replace_with_bintool.dts new file mode 100644 index 000000000000..d7fabd2cd835 --- /dev/null +++ b/tools/binman/test/232_replace_with_bintool.dts @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + allow-repack; + + u-boot { + }; + + _testing { + require-bintool-for-contents; + require-bintool-for-pack; + }; + + fdtmap { + }; + + u-boot2 { + type = "u-boot"; + }; + + text { + text = "some text"; + }; + + u-boot-dtb { + }; + + image-header { + location = "end"; + }; + }; +}; From patchwork Sun Mar 27 15:31:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609897 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=pvwKK7uG; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKbC4gHFz9sBJ for ; Mon, 28 Mar 2022 02:32:55 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 759FF83941; Sun, 27 Mar 2022 17:32:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pvwKK7uG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DED1D80F68; Sun, 27 Mar 2022 17:32:18 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 DC12A83941 for ; Sun, 27 Mar 2022 17:32:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x634.google.com with SMTP id j15so23942656eje.9 for ; Sun, 27 Mar 2022 08:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BisjAj6UECaGVKjgixlSCXKeZQxFIjGJpuabWO9BS54=; b=pvwKK7uGgh6w50vPYQtKr1fRjH0GNlUGX99k/CrPsr8keN35iLkOEksbIYsvOlUd3b W5fUeubFZXJ3XITukbip5QDQba2Mdc7h0zpwoK6YZu1m1oh8k8E4svi+c+5/9LZE30z0 Ch4nJnEtFQElFCKwnywfGyEwf1bt+2GSajw2eLRSzmqnsA2YQwJfyp9OSbmnyWlT7Kkd Qk0DFxNwDufXBp0XypRggcE9AvWuhO6iCQBWmYmSbINe9BzfYjxaoZjKZDa+AQx8sP5Y jqGXo/NGeLYNRtQxg2qucO3nsa1NkL3jI/9xYtJj2z0o7DCYMLl4i+Y5AlVJ6fdX8ETB Lh/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BisjAj6UECaGVKjgixlSCXKeZQxFIjGJpuabWO9BS54=; b=GNSUTVaOoxR0MatzlirKJQwsh6m/HwfuiiJM6qfkeOxgdXZ17N1T5S2CubIXBOVYj0 +nIes+Z/YafyZ2jJCx6zU2QDGf8t0lShrz3VvHd+EAAWTe1M1+IanEdoNWAe50m8aHk6 LuniRa6sgyNkWkUKFFtjraH8wvN2KhsbyRDK9sRzZr89lGUYMVJ/wbkUPcJ0Hinhbh8M 8aHhtbneo/4sNuJyTSfg8y5fvAYmtszIuSswmyP/VXiWveb1C+lVcM6SlHL9OfJ6K9sP q4nuxIn68m4nCheDmhTQDkPxpkxkMXKGqghQA0jeCENkjpXtitNmNSt1AqISRTiuZa3+ LTCQ== X-Gm-Message-State: AOAM533GoY9ak4v5zoYjn0by5kIYdShrQiD98rH38Ml4qxtV0A01C47z NOAhb/UuQQ29E5pda1FGEmLtg8GacQQ= X-Google-Smtp-Source: ABdhPJx+W+augIQxPKac6uOuv6dvgh0lfsDraVEcLK/CEvialEctxs5WIpssRuoV30mVnfX7rmCb3A== X-Received: by 2002:a17:906:4fcc:b0:6e0:3269:2054 with SMTP id i12-20020a1709064fcc00b006e032692054mr21960035ejw.117.1648395134408; Sun, 27 Mar 2022 08:32:14 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:13 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 3/7] binman: Don't reset offset/size if image doesn't allow repacking Date: Sun, 27 Mar 2022 18:31:46 +0300 Message-Id: <20220327153151.15912-4-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean When an image has the 'allow-repack' property, binman includes the original offset and size properties from the image description in the fdtmap. These are later used as the packing constraints when replacing entries in an image, so other unconstrained entries can be freely positioned. Replacing an entry in an image without 'allow-repack' (and therefore the original offsets) follows the same logic and results in entries being merely concatenated. Instead, skip resetting the calculated offsets and sizes to the missing originals for these images so that every entry is constrained to its existing offset/size. Add tests that replace an entry with smaller or equal-sized data, in an image that doesn't allow repacking. Attempting to do so with bigger-size data is already an error that is already being tested. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/control.py | 2 +- tools/binman/ftest.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/binman/control.py b/tools/binman/control.py index e170aeae4fab..ce57dc7efc7b 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -303,7 +303,7 @@ def BeforeReplace(image, allow_resize): # If repacking, drop the old offset/size values except for the original # ones, so we are only left with the constraints. - if allow_resize: + if image.allow_repack and allow_resize: image.ResetForPack() diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index da9733d39a6a..3d79f82dff43 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5540,6 +5540,27 @@ def testReplaceCmdOtherWithBintool(self): finally: shutil.rmtree(tmpdir) + def testReplaceResizeNoRepackSameSize(self): + """Test replacing entries with same-size data without repacking""" + expected = b'x' * len(U_BOOT_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', expected) + self.assertEqual(expected, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + + def testReplaceResizeNoRepackSmallerSize(self): + """Test replacing entries with smaller-size data without repacking""" + new_data = b'x' + data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', new_data) + expected = new_data.ljust(len(U_BOOT_DATA), b'\0') + self.assertEqual(expected, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + if __name__ == "__main__": unittest.main() From patchwork Sun Mar 27 15:31:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609899 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=gvcKgdH5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKbj239dz9sBJ for ; Mon, 28 Mar 2022 02:33:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 35ABA839B3; Sun, 27 Mar 2022 17:32:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gvcKgdH5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 048B88395B; Sun, 27 Mar 2022 17:32:25 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 8E6D0836A9 for ; Sun, 27 Mar 2022 17:32:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ed1-x52f.google.com with SMTP id a17so14330193edm.9 for ; Sun, 27 Mar 2022 08:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GnqHri317SlaV1PGcxVfGu/eK3Gnb9CpcaeykC/2mCU=; b=gvcKgdH5gBc3ftbDgrimzNYOlvy+sj8BEtwACDmboDP+azux54ShAznwA2m9pAaY5u PuKSWwW+zqnNeUTbLkT26Ppxm2MO32l7/L5FK+PvbZn8L4qkGQNuVo+5pehe1WCnG/bM eGNXgFp4OD8jnkO7B+n/r0GVh8pj3iGX5B1oDmiOk+xkVNOo28fepI79EaMfPIi07UzM Ou0zm6+wmkuq0Ld+GvE3IuSD5948rYRaOkJ0PFtd2u1+S5xeCG4kAHPV0JoTW68nmtp4 TV7gMfwGueanqSHtzydh2wlEiqjWgjMrN/r7G5Wl8KT3naZisDejjt3P4ax+66aP9Oet q2LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GnqHri317SlaV1PGcxVfGu/eK3Gnb9CpcaeykC/2mCU=; b=Q69lhRlDiBsWTra59xUgrz9W1vbAlz+Fnnx8r3j6xhX3e4uEQgvBJdf3D1O3481FON oyd8TSYviiMR0snnTH6uLjWf7tZ04baydUXR68eANfC44/Kuu8KY2nCC8bDOoZxRoCUf wRhK02Bwtzr9EHT08low2A4dyUSpVdHzt2XsQbl9YE7ePUnfT6GY4iGLcwPm9vbuRsf3 XidmrITqBbadRumSakqFGViE37KbDRslhSk/5/MMwDHpct1WpOIG4L7+B9gUMU7cdRJv /XCbiDQk3cejNLQWrON7ge4OeGGJq5fw7/p9Aj1OgIV/cSpDJp0wEnlReCoEoKTYW4hf e57w== X-Gm-Message-State: AOAM530nfn5Exah36sXZgIJ5rsNQyrZIbPcW93sTTYuhmmWlYYomNAOG 89V/6FB0nVCDy/jOWu8j61+utHQ5xpA= X-Google-Smtp-Source: ABdhPJzy7bI9IxF1LEH8mHIm85BbgSWDkQAP8VUkoUNvad4+xtYqEMEPprm8CkKRjc9NL9pp8QgPDA== X-Received: by 2002:a05:6402:35c5:b0:419:2c72:66c3 with SMTP id z5-20020a05640235c500b004192c7266c3mr11032311edc.343.1648395139131; Sun, 27 Mar 2022 08:32:19 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:18 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 4/7] binman: Remove '/images/' fragment from FIT subentry paths Date: Sun, 27 Mar 2022 18:31:47 +0300 Message-Id: <20220327153151.15912-5-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean Binman FIT entry nodes describe their subentries in an 'images' subnode, same as how they would be written for the mkimage executable. The entry type initially manually managed its subentries keyed by their node paths relative to its base node. It was later converted to a proper section while still keeping the same keys for subentries. These subentry keys of sections are used as path fragments, so they must not contain the path separator character '/'. Otherwise, they won't be addressable by binman extract/replace commands. Change these keys from the '/images/foo' forms to the subentry node names. Extend the simple FIT tests to check for this. Signed-off-by: Alper Nebi Yasak --- tools/binman/etype/fit.py | 13 ++++++++----- tools/binman/ftest.py | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index e0407715d819..035719871e04 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -384,7 +384,8 @@ def _add_entries(base_node, depth, node): entry.ReadNode() # The hash subnodes here are for mkimage, not binman. entry.SetUpdateHash(False) - self._entries[rel_path] = entry + image_name = rel_path[len('/images/'):] + self._entries[image_name] = entry for subnode in node.subnodes: _add_entries(base_node, depth + 1, subnode) @@ -630,7 +631,8 @@ def _add_node(base_node, depth, node): has_images = depth == 2 and in_images if has_images: - entry = self._priv_entries[rel_path] + image_name = rel_path[len('/images/'):] + entry = self._priv_entries[image_name] data = entry.GetData() fsw.property('data', bytes(data)) @@ -643,12 +645,12 @@ def _add_node(base_node, depth, node): # fsw.add_node() or _add_node() for it. pass elif self.GetImage().generate and subnode.name.startswith('@'): - entry = self._priv_entries.get(subnode_path) + entry = self._priv_entries.get(subnode.name) _gen_node(base_node, subnode, depth, in_images, entry) # This is a generator (template) entry, so remove it from # the list of entries used by PackEntries(), etc. Otherwise # it will appear in the binman output - to_remove.append(subnode_path) + to_remove.append(subnode.name) else: with fsw.add_node(subnode.name): _add_node(base_node, depth + 1, subnode) @@ -693,7 +695,8 @@ def SetImagePos(self, image_pos): fdt = Fdt.FromData(self.GetData()) fdt.Scan() - for path, section in self._entries.items(): + for image_name, section in self._entries.items(): + path = f"/images/{image_name}" node = fdt.GetNode(path) data_prop = node.props.get("data") diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 3d79f82dff43..87c072ef9c9c 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -3761,6 +3761,13 @@ def _CheckSimpleFitData(self, fit_data, kernel_data, fdt1_data): self.assertEqual(len(kernel_data), int(data_sizes[0].split()[0])) self.assertEqual(len(fdt1_data), int(data_sizes[1].split()[0])) + # Check if entry listing correctly omits /images/ + image = control.images['image'] + fit_entry = image.GetEntries()['fit'] + subentries = list(fit_entry.GetEntries().keys()) + expected = ['kernel', 'fdt-1'] + self.assertEqual(expected, subentries) + def testSimpleFit(self): """Test an image with a FIT inside""" data = self._DoReadFile('161_fit.dts') From patchwork Sun Mar 27 15:31:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609898 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=S2bzuTa+; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKbS3GtHz9sBJ for ; Mon, 28 Mar 2022 02:33:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BEB383981; Sun, 27 Mar 2022 17:32:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S2bzuTa+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED10683994; Sun, 27 Mar 2022 17:32:29 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 0914A83953 for ; Sun, 27 Mar 2022 17:32:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x630.google.com with SMTP id qa43so23942932ejc.12 for ; Sun, 27 Mar 2022 08:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bboduJ1hqqAr9DtgnBx25SrAoxJSt+ZGvisMYhebZk4=; b=S2bzuTa+0W+5PcgUMkRhv354UjQM4HzC24t++QPU5/TaGdK+RuBWxGuxYDLxxgo0uy xonlBAhkMUo8BgeSzdXm7PSeznS2Vi0rNSemqEodsz3h+g5pmENk1fpgwTU5QOvngyL4 wF9GzQmw70SPxUgQGrXhrispjpux/TEZyR1TVccOgK54D+v7lQHeB2cqodZizP/02DIC JS0cjAMKm6mGHGbHCdC9Q+nK8wzcqRRRGiznmjKhzNbSkGVfFn2j7QTtMryHgBzT+wox V0j/Gju9depszcEuansB/EfHb+idlInAP0KJF1Qvh12BS8gsqaaf6PaKsgp+N8yAQfjQ vC4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bboduJ1hqqAr9DtgnBx25SrAoxJSt+ZGvisMYhebZk4=; b=TsdLmVhp4sdGAbgE6o53oSGFxAIQmYOLJMWQMkl5P5I2Dw96CALwznugTAJf6gtCeT S2XzmwMckr4LkSG1sJgLMpZlZOkg/zdWvcyvdihO/uteUGXzLrg90SJvHcxjWvqdece4 k2GKJmyLSsCSg5C6edbwLx5HdYSXq8lRTsuUI1qJ8/sdN0SIKCsgUyVlxnGgznABZzSA tcNsoK4WkTihyQLvnpaSYLfQQhFVjmZjgHvzV7vg7vu99L/vpnpZK8L85jvemsoKITI5 4cmMGLZjLp3Pw0Zm0y+UQvPyUFBMmS802plx9rFuCP+Qh0nILgHt8xYcmfKcmDtHjzDH yUUA== X-Gm-Message-State: AOAM531oFt2pKZoragSV+y77oIh9g9xXUqwbOu2ksjdtBfSgFFUYizie aFve0sdeVFcJpE49f+Rg4ZUhMP6//Lw= X-Google-Smtp-Source: ABdhPJzzWmn8Wop1LfZ6e4hkdIqB6bqfXTcmublazBxvRm2LHTcJQt3vMT+o5h0E1LRLJS7En97ywA== X-Received: by 2002:a17:907:7f8d:b0:6db:7227:daea with SMTP id qk13-20020a1709077f8d00b006db7227daeamr22465167ejc.100.1648395141560; Sun, 27 Mar 2022 08:32:21 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:21 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 5/7] binman: Create FIT subentries in the FIT section, not its parent Date: Sun, 27 Mar 2022 18:31:48 +0300 Message-Id: <20220327153151.15912-6-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean When reading images from a file, each entry's data is read from its parent section as specified in the Entry.Create() call that created it. The FIT entry type has been creating its subentries under its parent (their grandparent), as creating them under the FIT entry resulted in an error until FIT was converted into a proper section. FIT subentries have their offsets relative to the FIT section, and reading those offsets in the parent section results in wrong data. The subentries rightfully belong under the FIT entries, so create them there. Add tests checking that we can extract the correct data for a FIT entry and its subentries. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/etype/fit.py | 2 +- tools/binman/ftest.py | 35 +++++++++ tools/binman/test/233_fit_extract_replace.dts | 74 +++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/233_fit_extract_replace.dts diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 035719871e04..12306623af67 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -380,7 +380,7 @@ def _add_entries(base_node, depth, node): # section entries for them here to merge the content subnodes # together and put the merged contents in the subimage node's # 'data' property later. - entry = Entry.Create(self.section, node, etype='section') + entry = Entry.Create(self, node, etype='section') entry.ReadNode() # The hash subnodes here are for mkimage, not binman. entry.SetUpdateHash(False) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 87c072ef9c9c..a31568997f6f 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5568,6 +5568,41 @@ def testReplaceResizeNoRepackSmallerSize(self): self.assertIsNotNone(path) self.assertEqual(expected_fdtmap, fdtmap) + def testExtractFit(self): + """Test extracting a FIT section""" + self._DoReadFileRealDtb('233_fit_extract_replace.dts') + image_fname = tools.get_output_filename('image.bin') + + fit_data = control.ReadEntry(image_fname, 'fit') + fit = fdt.Fdt.FromData(fit_data) + fit.Scan() + + # Check subentry data inside the extracted fit + for node_path, expected in [ + ('/images/kernel', U_BOOT_DATA), + ('/images/fdt-1', U_BOOT_NODTB_DATA), + ('/images/scr-1', COMPRESS_DATA), + ]: + node = fit.GetNode(node_path) + data = fit.GetProps(node)['data'].bytes + self.assertEqual(expected, data) + + def testExtractFitSubentries(self): + """Test extracting FIT section subentries""" + self._DoReadFileRealDtb('233_fit_extract_replace.dts') + image_fname = tools.get_output_filename('image.bin') + + for entry_path, expected in [ + ('fit/kernel', U_BOOT_DATA), + ('fit/kernel/u-boot', U_BOOT_DATA), + ('fit/fdt-1', U_BOOT_NODTB_DATA), + ('fit/fdt-1/u-boot-nodtb', U_BOOT_NODTB_DATA), + ('fit/scr-1', COMPRESS_DATA), + ('fit/scr-1/blob', COMPRESS_DATA), + ]: + data = control.ReadEntry(image_fname, entry_path) + self.assertEqual(expected, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/233_fit_extract_replace.dts b/tools/binman/test/233_fit_extract_replace.dts new file mode 100644 index 000000000000..b44d05afe1af --- /dev/null +++ b/tools/binman/test/233_fit_extract_replace.dts @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + allow-repack; + + fill { + size = <0x1000>; + fill-byte = [77]; + }; + + fit { + description = "test-desc"; + #address-cells = <1>; + + images { + kernel { + description = "test u-boot"; + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + + u-boot { + }; + }; + + fdt-1 { + description = "test u-boot-nodtb"; + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + + u-boot-nodtb { + }; + }; + + scr-1 { + description = "test blob"; + type = "script"; + arch = "arm64"; + compression = "none"; + + blob { + filename = "compress"; + }; + }; + }; + + configurations { + default = "conf-1"; + + conf-1 { + description = "Kernel with FDT blob"; + kernel = "kernel"; + fdt = "fdt-1"; + }; + }; + }; + + u-boot-dtb { + }; + + fdtmap { + }; + }; +}; From patchwork Sun Mar 27 15:31:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609900 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=btcxOpG1; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKbt47Vzz9sBJ for ; Mon, 28 Mar 2022 02:33:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6E1F839B1; Sun, 27 Mar 2022 17:33:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="btcxOpG1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A321F8395A; Sun, 27 Mar 2022 17:32:35 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 71F5A8396C for ; Sun, 27 Mar 2022 17:32:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x631.google.com with SMTP id yy13so23999876ejb.2 for ; Sun, 27 Mar 2022 08:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bct4mL3ozcxTChvxCkPbDUNK1RfvDHWOd+esrXOz+bU=; b=btcxOpG1WN7Lj8H+j50T8v2CBXEUnBK+fwnTyO+iZQEvaVpbpZuJZGmvVsFOCscbNI 5ql0DmwKIlubYo8sjCtb+igavgfaO6v8Ck1NlfN8E14dhfc2A4Ae4kg284MfkgIPa8lI SbaLQTkLs8K9n6J0NLtJUr6lOXgoTIKwer3cDo6obN0DppY9eMxGOcOEBdauYH1+/3O6 KtVweiDfXI0h8+5JxnpehuSAYhHgIUktTTYRxoHjf39/yH6ChUqwf6zxVeNzJ2Eyz8sL c4+rJfE/Lqj8VGbFaDW/F1Vj0f6nWGWu7KxoHsc76n9gGZAtsF//N4hG6ALC+xLADinm NuKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bct4mL3ozcxTChvxCkPbDUNK1RfvDHWOd+esrXOz+bU=; b=w1VVM8GXK/Wk42hbNBPlLx4WP9FK2u7PMo6Kya/p5F7UsbWUdUCns1imfwcY+Sl1dt EQaUTQZB+Arzm0GpQPwTlp+mcYVxMnkr+4JS7O43xpWFQQOuowLuldZQEOIa6TxbtJzg ey/klYMMRG9R4M0irV1vOXI0LFzKwWPNIu+6PXdB7O/iFpzSoCKjYO3U+Nac3AzQ8YN+ e/gmm28EMhcfvLM4/27Y3qjfIKWNRr+saBwnRTWLaCk1GtcB7E87vgkfCveX5ZwYyfHJ ly6XSDiuIyt0Z89SSh/ZyRxDyvRDpe+WG9M32djKDX8hhWDfKQR4MW1ovYXUp93Oy4NB AeaA== X-Gm-Message-State: AOAM532KQ9b+oxpk66/JUrOMA7OssdrCgMIWUXGm8viBn0v1/v6rNN8h n9W9Zo0WPEXqQqoa2N7nxh84Pty1igU= X-Google-Smtp-Source: ABdhPJwRFYlYeJ2oZQ6dm8+HTVOtdvGxuOAJsaWJaT04mLW9RifjFYiJ1WcA9ES4O5hMtT7JipPw0Q== X-Received: by 2002:a17:907:7202:b0:6df:83a9:67d2 with SMTP id dr2-20020a170907720200b006df83a967d2mr22422474ejc.327.1648395144114; Sun, 27 Mar 2022 08:32:24 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:23 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 6/7] binman: Test replacing non-section entries in FIT subsections Date: Sun, 27 Mar 2022 18:31:49 +0300 Message-Id: <20220327153151.15912-7-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean A previous patch fixes binman to correctly extract FIT subentries. This makes it easier to test replacing these entries as we can write tests using an existing helper function that relies on extracting the replaced entry. Add tests that replace leaf entries in FIT subsections with data of various sizes. Replacing the subsections or the whole FIT section does not work yet due to the section contents being re-built from unreplaced subentries' data. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/ftest.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index a31568997f6f..43bec4a88841 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5603,6 +5603,44 @@ def testExtractFitSubentries(self): data = control.ReadEntry(image_fname, entry_path) self.assertEqual(expected, data) + def testReplaceFitSubentryLeafSameSize(self): + """Test replacing a FIT leaf subentry with same-size data""" + new_data = b'x' * len(U_BOOT_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd( + 'fit/kernel/u-boot', new_data, + dts='233_fit_extract_replace.dts') + self.assertEqual(new_data, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + + def testReplaceFitSubentryLeafBiggerSize(self): + """Test replacing a FIT leaf subentry with bigger-size data""" + new_data = b'ub' * len(U_BOOT_NODTB_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd( + 'fit/fdt-1/u-boot-nodtb', new_data, + dts='233_fit_extract_replace.dts') + self.assertEqual(new_data, data) + + # Will be repacked, so fdtmap must change + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertNotEqual(expected_fdtmap, fdtmap) + + def testReplaceFitSubentryLeafSmallerSize(self): + """Test replacing a FIT leaf subentry with smaller-size data""" + new_data = b'x' + expected = new_data.ljust(len(U_BOOT_NODTB_DATA), b'\0') + data, expected_fdtmap, _ = self._RunReplaceCmd( + 'fit/fdt-1/u-boot-nodtb', new_data, + dts='233_fit_extract_replace.dts') + self.assertEqual(expected, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + if __name__ == "__main__": unittest.main() From patchwork Sun Mar 27 15:31:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1609901 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=LBseYZP/; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRKc52N5xz9sBJ for ; Mon, 28 Mar 2022 02:33:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B2A7F83A34; Sun, 27 Mar 2022 17:33:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LBseYZP/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C6AC3836A9; Sun, 27 Mar 2022 17:32:36 +0200 (CEST) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 03FB383981 for ; Sun, 27 Mar 2022 17:32:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x62a.google.com with SMTP id qa43so23943189ejc.12 for ; Sun, 27 Mar 2022 08:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tGwfkg5My1s9WbGMVuc2RpeNotGY8kEuBcJkL+RcZHE=; b=LBseYZP/XoUwIQUiC2crx40aCR2VgMI2G8p7OkhcksbcthxGasRZmCphTNdg+hW2uU 9fRfkxV4WIrGScpvPH/FXnRIvk8chVokG75q+nMDEfs+7kQGWQh32hGCXWenu6wZIBdk y1S9PO+pSkiFahaB07ZWDR9k6hz+uA8Z4SRl0pY9TA1Ol8kDTbW0bjTfrS2bdjpEX6tI ky3PQAqUz4aotcOtONWFLAh2G8zvsKYeCTjAAb0Xwu1IiowJqFAnnV1fACvi0CcIGcSu VD3Cv+0F4WtPbioBmjwPvNmywCaF+bfoAHzp7QEBV7X3Rkqu/47I2Eugj83648GXxaC/ G2Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tGwfkg5My1s9WbGMVuc2RpeNotGY8kEuBcJkL+RcZHE=; b=esYbTvezdJ5Mpuy6Z4OkC4HXzvS5pdBdgHryp9V5/hfj1u7y7WjPdYj+MEAI92O/dV cw0iNT0oxPs1OTa4YlZu8dVr6GFChvbXtmjxzT2ji+IvF80Lc5HqPl+e08PFGbIERi/B tiNpE6B3caEPr1pdqRF3l+gQswQQ4wzGlI0bJj64E24DzmHc3LMmMvF6fb+aP4zzartM svAgY30Z6L7MaVFRYxBb3+PGQyCD9LyT6axWc4LgMmNVO4st/WpD1UOgNm2pcbJMMcfC Hp0WNQQ/37Zfu6MpRONYGQdT47H3mp0VGgHXyf0Wdw9eTGNaCieHQQxAySzm9oUGKkXC M8NA== X-Gm-Message-State: AOAM531MSKYJVWUxqxC39FXSFgWRyw95KURDFfXWhaOvNnWbGMUTDgWF ukW9EXt4oKJR5DEcLLWNf8kNSsz8aKY= X-Google-Smtp-Source: ABdhPJwkdDAhwpo9MuUTGjojf47/cJ66AH0i9nn/Chn4kKjjsW9g0BH98Mz+guZCD9/jJVb01URw6w== X-Received: by 2002:a17:907:62a1:b0:6da:7952:d4d2 with SMTP id nd33-20020a17090762a100b006da7952d4d2mr22480120ejc.260.1648395146650; Sun, 27 Mar 2022 08:32:26 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:26 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 7/7] binman: Refuse to replace sections for now Date: Sun, 27 Mar 2022 18:31:50 +0300 Message-Id: <20220327153151.15912-8-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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.5 at phobos.denx.de X-Virus-Status: Clean Binman interfaces allow attempts to replace any entry in the image with arbitrary data. When trying to replace sections, the changes in the section entry's data are not propagated to its child entries. This, combined with how sections rebuild their contents from its children, eventually causes the replaced contents to be silently overwritten by rebuilt contents equivalent to the original data. Add a simple test for replacing a section that is currently failing due to this behaviour, and mark it as an expected failure. Also, raise an error when replacing a section instead of silently pretending it was replaced. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/etype/section.py | 3 +++ tools/binman/ftest.py | 9 ++++++++ .../test/234_replace_section_simple.dts | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tools/binman/test/234_replace_section_simple.dts diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index ccac658c1831..bd67238b9199 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -788,6 +788,9 @@ def ReadChildData(self, child, decomp=True, alt_format=None): data = new_data return data + def WriteData(self, data, decomp=True): + self.Raise("Replacing sections is not implemented yet") + def WriteChildData(self, child): return True diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 43bec4a88841..058651cc18a0 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5641,6 +5641,15 @@ def testReplaceFitSubentryLeafSmallerSize(self): self.assertIsNotNone(path) self.assertEqual(expected_fdtmap, fdtmap) + @unittest.expectedFailure + def testReplaceSectionSimple(self): + """Test replacing a simple section with arbitrary data""" + new_data = b'w' * len(COMPRESS_DATA + U_BOOT_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd( + 'section', new_data, + dts='234_replace_section_simple.dts') + self.assertEqual(new_data, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/234_replace_section_simple.dts b/tools/binman/test/234_replace_section_simple.dts new file mode 100644 index 000000000000..c9d5c3285615 --- /dev/null +++ b/tools/binman/test/234_replace_section_simple.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + allow-repack; + + u-boot-dtb { + }; + + section { + blob { + filename = "compress"; + }; + + u-boot { + }; + }; + + fdtmap { + }; + }; +};