From patchwork Fri Aug 26 15:36:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 1670913 X-Patchwork-Delegate: ykai007@gmail.com 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=) 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 4MDkVK6rgYz1yhT for ; Sat, 27 Aug 2022 01:37:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1AEC884915; Fri, 26 Aug 2022 17:37:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0leil.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 9FFC9848E3; Fri, 26 Aug 2022 17:37:05 +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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [IPv6:2001:4b98:dc4:8::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 07367848F0 for ; Fri, 26 Aug 2022 17:37:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0leil.net Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=foss+uboot@0leil.net Received: (Authenticated sender: foss@0leil.net) by mail.gandi.net (Postfix) with ESMTPSA id A2FD120000D; Fri, 26 Aug 2022 15:36:59 +0000 (UTC) From: Quentin Schulz To: Cc: bharat.gooty@broadcom.com, rayagonda.kokatanur@broadcom.com, sjg@chromium.org, philipp.tomsich@vrull.eu, kever.yang@rock-chips.com, jagan@amarulasolutions.com, alpernebiyasak@gmail.com, xypron.glpk@gmx.de, heiko.thiery@gmail.com, u-boot@lists.denx.de, Quentin Schulz , Quentin Schulz Subject: [PATCH v5 2/8] binman: allow user-defined filenames for mkimage entry Date: Fri, 26 Aug 2022 17:36:28 +0200 Message-Id: <20220826153634.3086393-3-foss+uboot@0leil.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220826153634.3086393-1-foss+uboot@0leil.net> References: <20220826153634.3086393-1-foss+uboot@0leil.net> 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 From: Quentin Schulz mkimage entry currently creates a file whose name is derived from the section name containing said entry. Let's allow the user to define a filename for the mkimage-generated binary by using the 'filename' DT property. Cc: Quentin Schulz Signed-off-by: Quentin Schulz Reviewed-by: Simon Glass --- v5: - updated unit test filename, - removed _testing section in unit test, - removed -n arg in unit test, - removed size property in binman node, v4: - added binman test, - fixed >80 chars-long line, added in v3 tools/binman/etype/mkimage.py | 11 ++++++++--- tools/binman/ftest.py | 7 +++++++ tools/binman/test/242_mkimage_filename.dts | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tools/binman/test/242_mkimage_filename.dts diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py index 5f4bc6fa3c..c2288c48ee 100644 --- a/tools/binman/etype/mkimage.py +++ b/tools/binman/etype/mkimage.py @@ -21,11 +21,13 @@ class Entry_mkimage(Entry): - multiple-data-files: boolean to tell binman to pass all files as datafiles to mkimage instead of creating a temporary file the result of datafiles concatenation + - filename: filename of output binary generated by mkimage The data passed to mkimage via the -d flag is collected from subnodes of the mkimage node, e.g.:: mkimage { + filename = "imximage.bin"; args = "-n test -T imximage"; u-boot-spl { @@ -38,8 +40,9 @@ class Entry_mkimage(Entry): mkimage -d -n test -T imximage The output from mkimage then becomes part of the image produced by - binman. If you need to put multiple things in the data file, you can use - a section, or just multiple subnodes like this:: + binman but also is written into `imximage.bin` file. If you need to put + multiple things in the data file, you can use a section, or just multiple + subnodes like this:: mkimage { args = "-n test -T imximage"; @@ -121,6 +124,7 @@ class Entry_mkimage(Entry): self._multiple_data_files = fdt_util.GetBool(self._node, 'multiple-data-files') self._mkimage_entries = OrderedDict() self._imagename = None + self._filename = fdt_util.GetString(self._node, 'filename') self.align_default = None def ReadNode(self): @@ -164,7 +168,8 @@ class Entry_mkimage(Entry): [self._imagename], 'mkimage-n', 1024) if image_data is None: return False - output_fname = tools.get_output_filename('mkimage-out.%s' % uniq) + outfile = self._filename if self._filename else 'mkimage-out.%s' % uniq + output_fname = tools.get_output_filename(outfile) args = ['-d', input_fname] if self._data_to_imagename: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 091692ef93..da0c7299ac 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5834,6 +5834,13 @@ fdt fdtmap Extract the devicetree blob from the fdtmap expect += U_BOOT_SPL_DATA self.assertEqual(expect, data[-len(expect):]) + def testMkimageFilename(self): + """Test using mkimage to build a binary with a filename""" + retcode = self._DoTestFile('242_mkimage_filename.dts') + self.assertEqual(0, retcode) + fname = tools.get_output_filename('mkimage-test.bin') + self.assertTrue(os.path.exists(fname)) + def testCompressDtbPrependInvalid(self): """Test that invalid header is detected""" with self.assertRaises(ValueError) as e: diff --git a/tools/binman/test/242_mkimage_filename.dts b/tools/binman/test/242_mkimage_filename.dts new file mode 100644 index 0000000000..4483790ae8 --- /dev/null +++ b/tools/binman/test/242_mkimage_filename.dts @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + mkimage { + filename = "mkimage-test.bin"; + args = "-T script"; + + u-boot-spl { + }; + }; + }; +};