All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 08/21] binman: Allow using an an 'expanded' entry type
Date: Mon, 15 Mar 2021 20:26:13 +1300	[thread overview]
Message-ID: <20210315072627.2101110-9-sjg@chromium.org> (raw)
In-Reply-To: <20210315072627.2101110-1-sjg@chromium.org>

As the first step in supporting expanded entries, add a way for binman to
automatically select an 'expanded' version of an entry type, if requested.
This is controlled by a class method.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 tools/binman/entry.py      | 60 ++++++++++++++++++++++++++++++++------
 tools/binman/entry_test.py | 12 ++++++++
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 507760e2a86..1651a38255e 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -102,22 +102,30 @@ class Entry(object):
         self.allow_missing = False
 
     @staticmethod
-    def Lookup(node_path, etype):
+    def Lookup(node_path, etype, expanded):
         """Look up the entry class for a node.
 
         Args:
             node_node: Path name of Node object containing information about
                        the entry to create (used for errors)
             etype:   Entry type to use
+            expanded: Use the expanded version of etype
 
         Returns:
-            The entry class object if found, else None
+            The entry class object if found, else None if not found and expanded
+                is True
+
+        Raise:
+            ValueError if expanded is False and the class is not found
         """
         # Convert something like 'u-boot at 0' to 'u_boot' since we are only
         # interested in the type.
         module_name = etype.replace('-', '_')
+
         if '@' in module_name:
             module_name = module_name.split('@')[0]
+        if expanded:
+            module_name += '_expanded'
         module = modules.get(module_name)
 
         # Also allow entry-type modules to be brought in from the etype directory.
@@ -127,6 +135,8 @@ class Entry(object):
             try:
                 module = importlib.import_module('binman.etype.' + module_name)
             except ImportError as e:
+                if expanded:
+                    return None
                 raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
                                  (etype, node_path, module_name, e))
             modules[module_name] = module
@@ -135,21 +145,31 @@ class Entry(object):
         return getattr(module, 'Entry_%s' % module_name)
 
     @staticmethod
-    def Create(section, node, etype=None):
+    def Create(section, node, etype=None, expanded=False):
         """Create a new entry for a node.
 
         Args:
-            section: Section object containing this node
-            node:    Node object containing information about the entry to
-                     create
-            etype:   Entry type to use, or None to work it out (used for tests)
+            section:  Section object containing this node
+            node:     Node object containing information about the entry to
+                      create
+            etype:    Entry type to use, or None to work it out (used for tests)
+            expanded: True to use expanded versions of entries, where available
 
         Returns:
             A new Entry object of the correct type (a subclass of Entry)
         """
         if not etype:
             etype = fdt_util.GetString(node, 'type', node.name)
-        obj = Entry.Lookup(node.path, etype)
+        obj = Entry.Lookup(node.path, etype, expanded)
+        if obj and expanded:
+            # Check whether to use the expanded entry
+            new_etype = etype + '-expanded'
+            if obj.UseExpanded(node, etype, new_etype):
+                etype = new_etype
+            else:
+                obj = None
+        if not obj:
+            obj = Entry.Lookup(node.path, etype, False)
 
         # Call its constructor to get the object we want.
         return obj(section, etype, node)
@@ -648,7 +668,7 @@ features to produce new behaviours.
             modules.remove('_testing')
         missing = []
         for name in modules:
-            module = Entry.Lookup('WriteDocs', name)
+            module = Entry.Lookup('WriteDocs', name, False)
             docs = getattr(module, '__doc__')
             if test_missing == name:
                 docs = None
@@ -907,3 +927,25 @@ features to produce new behaviours.
             self.uncomp_size = len(indata)
         data = tools.Compress(indata, self.compress)
         return data
+
+    @classmethod
+    def UseExpanded(cls, node, etype, new_etype):
+        """Check whether to use an expanded entry type
+
+        This is called by Entry.Create() when it finds an expanded version of
+        an entry type (e.g. 'u-boot-expanded'). If this method returns True then
+        it will be used (e.g. in place of 'u-boot'). If it returns False, it is
+        ignored.
+
+        Args:
+            node:     Node object containing information about the entry to
+                      create
+            etype:    Original entry type being used
+            new_etype: New entry type proposed
+
+        Returns:
+            True to use this entry type, False to use the original one
+        """
+        tout.Info("Node '%s': etype '%s': %s selected" %
+                  (node.path, etype, new_etype))
+        return True
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index 80802f33de6..c3d5f3eef48 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -87,6 +87,18 @@ class TestEntry(unittest.TestCase):
         base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
         self.assertIsNone(base.ReadChildData(base))
 
+    def testExpandedEntry(self):
+        """Test use of an expanded entry when available"""
+        base = entry.Entry.Create(None, self.GetNode())
+        self.assertEqual('u-boot', base.etype)
+
+        expanded = entry.Entry.Create(None, self.GetNode(), expanded=True)
+        self.assertEqual('u-boot-expanded', expanded.etype)
+
+        with self.assertRaises(ValueError) as e:
+            entry.Entry.Create(None, self.GetNode(), 'missing', expanded=True)
+        self.assertIn("Unknown entry type 'missing' in node '/binman/u-boot'",
+                      str(e.exception))
 
 if __name__ == "__main__":
     unittest.main()
-- 
2.31.0.rc2.261.g7f71774620-goog

  parent reply	other threads:[~2021-03-15  7:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  7:26 [PATCH v2 00/21] binman: Support devicetree update in all entries Simon Glass
2021-03-15  7:26 ` [PATCH v2 01/21] binman: Allow extracting to current directory Simon Glass
2021-03-15  7:26 ` [PATCH v2 02/21] binman: Document ExpandEntries() in the base class Simon Glass
2021-03-15  7:26 ` [PATCH v2 03/21] binman: Update entry help for files-align Simon Glass
2021-03-15  7:26 ` [PATCH v2 04/21] binman: Tidy up underscores in entry documentation Simon Glass
2021-03-15  7:26 ` [PATCH v2 05/21] binman: Correct the documentation for u-boot-spl-bss-pad Simon Glass
2021-03-15  7:26 ` [PATCH v2 06/21] binman: Add support for u-boot-tpl-nodtb Simon Glass
2021-03-15  7:26 ` [PATCH v2 07/21] binman: Add support for u-boot-tpl-bss-bad Simon Glass
2021-03-15  7:26 ` Simon Glass [this message]
2021-03-15  7:26 ` [PATCH v2 09/21] binman: Allow a way to select expanded entries Simon Glass
2021-03-15  7:26 ` [PATCH v2 10/21] binman: Plumb expanded entries through fully Simon Glass
2021-03-15  7:26 ` [PATCH v2 11/21] binman: Automatically expand phase binaries into sections Simon Glass
2021-03-15  7:26 ` [PATCH v2 12/21] Makefile: Pass new entry args to binman Simon Glass
2021-03-15  7:26 ` [PATCH v2 13/21] x86: Make use of binman expanded entries Simon Glass
2021-03-15  7:26 ` [PATCH v2 14/21] x86: dts: Drop unused CONFIG_SPL Simon Glass
2021-03-15  7:26 ` [PATCH v2 15/21] doc: Move UEFI under develop/ Simon Glass
2021-03-17  7:46   ` Heinrich Schuchardt
2021-03-18  6:36     ` Simon Glass
2021-03-15  7:26 ` [PATCH v2 16/21] doc: Move driver model docs " Simon Glass
2021-03-15  7:26 ` [PATCH v2 17/21] binman: doc: Add documentation to htmldocs Simon Glass
2021-03-15  7:26 ` [PATCH v2 18/21] binman: Rearrange documentation into headings Simon Glass
2021-03-15  7:26 ` [PATCH v2 19/21] binman: Incorporate entry documentation Simon Glass
2021-03-15  7:26 ` [PATCH v2 20/21] binman: Drop repetitive heading for each entry Simon Glass
2021-03-15  7:26 ` [PATCH v2 21/21] binman: Update various pieces of the documentation Simon Glass
2021-03-17  1:29 ` Simon Glass
2021-03-17  1:29 ` [PATCH v2 20/21] binman: Drop repetitive heading for each entry Simon Glass
2021-03-17  1:29 ` [PATCH v2 19/21] binman: Incorporate entry documentation Simon Glass
2021-03-17  1:29 ` [PATCH v2 18/21] binman: Rearrange documentation into headings Simon Glass
2021-03-17  1:29 ` [PATCH v2 17/21] binman: doc: Add documentation to htmldocs Simon Glass
2021-03-17  1:29 ` [PATCH v2 16/21] doc: Move driver model docs under develop/ Simon Glass
2021-03-17  1:29 ` [PATCH v2 15/21] doc: Move UEFI " Simon Glass
2021-03-17  1:29 ` [PATCH v2 14/21] x86: dts: Drop unused CONFIG_SPL Simon Glass
2021-03-17  1:29 ` [PATCH v2 13/21] x86: Make use of binman expanded entries Simon Glass
2021-03-17  1:29 ` [PATCH v2 12/21] Makefile: Pass new entry args to binman Simon Glass
2021-03-17  1:29 ` [PATCH v2 11/21] binman: Automatically expand phase binaries into sections Simon Glass
2021-03-17  1:29 ` [PATCH v2 10/21] binman: Plumb expanded entries through fully Simon Glass
2021-03-17  1:29 ` [PATCH v2 09/21] binman: Allow a way to select expanded entries Simon Glass
2021-03-17  1:29 ` [PATCH v2 08/21] binman: Allow using an an 'expanded' entry type Simon Glass
2021-03-17  1:30 ` [PATCH v2 07/21] binman: Add support for u-boot-tpl-bss-bad Simon Glass
2021-03-17  1:30 ` [PATCH v2 06/21] binman: Add support for u-boot-tpl-nodtb Simon Glass
2021-03-17  1:30 ` [PATCH v2 05/21] binman: Correct the documentation for u-boot-spl-bss-pad Simon Glass
2021-03-17  1:30 ` [PATCH v2 04/21] binman: Tidy up underscores in entry documentation Simon Glass
2021-03-17  1:30 ` [PATCH v2 03/21] binman: Update entry help for files-align Simon Glass
2021-03-17  1:30 ` [PATCH v2 02/21] binman: Document ExpandEntries() in the base class Simon Glass
2021-03-17  1:30 ` [PATCH v2 01/21] binman: Allow extracting to current directory 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=20210315072627.2101110-9-sjg@chromium.org \
    --to=sjg@chromium.org \
    --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.