binman: Correct pylint errors
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@chromium.org>
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 0626b85..1d1ca43 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 a179f78..c9d7a08 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -20,6 +20,10 @@
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 @@
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 a67915b..5084838 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -116,7 +116,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 bf68a85..85dc339 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -19,6 +19,8 @@
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 7ed9b26..1d60076 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 @@
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 3ce7511..4159e30 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 ed25e46..23e2ad6 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 cc1fbdf..4a1837f 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -12,6 +12,9 @@
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 76e8dbe..33c9d03 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -15,6 +15,11 @@
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 0650a69..13838ec 100644
--- a/tools/binman/etype/files.py
+++ b/tools/binman/etype/files.py
@@ -13,6 +13,8 @@
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 2515907..639b12d 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -163,6 +163,7 @@
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 554b3b2..047d310 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.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 8f00db6..8d41ab6 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -991,7 +991,7 @@
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')
@@ -3714,7 +3714,7 @@
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')
@@ -4095,13 +4095,6 @@
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 = {
@@ -4986,16 +4979,6 @@
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: