]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Add support for adding a name prefix to entries
authorSimon Glass <sjg@chromium.org>
Fri, 1 Jun 2018 15:38:21 +0000 (09:38 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 7 Jun 2018 19:25:08 +0000 (11:25 -0800)
Sometimes we have several sections which repeat the same entries (e.g. for
a read-only and read-write version of the same section). It is useful to
be able to tell these entries apart by name.

Add a new 'name-prefix' property for sections, which causes all entries
within that section to have a given name prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/README
tools/binman/bsection.py
tools/binman/entry.py
tools/binman/ftest.py
tools/binman/test/56_name_prefix.dts [new file with mode: 0644]

index 64e529f06b9167f97ab20d10ec27420556b91f64..42ed4448bc2526b8f23ce7e121c747ab15b0f200 100644 (file)
@@ -417,11 +417,13 @@ and can be programmed:
        binman {
                section@0 {
                        read-only;
+                       name-prefix = "ro-";
                        size = <0x100000>;
                        u-boot {
                        };
                };
                section@1 {
+                       name-prefix = "rw-";
                        size = <0x100000>;
                        u-boot {
                        };
@@ -437,6 +439,12 @@ read-only:
        Indicates that this section is read-only. This has no impact on binman's
        operation, but his property can be read at run time.
 
+name-prefix:
+       This string is prepended to all the names of the binaries in the
+       section. In the example above, the 'u-boot' binaries which actually be
+       renamed to 'ro-u-boot' and 'rw-u-boot'. This can be useful to
+       distinguish binaries with otherwise identical names.
+
 
 Special properties
 ------------------
index e0960d40784115db7a6c56e5884ebb3b1d8d6df7..3f30f6e4fe7da30c3191a886db05ff955a68200f 100644 (file)
@@ -41,6 +41,8 @@ class Section(object):
              memory address (like 0xff800000) is the first entry position.
              This causes _skip_at_start to be set to the starting memory
              address.
+        _name_prefix: Prefix to add to the name of all entries within this
+            section
         _entries: OrderedDict() of entries
     """
     def __init__(self, name, node, test=False):
@@ -58,6 +60,7 @@ class Section(object):
         self._sort = False
         self._skip_at_start = 0
         self._end_4gb = False
+        self._name_prefix = ''
         self._entries = OrderedDict()
         if not test:
             self._ReadNode()
@@ -79,10 +82,13 @@ class Section(object):
             self._Raise("Section size must be provided when using end-at-4gb")
         if self._end_4gb:
             self._skip_at_start = 0x100000000 - self._size
+        self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
 
     def _ReadEntries(self):
         for node in self._node.subnodes:
-            self._entries[node.name] = Entry.Create(self, node)
+            entry = Entry.Create(self, node)
+            entry.SetPrefix(self._name_prefix)
+            self._entries[node.name] = entry
 
     def CheckSize(self):
         """Check that the section contents does not exceed its size, etc."""
index 3811d33e4203f30c0e5723381924a7e401e1b99d..e4d688c91f9aa54c27331b80dccb5f2074edd6de 100644 (file)
@@ -48,11 +48,11 @@ class Entry(object):
         pad_after: Number of pad bytes after the contents, 0 if none
         data: Contents of entry (string of bytes)
     """
-    def __init__(self, section, etype, node, read_node=True):
+    def __init__(self, section, etype, node, read_node=True, name_prefix=''):
         self.section = section
         self.etype = etype
         self._node = node
-        self.name = node and node.name or 'none'
+        self.name = node and (name_prefix + node.name) or 'none'
         self.pos = None
         self.size = None
         self.contents_size = 0
@@ -129,6 +129,15 @@ class Entry(object):
         self.align_end = fdt_util.GetInt(self._node, 'align-end')
         self.pos_unset = fdt_util.GetBool(self._node, 'pos-unset')
 
+    def SetPrefix(self, prefix):
+        """Set the name prefix for a node
+
+        Args:
+            prefix: Prefix to set, or '' to not use a prefix
+        """
+        if prefix:
+            self.name = prefix + self.name
+
     def ObtainContents(self):
         """Figure out the contents of an entry.
 
index 61bbb53f8c3ca2b591d96d28368c15f8ef2c0b89..eb8a0793cbe1f4c77bd2928ad3406c41b3800989 100644 (file)
@@ -950,5 +950,15 @@ class TestFunctional(unittest.TestCase):
  00000000  00000004  u-boot
 ''', map_data)
 
+    def testNamePrefix(self):
+        """Tests that name prefixes are used"""
+        _, _, map_data = self._DoReadFileDtb('56_name_prefix.dts', map=True)
+        self.assertEqual('''Position      Size  Name
+00000000  00000010  section@0
+ 00000000  00000004  ro-u-boot
+00000010  00000010  section@1
+ 00000000  00000004  rw-u-boot
+''', map_data)
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/56_name_prefix.dts b/tools/binman/test/56_name_prefix.dts
new file mode 100644 (file)
index 0000000..f38c80e
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               pad-byte = <0x26>;
+               size = <0x28>;
+               section@0 {
+                       read-only;
+                       name-prefix = "ro-";
+                       size = <0x10>;
+                       pad-byte = <0x21>;
+
+                       u-boot {
+                       };
+               };
+               section@1 {
+                       name-prefix = "rw-";
+                       size = <0x10>;
+                       pad-byte = <0x61>;
+
+                       u-boot {
+                       };
+               };
+       };
+};