]> git.baikalelectronics.ru Git - uboot.git/commitdiff
binman: Allow writing section contents to a file
authorSimon Glass <sjg@chromium.org>
Sat, 7 Jan 2023 21:07:08 +0000 (14:07 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 18 Jan 2023 18:50:01 +0000 (11:50 -0700)
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>
tools/binman/binman.rst
tools/binman/etype/section.py
tools/binman/ftest.py
tools/binman/image.py
tools/binman/test/261_section_fname.dts [new file with mode: 0644]

index 69e4b00239c188fc6cd1f9bc14fa0b49ae20f056..2899e1c7833622f5d2edb1d8f4ac93dc6f11e122 100644 (file)
@@ -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
 ----------------
index da561e2bcc7453184b382799c2cd73be286e0c24..305155c8461c3dc439d933abec60be2a959fcf35 100644 (file)
@@ -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):
index 62ee86b9b75e349d895724ea0e46e049a622afeb..c3cb32dca26d676cdd469a616a503bb12357b7ce 100644 (file)
@@ -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()
index 6d4bff584363d9b5d7c25af6f3c01aed3cf81079..b84dd21e22af4cfbc9a2846f510ef911e8d9ccff 100644 (file)
@@ -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 (file)
index 0000000..790381e
--- /dev/null
@@ -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 {
+                       };
+               };
+       };
+};