[PATCH 4/9] binman: Correct pylint errors

Simon Glass sjg at chromium.org
Fri Feb 11 21:23:21 CET 2022


Fix pylint errors that can be fixed and mask those that seem to be
incorrect.

A complication with binman is that it tries to avoid importing libfdt
(or anything that imports it) unless needed, so that things like help
still work if it is missing.

Note that two tests are duplicated in binman and two others have
duplicate names, so both of these issues are fixed also.

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

 tools/binman/cmdline.py                     |  2 +-
 tools/binman/control.py                     |  6 ++++++
 tools/binman/elf_test.py                    | 13 ++++++-------
 tools/binman/entry.py                       |  2 ++
 tools/binman/entry_test.py                  |  7 ++-----
 tools/binman/etype/blob_dtb.py              |  3 +++
 tools/binman/etype/blob_phase.py            |  3 +++
 tools/binman/etype/cbfs.py                  |  3 +++
 tools/binman/etype/fdtmap.py                |  5 +++++
 tools/binman/etype/files.py                 |  2 ++
 tools/binman/etype/section.py               |  1 +
 tools/binman/etype/u_boot_dtb_with_ucode.py |  3 +++
 tools/binman/ftest.py                       | 21 ++-------------------
 13 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 0626b850f4..1d1ca43993 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -7,7 +7,7 @@
 
 import argparse
 from argparse import ArgumentParser
-import state
+from binman import state
 
 def make_extract_parser(subparsers):
     """make_extract_parser: Make a subparser for the 'extract' command
diff --git a/tools/binman/control.py b/tools/binman/control.py
index a179f78129..c9d7a08bbc 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -20,6 +20,10 @@ from binman import elf
 from patman import command
 from patman import tout
 
+# These are imported if needed since they import libfdt
+state = None
+Image = None
+
 # List of images we plan to create
 # Make this global so that it can be referenced from tests
 images = OrderedDict()
@@ -41,6 +45,8 @@ def _ReadImageDesc(binman_node, use_expanded):
     Returns:
         OrderedDict of Image objects, each of which describes an image
     """
+    # For Image()
+    # pylint: disable=E1102
     images = OrderedDict()
     if 'multiple-images' in binman_node.props:
         for node in binman_node.subnodes:
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 47ebfbac4a..75b6dc8d73 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -116,7 +116,7 @@ class TestElf(unittest.TestCase):
         entry = FakeEntry(10)
         section = FakeSection()
         with self.assertRaises(ValueError) as e:
-            syms = elf.LookupAndWriteSymbols('missing-file', entry, section)
+            elf.LookupAndWriteSymbols('missing-file', entry, section)
         self.assertIn("Filename 'missing-file' not found in input path",
                       str(e.exception))
 
@@ -126,7 +126,7 @@ class TestElf(unittest.TestCase):
         section = FakeSection()
         elf_fname = self.ElfTestFile('u_boot_binman_syms')
         with self.assertRaises(ValueError) as e:
-            syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
+            elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertIn('entry_path has offset 4 (size 8) but the contents size '
                       'is a', str(e.exception))
 
@@ -139,8 +139,7 @@ class TestElf(unittest.TestCase):
         entry = FakeEntry(10)
         section = FakeSection()
         elf_fname = self.ElfTestFile('u_boot_binman_syms_bad')
-        self.assertEqual(elf.LookupAndWriteSymbols(elf_fname, entry, section),
-                         None)
+        elf.LookupAndWriteSymbols(elf_fname, entry, section)
 
     def testBadSymbolSize(self):
         """Test that an attempt to use an 8-bit symbol are detected
@@ -152,7 +151,7 @@ class TestElf(unittest.TestCase):
         section = FakeSection()
         elf_fname =self.ElfTestFile('u_boot_binman_syms_size')
         with self.assertRaises(ValueError) as e:
-            syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
+            elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertIn('has size 1: only 4 and 8 are supported',
                       str(e.exception))
 
@@ -165,7 +164,7 @@ class TestElf(unittest.TestCase):
         entry = FakeEntry(24)
         section = FakeSection(sym_value=None)
         elf_fname = self.ElfTestFile('u_boot_binman_syms')
-        syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
+        elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertEqual(tools.get_bytes(255, 20) + tools.get_bytes(ord('a'), 4),
                                                                   entry.data)
 
@@ -177,7 +176,7 @@ class TestElf(unittest.TestCase):
             section = FakeSection()
             elf_fname = self.ElfTestFile('u_boot_binman_syms')
             with test_util.capture_sys_output() as (stdout, stderr):
-                syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
+                elf.LookupAndWriteSymbols(elf_fname, entry, section)
             self.assertTrue(len(stdout.getvalue()) > 0)
         finally:
             tout.init(tout.WARNING)
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index dc26f8f167..9809288ffa 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -19,6 +19,8 @@ from patman import tout
 
 modules = {}
 
+# This is imported if needed
+state = None
 
 # An argument which can be passed to entries on the command line, in lieu of
 # device-tree properties.
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index 7ed9b262bb..1d60076be1 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -5,6 +5,7 @@
 # Test for the Entry class
 
 import collections
+import importlib
 import os
 import sys
 import unittest
@@ -32,11 +33,7 @@ class TestEntry(unittest.TestCase):
     def _ReloadEntry(self):
         global entry
         if entry:
-            if sys.version_info[0] >= 3:
-                import importlib
-                importlib.reload(entry)
-            else:
-                reload(entry)
+            importlib.reload(entry)
         else:
             from binman import entry
 
diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py
index 3ce7511f6f..4159e3032a 100644
--- a/tools/binman/etype/blob_dtb.py
+++ b/tools/binman/etype/blob_dtb.py
@@ -8,6 +8,9 @@
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 
+# This is imported if needed
+state = None
+
 class Entry_blob_dtb(Entry_blob):
     """A blob that holds a device tree
 
diff --git a/tools/binman/etype/blob_phase.py b/tools/binman/etype/blob_phase.py
index ed25e467a1..23e2ad69ba 100644
--- a/tools/binman/etype/blob_phase.py
+++ b/tools/binman/etype/blob_phase.py
@@ -7,6 +7,9 @@
 
 from binman.etype.section import Entry_section
 
+# This is imported if needed
+state = None
+
 class Entry_blob_phase(Entry_section):
     """Section that holds a phase binary
 
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index cc1fbdf4b5..4a1837f26c 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -12,6 +12,9 @@ from binman.cbfs_util import CbfsWriter
 from binman.entry import Entry
 from dtoc import fdt_util
 
+# This is imported if needed
+state = None
+
 class Entry_cbfs(Entry):
     """Coreboot Filesystem (CBFS)
 
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index 76e8dbe818..33c9d039a9 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -15,6 +15,11 @@ from patman import tout
 FDTMAP_MAGIC   = b'_FDTMAP_'
 FDTMAP_HDR_LEN = 16
 
+# These is imported if needed
+Fdt = None
+libfdt = None
+state = None
+
 def LocateFdtmap(data):
     """Search an image for an fdt map
 
diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py
index 0650a69c55..13838ece8f 100644
--- a/tools/binman/etype/files.py
+++ b/tools/binman/etype/files.py
@@ -13,6 +13,8 @@ from binman.etype.section import Entry_section
 from dtoc import fdt_util
 from patman import tools
 
+# This is imported if needed
+state = None
 
 class Entry_files(Entry_section):
     """A set of files arranged in a section
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 25159074ba..639b12d95b 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -163,6 +163,7 @@ class Entry_section(Entry):
         self._sort = False
         self._skip_at_start = None
         self._end_4gb = False
+        self._ignore_missing = False
 
     def ReadNode(self):
         """Read properties from the section node"""
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index 554b3b2e00..047d310cdf 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/tools/binman/etype/u_boot_dtb_with_ucode.py
@@ -9,6 +9,9 @@ from binman.entry import Entry
 from binman.etype.blob_dtb import Entry_blob_dtb
 from patman import tools
 
+# This is imported if needed
+state = None
+
 class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
     """A U-Boot device tree file, with the microcode removed
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 59b6d52fbe..eabfb2a8b7 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -989,7 +989,7 @@ class TestFunctional(unittest.TestCase):
         self.assertIn("Section '/binman': Size 0x7 (7) does not match "
                       "align-size 0x8 (8)", str(e.exception))
 
-    def testPackAlignPowerOf2(self):
+    def testPackAlignPowerOf2Inv(self):
         """Test that invalid image alignment is detected"""
         with self.assertRaises(ValueError) as e:
             self._DoTestFile('020_pack_inv_image_align_power2.dts')
@@ -3712,7 +3712,7 @@ class TestFunctional(unittest.TestCase):
         err = stderr.getvalue()
         self.assertRegex(err, "Image 'main-section'.*missing.*: intel-ifwi")
 
-    def testPackOverlap(self):
+    def testPackOverlapZero(self):
         """Test that zero-size overlapping regions are ignored"""
         self._DoTestFile('160_pack_overlap_zero.dts')
 
@@ -3981,13 +3981,6 @@ class TestFunctional(unittest.TestCase):
         self.assertIn("Generator node requires 'fit,fdt-list' property",
                       str(e.exception))
 
-    def testFitFdtEmptyList(self):
-        """Test handling of an empty 'of-list' entry arg"""
-        entry_args = {
-            'of-list': '',
-        }
-        data = self._DoReadFileDtb('170_fit_fdt.dts', entry_args=entry_args)[0]
-
     def testFitFdtMissing(self):
         """Test handling of a missing 'default-dt' entry arg"""
         entry_args = {
@@ -4872,16 +4865,6 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertEqual('rot-cert', fent.fip_type)
         self.assertEqual(b'aa', fent.data)
 
-    def testFipOther(self):
-        """Basic FIP with something that isn't a external blob"""
-        data = self._DoReadFile('204_fip_other.dts')
-        hdr, fents = fip_util.decode_fip(data)
-
-        self.assertEqual(2, len(fents))
-        fent = fents[1]
-        self.assertEqual('rot-cert', fent.fip_type)
-        self.assertEqual(b'aa', fent.data)
-
     def testFipNoType(self):
         """FIP with an entry of an unknown type"""
         with self.assertRaises(ValueError) as e:
-- 
2.35.1.265.g69c8d7142f-goog



More information about the U-Boot mailing list