From patchwork Sat Dec 17 16:11:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1716905 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=Dq32UJWX; 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 4NZ9vy1vk3z240B for ; Sun, 18 Dec 2022 03:11:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA66485375; Sat, 17 Dec 2022 17:11:50 +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="Dq32UJWX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4D6CD85382; Sat, 17 Dec 2022 17:11:49 +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-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (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 4FC4681A10 for ; Sat, 17 Dec 2022 17:11:46 +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-x135.google.com with SMTP id d14so2743075ilq.11 for ; Sat, 17 Dec 2022 08:11:46 -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=EInlF38ygF4b3Doyzad7HjBjbxvnSC+wVq1WYXqSzvk=; b=Dq32UJWXwd7s/mWiXULkJoIkZcjMszxBf+/oycSgyh4XDVoqscxNLNKP+M6FRbe/OZ suc0QowUTbXcdeUMLGnBitzZNTKOBOzphqh55NriZIUoafwLUIDV02jWIoo+lhsNoi1N i9OrgMxsMew/Z7rBP5zP8oSX+dZuCAnpDjOf0= 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=EInlF38ygF4b3Doyzad7HjBjbxvnSC+wVq1WYXqSzvk=; b=Oy1pryQ2QVB7r3dylvTJrxB2S/OpyQMM/utdFuIfIHgyvgA8Xs8imUOMka3yianl84 uAGi7ayG4YQwP4kfVdfTLnQQcBaJMnPyTXTVIDGQhRM2K4L8Bmfekg96rL27is3rkvzR MCaKqzA9m5xkQWjwgD9BtvOoL9r3DbZnReeEoyBfERMsTMVY8PawhuhPq7iX7/76lQ4N gR7b7bF5Bah83AoaCdv2DSy9aTatbaEIm1DxthjRVZx7zgu9DQXqLlWkGe+4Iv307Acf 0mIpCNQqOl07Kitrve4k9V6Dc0thnZtQYfCokxe9xPEZvNXNWFtZ866f6DhXyOwoSEmh eaSQ== X-Gm-Message-State: ANoB5pkcf7jC3Pmip86CqMRlnQsUwcHGYS8PW8QTiR/PCzaH25vnbZQW zB7/FQ2yt1sD4jCtX77PqFdhdNVYWlNfsTXA X-Google-Smtp-Source: AA0mqf4TvvrXZHOW50apxWn5oY9ueEk9FYlR1x2MvcCbjSMxz3OgppRXDaar7YOf5rEHtYyThfGQqQ== X-Received: by 2002:a05:6e02:b2a:b0:303:3e96:a16c with SMTP id e10-20020a056e020b2a00b003033e96a16cmr29956020ilu.20.1671293504680; Sat, 17 Dec 2022 08:11:44 -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 o5-20020a056e02092500b00302f958e71dsm1652817ilt.49.2022.12.17.08.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 08:11:43 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Peter Geis , Jerome Forissier , Tom Rini , Philippe Reynes , Alper Nebi Yasak , huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich , Quentin Schulz , Ivan Mikhaylov , Roger Quadros Subject: [PATCH v6 01/12] binman: Allow writing section contents to a file Date: Sat, 17 Dec 2022 09:11:06 -0700 Message-Id: <20221217161117.61699-2-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221217161117.61699-1-sjg@chromium.org> References: <20221217161117.61699-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 At present only the image (which is a section) has a filename. Move this implementation to the entry_Section class so that any section can have a filename. With this, the section data is written to a file. This allows parts of an image to be written, along with the entire image. Make a note that this can be used to include the contents of a section in one image in another (later) image. Signed-off-by: Simon Glass --- (no changes since v5) Changes in v5: - Update commit message to mention using parts of one image in another tools/binman/binman.rst | 5 +++++ tools/binman/etype/section.py | 12 +++++++++- tools/binman/ftest.py | 14 ++++++++++++ tools/binman/image.py | 3 --- tools/binman/test/261_section_fname.dts | 29 +++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 tools/binman/test/261_section_fname.dts diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index e7b231e0712..b091114fb91 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -836,6 +836,11 @@ name-prefix: renamed to 'ro-u-boot' and 'rw-u-boot'. This can be useful to distinguish binaries with otherwise identical names. +filename: + This allows the contents of the section to be written to a file in the + output directory. This can sometimes be useful to use the data in one + section in different image, since there is currently no way to share data + beteen images other than through files. Image Properties ---------------- diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index da561e2bcc7..305155c8461 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -144,6 +144,10 @@ class Entry_section(Entry): be written at offset 4 in the image file, since the first 16 bytes are skipped when writing. + filename + filename to write the unpadded section contents to within the output + directory (None to skip this). + Since a section is also an entry, it inherits all the properies of entries too. @@ -163,6 +167,7 @@ class Entry_section(Entry): self._skip_at_start = None self._end_4gb = False self._ignore_missing = False + self._filename = None def ReadNode(self): """Read properties from the section node""" @@ -183,6 +188,8 @@ class Entry_section(Entry): self._skip_at_start = 0 self._name_prefix = fdt_util.GetString(self._node, 'name-prefix') self.align_default = fdt_util.GetInt(self._node, 'align-default', 0) + self._filename = fdt_util.GetString(self._node, 'filename', + self._filename) self.ReadEntries() @@ -348,7 +355,8 @@ class Entry_section(Entry): """Get the contents of an entry This builds the contents of the section, stores this as the contents of - the section and returns it + the section and returns it. If the section has a filename, the data is + written there also. Args: required: True if the data must be present, False if it is OK to @@ -363,6 +371,8 @@ class Entry_section(Entry): if data is None: return None self.SetContents(data) + if self._filename: + tools.write_file(tools.get_output_filename(self._filename), data) return data def GetOffsets(self): diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 62ee86b9b75..c3cb32dca26 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6077,5 +6077,19 @@ fdt fdtmap Extract the devicetree blob from the fdtmap 'Cannot write symbols to an ELF file without Python elftools', str(exc.exception)) + def testSectionFilename(self): + """Check writing of section contents to a file""" + data = self._DoReadFile('261_section_fname.dts') + expected = (b'&&' + U_BOOT_DATA + b'&&&' + + tools.get_bytes(ord('!'), 7) + + U_BOOT_DATA + tools.get_bytes(ord('&'), 12)) + self.assertEqual(expected, data) + + sect_fname = tools.get_output_filename('outfile.bin') + self.assertTrue(os.path.exists(sect_fname)) + sect_data = tools.read_file(sect_fname) + self.assertEqual(U_BOOT_DATA, sect_data) + + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/image.py b/tools/binman/image.py index 6d4bff58436..b84dd21e22a 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -94,9 +94,6 @@ class Image(section.Entry_section): def ReadNode(self): super().ReadNode() - filename = fdt_util.GetString(self._node, 'filename') - if filename: - self._filename = filename self.allow_repack = fdt_util.GetBool(self._node, 'allow-repack') self._symlink = fdt_util.GetString(self._node, 'symlink') diff --git a/tools/binman/test/261_section_fname.dts b/tools/binman/test/261_section_fname.dts new file mode 100644 index 00000000000..790381e7301 --- /dev/null +++ b/tools/binman/test/261_section_fname.dts @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + pad-byte = <0x26>; + size = <0x20>; + section@0 { + size = <0x10>; + pad-byte = <0x21>; + pad-before = <2>; + pad-after = <3>; + + section { + filename = "outfile.bin"; + u-boot { + }; + }; + }; + section@1 { + u-boot { + }; + }; + }; +};