]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Support alignment of files
authorSimon Glass <sjg@chromium.org>
Thu, 7 Jan 2021 04:35:18 +0000 (21:35 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 30 Jan 2021 21:25:41 +0000 (14:25 -0700)
When packing files it is sometimes useful to align the start of each file,
e.g. if the flash driver can only access 32-bit-aligned data. Provides a
new property to support this.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/etype/files.py
tools/binman/ftest.py
tools/binman/state.py
tools/binman/test/084_files.dts
tools/binman/test/190_files_align.dts [new file with mode: 0644]
tools/dtoc/fdt.py
tools/dtoc/test_fdt.py

index ce3832e3cddbc1742a85e35d5c38f65f81f40b20..1feebd0510e479a8f271ed8b2c38586e7340f63a 100644 (file)
@@ -22,6 +22,7 @@ class Entry_files(Entry_section):
         - files-compress: Compression algorithm to use:
             none: No compression
             lz4: Use lz4 compression (via 'lz4' command-line utility)
+        - files-align: Align each file to the given alignment
 
     This entry reads a number of files and places each in a separate sub-entry
     within this entry. To access these you need to enable device-tree updates
@@ -38,6 +39,7 @@ class Entry_files(Entry_section):
             self.Raise("Missing 'pattern' property")
         self._files_compress = fdt_util.GetString(self._node, 'files-compress',
                                                   'none')
+        self._files_align = fdt_util.GetInt(self._node, 'files-align');
         self._require_matches = fdt_util.GetBool(self._node,
                                                 'require-matches')
 
@@ -55,6 +57,8 @@ class Entry_files(Entry_section):
             state.AddString(subnode, 'type', 'blob')
             state.AddString(subnode, 'filename', fname)
             state.AddString(subnode, 'compress', self._files_compress)
+            if self._files_align:
+                state.AddInt(subnode, 'align', self._files_align)
 
         # Read entries again, now that we have some
         self._ReadEntries()
index 7f7827b6a7d977b54d5705a30d196703b16a75b9..b31a7305a33f2b562c13353d222ba34fcdbfd046 100644 (file)
@@ -4218,6 +4218,14 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(orig_image.GetEntries().keys(),
                          image.GetEntries().keys())
 
+    def testFilesAlign(self):
+        """Test alignment with files"""
+        data = self._DoReadFile('190_files_align.dts')
+
+        # The first string is 15 bytes so will align to 16
+        expect = FILES_DATA[:15] + b'\0' + FILES_DATA[15:]
+        self.assertEqual(expect, data)
+
 
 if __name__ == "__main__":
     unittest.main()
index 36bc5135354f49799fa3d8cf337bf0fcd5fcd52a..bb3e36ea7afb84218ebb8245fb731a2836ac13df 100644 (file)
@@ -314,6 +314,16 @@ def AddString(node, prop, value):
     for n in GetUpdateNodes(node):
         n.AddString(prop, value)
 
+def AddInt(node, prop, value):
+    """Add a new string property to affected device trees
+
+    Args:
+        prop_name: Name of property
+        val: Integer value of property
+    """
+    for n in GetUpdateNodes(node):
+        n.AddInt(prop, value)
+
 def SetInt(node, prop, value, for_repack=False):
     """Update an integer property in affected device trees with an integer value
 
index 83ddb78f8e7b48611a50170b6c01812d9d507530..8f09afd24ea8b9425f9889e3523a507e53251d90 100644 (file)
@@ -5,7 +5,7 @@
        binman {
                files {
                        pattern = "files/*.dat";
-                       compress = "none";
+                       files-compress = "none";
                };
        };
 };
diff --git a/tools/binman/test/190_files_align.dts b/tools/binman/test/190_files_align.dts
new file mode 100644 (file)
index 0000000..213ba96
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/dts-v1/;
+
+/ {
+       binman {
+               files {
+                       pattern = "files/*.dat";
+                       files-compress = "none";
+                       files-align = <4>;
+               };
+       };
+};
index 965106a3b28a294eca849443273bea8290c9c90a..25ce5136ebff5871a2e106e45339d2ce7c1b363e 100644 (file)
@@ -463,6 +463,18 @@ class Node:
         val = bytes(val, 'utf-8')
         self.AddData(prop_name, val + b'\0')
 
+    def AddInt(self, prop_name, val):
+        """Add a new integer property to a node
+
+        The device tree is marked dirty so that the value will be written to
+        the blob on the next sync.
+
+        Args:
+            prop_name: Name of property to add
+            val: Integer value of property
+        """
+        self.AddData(prop_name, struct.pack('>I', val))
+
     def AddSubnode(self, name):
         """Add a new subnode to the node
 
index dc6943f73373a85c355f884ae23358617446eac9..e8fbbd5d10aa987e40a85d33221dd3fcea2b144e 100755 (executable)
@@ -397,6 +397,12 @@ class TestProp(unittest.TestCase):
         data = self.fdt.getprop(self.node.Offset(), 'one')
         self.assertEqual(1, fdt32_to_cpu(data))
 
+        val = 1234
+        self.node.AddInt('integer', val)
+        self.dtb.Sync(auto_resize=True)
+        data = self.fdt.getprop(self.node.Offset(), 'integer')
+        self.assertEqual(val, fdt32_to_cpu(data))
+
         val = '123' + chr(0) + '456'
         self.node.AddString('string', val)
         self.dtb.Sync(auto_resize=True)