From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAF2CC433F5 for ; Sun, 27 Mar 2022 15:32:42 +0000 (UTC) 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) 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 Content-Transfer-Encoding: 8bit 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 --- 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"; + }; + }; +}; -- 2.35.1