[U-Boot,04/34] binman: Allow use of help and entry-docs without libfdt
diff mbox series

Message ID 20190824132315.53130-5-sjg@chromium.org
State New
Delegated to: Simon Glass
Headers show
Series
  • binman: Various improvements and tidy-ups
Related show

Commit Message

Simon Glass Aug. 24, 2019, 1:22 p.m. UTC
At present if libfdt is not available binman can't do anything much.
Improve the situation a little.

Ideally there should be a test to cover this, but I'm not quite sure how
to fake this.

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

 tools/binman/control.py                     | 10 ++++++++--
 tools/binman/entry.py                       |  5 ++++-
 tools/binman/etype/blob.py                  |  1 -
 tools/binman/etype/blob_dtb.py              |  6 ++++--
 tools/binman/etype/cbfs.py                  |  5 ++++-
 tools/binman/etype/fdtmap.py                | 13 +++++++++----
 tools/binman/etype/files.py                 |  5 ++++-
 tools/binman/etype/u_boot_dtb_with_ucode.py |  5 ++++-
 8 files changed, 37 insertions(+), 13 deletions(-)

Patch
diff mbox series

diff --git a/tools/binman/control.py b/tools/binman/control.py
index 9e7587864c..43f5d49406 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -15,8 +15,6 @@  import tools
 import cbfs_util
 import command
 import elf
-from image import Image
-import state
 import tout
 
 # List of images we plan to create
@@ -459,6 +457,10 @@  def Binman(args):
     Args:
         args: Command line arguments Namespace object
     """
+    # Put these here so that we can import this module without libfdt
+    global state
+    global Image
+
     if args.full_help:
         pager = os.getenv('PAGER')
         if not pager:
@@ -468,6 +470,10 @@  def Binman(args):
         command.Run(pager, fname)
         return 0
 
+    # Put these here so that we can import this module without libfdt
+    from image import Image
+    import state
+
     if args.cmd == 'ls':
         try:
             tools.PrepareOutputDir(None)
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 6a2c6e0d92..04c26f9e50 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -21,7 +21,6 @@  import os
 import sys
 
 import fdt_util
-import state
 import tools
 from tools import ToHex, ToHexSize
 import tout
@@ -71,6 +70,10 @@  class Entry(object):
         orig_size: Original size value read from node
     """
     def __init__(self, section, etype, node, name_prefix=''):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        import state
+
         self.section = section
         self.etype = etype
         self._node = node
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index d15d0789e5..d34c7b51bf 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -7,7 +7,6 @@ 
 
 from entry import Entry
 import fdt_util
-import state
 import tools
 import tout
 
diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py
index 5b559967d7..b2afa064c1 100644
--- a/tools/binman/etype/blob_dtb.py
+++ b/tools/binman/etype/blob_dtb.py
@@ -5,8 +5,6 @@ 
 # Entry-type module for U-Boot device tree files
 #
 
-import state
-
 from entry import Entry
 from blob import Entry_blob
 
@@ -18,6 +16,10 @@  class Entry_blob_dtb(Entry_blob):
     'state' module.
     """
     def __init__(self, section, etype, node):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        import state
+
         Entry_blob.__init__(self, section, etype, node)
 
     def ObtainContents(self):
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 28a9c81a8a..35b78370b2 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -11,7 +11,6 @@  import cbfs_util
 from cbfs_util import CbfsWriter
 from entry import Entry
 import fdt_util
-import state
 
 class Entry_cbfs(Entry):
     """Entry containing a Coreboot Filesystem (CBFS)
@@ -164,6 +163,10 @@  class Entry_cbfs(Entry):
     both of size 1MB.
     """
     def __init__(self, section, etype, node):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        import state
+
         Entry.__init__(self, section, etype, node)
         self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
         self._cbfs_entries = OrderedDict()
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index b1810b9ddb..5dc08b8289 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -8,11 +8,7 @@  This handles putting an FDT into the image with just the information about the
 image.
 """
 
-import libfdt
-
 from entry import Entry
-from fdt import Fdt
-import state
 import tools
 import tout
 
@@ -80,6 +76,15 @@  class Entry_fdtmap(Entry):
     added as necessary. See the binman README.
     """
     def __init__(self, section, etype, node):
+        # Put these here to allow entry-docs and help to work without libfdt
+        global libfdt
+        global state
+        global Fdt
+
+        import libfdt
+        import state
+        from fdt import Fdt
+
         Entry.__init__(self, section, etype, node)
 
     def _GetFdtmap(self):
diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py
index 0068b305f7..3473a2b1ef 100644
--- a/tools/binman/etype/files.py
+++ b/tools/binman/etype/files.py
@@ -11,7 +11,6 @@  import os
 
 from section import Entry_section
 import fdt_util
-import state
 import tools
 
 
@@ -29,6 +28,10 @@  class Entry_files(Entry_section):
     at run-time so you can obtain the file positions.
     """
     def __init__(self, section, etype, node):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        import state
+
         Entry_section.__init__(self, section, etype, node)
         self._pattern = fdt_util.GetString(self._node, 'pattern')
         if not self._pattern:
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index cb6c3730d7..6efd24a9b3 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/tools/binman/etype/u_boot_dtb_with_ucode.py
@@ -7,7 +7,6 @@ 
 
 from entry import Entry
 from blob_dtb import Entry_blob_dtb
-import state
 import tools
 
 class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
@@ -25,6 +24,10 @@  class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
     it available to u_boot_ucode.
     """
     def __init__(self, section, etype, node):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        import state
+
         Entry_blob_dtb.__init__(self, section, etype, node)
         self.ucode_data = b''
         self.collate = False