[U-Boot] [PATCH 14/31] binman: Move state information into a new module

Simon Glass sjg at chromium.org
Fri Sep 14 10:57:19 UTC 2018


At present the control module has state information in it, since it is the
primary user of this. But it is a bit odd to have entries and other
modules importing control to obtain this information.

It seems better to have a dedicated state module, which control can use as
well. Create a new module using code from control and update other modules
to use it.

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

 tools/binman/control.py                     | 50 +++----------
 tools/binman/entry.py                       |  7 +-
 tools/binman/etype/u_boot_dtb_with_ucode.py |  6 +-
 tools/binman/ftest.py                       |  3 +-
 tools/binman/state.py                       | 77 +++++++++++++++++++++
 5 files changed, 95 insertions(+), 48 deletions(-)
 create mode 100644 tools/binman/state.py

diff --git a/tools/binman/control.py b/tools/binman/control.py
index ded1b71109b..00dcb8ad6a5 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -7,27 +7,19 @@
 
 from collections import OrderedDict
 import os
-import re
 import sys
 import tools
 
 import command
 import elf
 from image import Image
+import state
 import tout
 
 # List of images we plan to create
 # Make this global so that it can be referenced from tests
 images = OrderedDict()
 
-# Records the device-tree files known to binman, keyed by filename (e.g.
-# 'u-boot-spl.dtb')
-fdt_files = {}
-
-# Arguments passed to binman to provide arguments to entries
-entry_args = {}
-
-
 def _ReadImageDesc(binman_node):
     """Read the image descriptions from the /binman node
 
@@ -60,39 +52,15 @@ def _FindBinmanNode(dtb):
             return node
     return None
 
-def GetFdt(fname):
-    """Get the Fdt object for a particular device-tree filename
-
-    Binman keeps track of at least one device-tree file called u-boot.dtb but
-    can also have others (e.g. for SPL). This function looks up the given
-    filename and returns the associated Fdt object.
+def WriteEntryDocs(modules, test_missing=None):
+    """Write out documentation for all entries
 
     Args:
-        fname: Filename to look up (e.g. 'u-boot.dtb').
-
-    Returns:
-        Fdt object associated with the filename
+        modules: List of Module objects to get docs for
+        test_missing: Used for testing only, to force an entry's documeentation
+            to show as missing even if it is present. Should be set to None in
+            normal use.
     """
-    return fdt_files[fname]
-
-def GetFdtPath(fname):
-    return fdt_files[fname]._fname
-
-def SetEntryArgs(args):
-    global entry_args
-
-    entry_args = {}
-    if args:
-        for arg in args:
-            m = re.match('([^=]*)=(.*)', arg)
-            if not m:
-                raise ValueError("Invalid entry arguemnt '%s'" % arg)
-            entry_args[m.group(1)] = m.group(2)
-
-def GetEntryArg(name):
-    return entry_args.get(name)
-
-def WriteEntryDocs(modules, test_missing=None):
     from entry import Entry
     Entry.WriteDocs(modules, test_missing)
 
@@ -141,7 +109,7 @@ def Binman(options, args):
         try:
             tools.SetInputDirs(options.indir)
             tools.PrepareOutputDir(options.outdir, options.preserve)
-            SetEntryArgs(options.entry_arg)
+            state.SetEntryArgs(options.entry_arg)
 
             # Get the device tree ready by compiling it and copying the compiled
             # output into a file in our output directly. Then scan it for use
@@ -154,7 +122,7 @@ def Binman(options, args):
             dtb = fdt.FdtScan(fname)
 
             # Note the file so that GetFdt() can find it
-            fdt_files['u-boot.dtb'] = dtb
+            state.fdt_files['u-boot.dtb'] = dtb
             node = _FindBinmanNode(dtb)
             if not node:
                 raise ValueError("Device tree '%s' does not have a 'binman' "
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index ec3b22e9b31..1d6299aefa5 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -17,10 +17,11 @@ try:
 except:
     have_importlib = False
 
-import fdt_util
-import control
 import os
 import sys
+
+import fdt_util
+import state
 import tools
 
 modules = {}
@@ -393,7 +394,7 @@ class Entry(object):
         Raises:
             ValueError if the argument cannot be converted to in
         """
-        value = control.GetEntryArg(name)
+        value = state.GetEntryArg(name)
         if value is not None:
             if datatype == int:
                 try:
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index 285a28dd1e7..3fab766011e 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/tools/binman/etype/u_boot_dtb_with_ucode.py
@@ -5,9 +5,9 @@
 # Entry-type module for U-Boot device tree with the microcode removed
 #
 
-import control
 from entry import Entry
 from blob import Entry_blob
+import state
 import tools
 
 class Entry_u_boot_dtb_with_ucode(Entry_blob):
@@ -51,7 +51,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
 
         # Remove the microcode
         fname = self.GetDefaultFilename()
-        fdt = control.GetFdt(fname)
+        fdt = state.GetFdt(fname)
         self.ucode = fdt.GetNode('/microcode')
         if not self.ucode:
             raise self.Raise("No /microcode node found in '%s'" % fname)
@@ -70,7 +70,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
     def ObtainContents(self):
         # Call the base class just in case it does something important.
         Entry_blob.ObtainContents(self)
-        self._pathname = control.GetFdtPath(self._filename)
+        self._pathname = state.GetFdtPath(self._filename)
         self.ReadBlobContents()
         if self.ucode:
             for node in self.ucode.subnodes:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 290e9aebf16..867179702d9 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -23,6 +23,7 @@ import fdt
 import fdt_util
 import fmap_util
 import test_util
+import state
 import tools
 import tout
 
@@ -258,7 +259,7 @@ class TestFunctional(unittest.TestCase):
             retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb,
                                        entry_args=entry_args)
             self.assertEqual(0, retcode)
-            out_dtb_fname = control.GetFdtPath('u-boot.dtb')
+            out_dtb_fname = state.GetFdtPath('u-boot.dtb')
 
             # Find the (only) image, read it and return its contents
             image = control.images['image']
diff --git a/tools/binman/state.py b/tools/binman/state.py
new file mode 100644
index 00000000000..6bc24ddf8ac
--- /dev/null
+++ b/tools/binman/state.py
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2018 Google, Inc
+# Written by Simon Glass <sjg at chromium.org>
+#
+# Holds and modifies the state information held by binman
+#
+
+import re
+from sets import Set
+
+import os
+import tools
+
+# Records the device-tree files known to binman, keyed by filename (e.g.
+# 'u-boot-spl.dtb')
+fdt_files = {}
+
+# Arguments passed to binman to provide arguments to entries
+entry_args = {}
+
+def GetFdt(fname):
+    """Get the Fdt object for a particular device-tree filename
+
+    Binman keeps track of at least one device-tree file called u-boot.dtb but
+    can also have others (e.g. for SPL). This function looks up the given
+    filename and returns the associated Fdt object.
+
+    Args:
+        fname: Filename to look up (e.g. 'u-boot.dtb').
+
+    Returns:
+        Fdt object associated with the filename
+    """
+    return fdt_files[fname]
+
+def GetFdtPath(fname):
+    """Get the full pathname of a particular Fdt object
+
+    Similar to GetFdt() but returns the pathname associated with the Fdt.
+
+    Args:
+        fname: Filename to look up (e.g. 'u-boot.dtb').
+
+    Returns:
+        Full path name to the associated Fdt
+    """
+    return fdt_files[fname]._fname
+
+def SetEntryArgs(args):
+    """Set the value of the entry args
+
+    This sets up the entry_args dict which is used to supply entry arguments to
+    entries.
+
+    Args:
+        args: List of entry arguments, each in the format "name=value"
+    """
+    global entry_args
+
+    entry_args = {}
+    if args:
+        for arg in args:
+            m = re.match('([^=]*)=(.*)', arg)
+            if not m:
+                raise ValueError("Invalid entry arguemnt '%s'" % arg)
+            entry_args[m.group(1)] = m.group(2)
+
+def GetEntryArg(name):
+    """Get the value of an entry argument
+
+    Args:
+        name: Name of argument to retrieve
+
+    Returns:
+        String value of argument
+    """
+    return entry_args.get(name)
-- 
2.19.0.397.gdd90340f6a-goog



More information about the U-Boot mailing list