All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Roger Quadros <rogerq@ti.com>, Tom Rini <trini@konsulko.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	Peter Geis <pgwipeout@gmail.com>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	huang lin <hl@rock-chips.com>,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Simon Glass <sjg@chromium.org>,
	Kever Yang <kever.yang@rock-chips.com>,
	Philipp Tomsich <philipp.tomsich@theobroma-systems.com>,
	Ivan Mikhaylov <ivan.mikhaylov@siemens.com>,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>,
	Philippe Reynes <philippe.reynes@softathome.com>
Subject: [PATCH v9 01/14] binman: Allow writing section contents to a file
Date: Sat,  7 Jan 2023 14:07:08 -0700	[thread overview]
Message-ID: <20230107210721.478062-2-sjg@chromium.org> (raw)
In-Reply-To: <20230107210721.478062-1-sjg@chromium.org>

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 <sjg@chromium.org>
---

(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 69e4b00239c..2899e1c7833 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 {
+			};
+		};
+	};
+};
-- 
2.39.0.314.g84b9a713c41-goog


  reply	other threads:[~2023-01-07 21:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 21:07 [PATCH v9 00/14] binman: rockchip: Migrate from rockchip SPL_FIT_GENERATOR script Simon Glass
2023-01-07 21:07 ` Simon Glass [this message]
2023-01-07 21:07 ` [PATCH v9 02/14] binman: Tidy up comment in fit _gen_node Simon Glass
2023-01-07 21:07 ` [PATCH v9 03/14] binman: Update entry docs Simon Glass
2023-01-07 21:07 ` [PATCH v9 04/14] binman: Use a reference for binman symbols docs Simon Glass
2023-01-07 21:07 ` [PATCH v9 05/14] binman: Support optional entries Simon Glass
2023-01-07 21:07 ` [PATCH v9 06/14] binman: Add a way to check for a valid ELF file Simon Glass
2023-01-07 21:07 ` [PATCH v9 07/14] binman: Support new op-tee binary format Simon Glass
2023-01-07 21:07 ` [PATCH v9 08/14] binman: Support optional external blobs Simon Glass
2023-01-07 21:07 ` [PATCH v9 09/14] rockchip: evb-rk3288: Drop raw-image support Simon Glass
2023-01-07 21:07 ` [PATCH v9 10/14] rockchip: Use multiple-images for rk3399 Simon Glass
2023-01-07 21:07 ` [PATCH v9 11/14] rockchip: Support building the all output files in binman Simon Glass
2023-01-07 21:07 ` [PATCH v9 12/14] rockchip: Convert all boards to use binman Simon Glass
2023-01-07 21:07 ` [PATCH v9 13/14] rockchip: Drop the FIT generator script Simon Glass
2023-01-07 21:07 ` [PATCH v9 14/14] treewide: Disable USE_SPL_FIT_GENERATOR by default Simon Glass
2023-01-08 13:41   ` Tom Rini
2023-01-08 15:48     ` Simon Glass
2023-01-08 16:06       ` Tom Rini
2023-01-08 16:20         ` Simon Glass
2023-01-08 16:24           ` Tom Rini
2023-01-08 19:36             ` Simon Glass
2023-01-09  8:56               ` Luca Ceresoli
2023-01-09 14:13                 ` Tom Rini
2023-01-09 14:29                   ` Michal Simek
2023-01-09 11:07               ` Michal Simek
2023-01-09 14:12                 ` Tom Rini
2023-01-09 14:37                   ` Michal Simek
2023-01-09 15:05                     ` Tom Rini
2023-01-09 15:34                 ` Simon Glass
2023-01-10 15:16                   ` Michal Simek
2023-01-15 16:31                     ` Simon Glass
2023-01-16 10:25                       ` Michal Simek
2023-01-09 18:55               ` Tom Rini
2023-01-19  2:11 ` [PATCH v9 12/14] rockchip: Convert all boards to use binman Simon Glass
2023-01-19  2:11 ` [PATCH v9 08/14] binman: Support optional external blobs Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230107210721.478062-2-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=alpernebiyasak@gmail.com \
    --cc=hl@rock-chips.com \
    --cc=ivan.mikhaylov@siemens.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=jerome.forissier@linaro.org \
    --cc=kever.yang@rock-chips.com \
    --cc=pgwipeout@gmail.com \
    --cc=philipp.tomsich@theobroma-systems.com \
    --cc=philippe.reynes@softathome.com \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=rogerq@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.