aboutsummaryrefslogtreecommitdiff
path: root/tools/binman
diff options
context:
space:
mode:
Diffstat (limited to 'tools/binman')
-rw-r--r--tools/binman/README14
-rw-r--r--tools/binman/README.entries15
-rwxr-xr-xtools/binman/binman.py26
-rw-r--r--tools/binman/bsection.py7
-rw-r--r--tools/binman/control.py15
-rw-r--r--tools/binman/elf.py4
-rw-r--r--tools/binman/elf_test.py5
-rw-r--r--tools/binman/entry.py5
-rw-r--r--tools/binman/entry_test.py6
-rw-r--r--tools/binman/etype/_testing.py2
-rw-r--r--tools/binman/etype/blob.py2
-rw-r--r--tools/binman/etype/fill.py4
-rw-r--r--tools/binman/etype/fmap.py3
-rw-r--r--tools/binman/etype/gbb.py2
-rw-r--r--tools/binman/etype/text.py9
-rw-r--r--tools/binman/etype/u_boot_dtb_with_ucode.py4
-rw-r--r--tools/binman/etype/u_boot_spl_bss_pad.py2
-rw-r--r--tools/binman/etype/u_boot_ucode.py4
-rw-r--r--tools/binman/etype/vblock.py2
-rw-r--r--tools/binman/fmap_util.py12
-rw-r--r--tools/binman/ftest.py213
-rw-r--r--tools/binman/state.py7
22 files changed, 216 insertions, 147 deletions
diff --git a/tools/binman/README b/tools/binman/README
index 927fa856acf..ac193f16cf7 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -702,6 +702,20 @@ To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
$ sudo apt-get install python-coverage python-pytest
+Concurrent tests
+----------------
+
+Binman tries to run tests concurrently. This means that the tests make use of
+all available CPUs to run.
+
+ To enable this:
+
+ $ sudo apt-get install python-subunit python3-subunit
+
+Use '-P 1' to disable this. It is automatically disabled when code coverage is
+being used (-T) since they are incompatible.
+
+
Advanced Features / Technical docs
----------------------------------
diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 9fc2f83280e..357946d6305 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -224,6 +224,20 @@ See README.x86 for information about x86 binary blobs.
+Entry: intel-refcode: Entry containing an Intel Reference Code file
+-------------------------------------------------------------------
+
+Properties / Entry arguments:
+ - filename: Filename of file to read into entry
+
+This file contains code for setting up the platform on some Intel systems.
+This is executed by U-Boot when needed early during startup. A typical
+filename is 'refcode.bin'.
+
+See README.x86 for information about x86 binary blobs.
+
+
+
Entry: intel-vbt: Entry containing an Intel Video BIOS Table (VBT) file
-----------------------------------------------------------------------
@@ -627,6 +641,7 @@ Entry: vblock: An entry which contains a Chromium OS verified boot block
------------------------------------------------------------------------
Properties / Entry arguments:
+ - content: List of phandles to entries to sign
- keydir: Directory containing the public keys to use
- keyblock: Name of the key file to use (inside keydir)
- signprivate: Name of provide key file to use (inside keydir)
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 439908e6650..aad2e9c8bc4 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -9,6 +9,8 @@
"""See README for more information"""
+from __future__ import print_function
+
import glob
import multiprocessing
import os
@@ -85,13 +87,25 @@ def RunTests(debug, processes, args):
else:
suite.run(result)
- print result
+ # Remove errors which just indicate a missing test. Since Python v3.5 If an
+ # ImportError or AttributeError occurs while traversing name then a
+ # synthetic test that raises that error when run will be returned. These
+ # errors are included in the errors accumulated by result.errors.
+ if test_name:
+ errors = []
+ for test, err in result.errors:
+ if ("has no attribute '%s'" % test_name) not in err:
+ errors.append((test, err))
+ result.testsRun -= 1
+ result.errors = errors
+
+ print(result)
for test, err in result.errors:
- print test.id(), err
+ print(test.id(), err)
for test, err in result.failures:
- print err, result.failures
+ print(err, result.failures)
if result.errors or result.failures:
- print 'binman tests FAILED'
+ print('binman tests FAILED')
return 1
return 0
@@ -143,9 +157,9 @@ def RunBinman(options, args):
try:
ret_code = control.Binman(options, args)
except Exception as e:
- print 'binman: %s' % e
+ print('binman: %s' % e)
if options.debug:
- print
+ print()
traceback.print_exc()
ret_code = 1
return ret_code
diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index 0ba542ee987..03dfa2f805c 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -8,7 +8,6 @@
from __future__ import print_function
from collections import OrderedDict
-from sets import Set
import sys
import fdt_util
@@ -109,7 +108,7 @@ class Section(object):
def GetFdtSet(self):
"""Get the set of device tree files used by this image"""
- fdt_set = Set()
+ fdt_set = set()
for entry in self._entries.values():
fdt_set.update(entry.GetFdtSet())
return fdt_set
@@ -254,7 +253,7 @@ class Section(object):
"""
for entry in self._entries.values():
offset_dict = entry.GetOffsets()
- for name, info in offset_dict.iteritems():
+ for name, info in offset_dict.items():
self._SetEntryOffsetSize(name, *info)
def PackEntries(self):
@@ -333,7 +332,7 @@ class Section(object):
def GetData(self):
"""Get the contents of the section"""
- section_data = chr(self._pad_byte) * self._size
+ section_data = tools.GetBytes(self._pad_byte, self._size)
for entry in self._entries.values():
data = entry.GetData()
diff --git a/tools/binman/control.py b/tools/binman/control.py
index b32e4e1996f..20186ee1980 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -5,6 +5,8 @@
# Creates binary images from input files controlled by a description
#
+from __future__ import print_function
+
from collections import OrderedDict
import os
import sys
@@ -129,12 +131,15 @@ def Binman(options, args):
if options.image:
skip = []
- for name, image in images.iteritems():
- if name not in options.image:
- del images[name]
+ new_images = OrderedDict()
+ for name, image in images.items():
+ if name in options.image:
+ new_images[name] = image
+ else:
skip.append(name)
+ images = new_images
if skip and options.verbosity >= 2:
- print 'Skipping images: %s' % ', '.join(skip)
+ print('Skipping images: %s' % ', '.join(skip))
state.Prepare(images, dtb)
@@ -170,7 +175,7 @@ def Binman(options, args):
except Exception as e:
if options.map:
fname = image.WriteMap()
- print "Wrote map file '%s' to show errors" % fname
+ print("Wrote map file '%s' to show errors" % fname)
raise
image.SetImagePos()
if options.update_fdt:
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 97df8e32c5d..828681d76d0 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -59,7 +59,7 @@ def GetSymbols(fname, patterns):
flags[1] == 'w')
# Sort dict by address
- return OrderedDict(sorted(syms.iteritems(), key=lambda x: x[1].address))
+ return OrderedDict(sorted(syms.items(), key=lambda x: x[1].address))
def GetSymbolAddress(fname, sym_name):
"""Get a value of a symbol from an ELF file
@@ -98,7 +98,7 @@ def LookupAndWriteSymbols(elf_fname, entry, section):
base = syms.get('__image_copy_start')
if not base:
return
- for name, sym in syms.iteritems():
+ for name, sym in syms.items():
if name.startswith('_binman'):
msg = ("Section '%s': Symbol '%s'\n in entry '%s'" %
(section.GetPath(), name, entry.GetPath()))
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index b68530c19ba..42d94cbbbe2 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -22,7 +22,7 @@ class FakeEntry:
"""
def __init__(self, contents_size):
self.contents_size = contents_size
- self.data = 'a' * contents_size
+ self.data = tools.GetBytes(ord('a'), contents_size)
def GetPath(self):
return 'entry_path'
@@ -122,7 +122,8 @@ class TestElf(unittest.TestCase):
section = FakeSection(sym_value=None)
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
- self.assertEqual(chr(255) * 16 + 'a' * 4, entry.data)
+ self.assertEqual(tools.GetBytes(255, 16) + tools.GetBytes(ord('a'), 4),
+ entry.data)
def testDebug(self):
"""Check that enabling debug in the elf module produced debug output"""
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 648cfd241f1..d842d89dd66 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -18,7 +18,6 @@ except:
have_importlib = False
import os
-from sets import Set
import sys
import fdt_util
@@ -178,8 +177,8 @@ class Entry(object):
# It would be better to use isinstance(self, Entry_blob_dtb) here but
# we cannot access Entry_blob_dtb
if fname and fname.endswith('.dtb'):
- return Set([fname])
- return Set()
+ return set([fname])
+ return set()
def ExpandEntries(self):
pass
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index 1f7ff5b4e41..b30a7beecc8 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -41,7 +41,11 @@ class TestEntry(unittest.TestCase):
del sys.modules['importlib']
global entry
if entry:
- reload(entry)
+ if sys.version_info[0] >= 3:
+ import importlib
+ importlib.reload(entry)
+ else:
+ reload(entry)
else:
import entry
entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py
index 3e345bd9526..ac62d2e2005 100644
--- a/tools/binman/etype/_testing.py
+++ b/tools/binman/etype/_testing.py
@@ -75,7 +75,7 @@ class Entry__testing(Entry):
def ObtainContents(self):
if self.return_unknown_contents or not self.return_contents:
return False
- self.data = 'a'
+ self.data = b'a'
self.contents_size = len(self.data)
if self.return_contents_once:
self.return_contents = False
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index ae80bbee530..f56a1f87688 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -60,7 +60,7 @@ class Entry_blob(Entry):
except AttributeError:
data = lz4.compress(data)
'''
- data = tools.Run('lz4', '-c', self._pathname)
+ data = tools.Run('lz4', '-c', self._pathname, binary=True)
self.SetContents(data)
return True
diff --git a/tools/binman/etype/fill.py b/tools/binman/etype/fill.py
index dcfe978a5bf..68efe42ec0b 100644
--- a/tools/binman/etype/fill.py
+++ b/tools/binman/etype/fill.py
@@ -5,7 +5,7 @@
from entry import Entry
import fdt_util
-
+import tools
class Entry_fill(Entry):
"""An entry which is filled to a particular byte value
@@ -28,5 +28,5 @@ class Entry_fill(Entry):
self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0)
def ObtainContents(self):
- self.SetContents(chr(self.fill_value) * self.size)
+ self.SetContents(tools.GetBytes(self.fill_value, self.size))
return True
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index bf35a5bbf4e..e6b5c5c74c0 100644
--- a/tools/binman/etype/fmap.py
+++ b/tools/binman/etype/fmap.py
@@ -7,6 +7,7 @@
from entry import Entry
import fmap_util
+import tools
class Entry_fmap(Entry):
@@ -46,7 +47,7 @@ class Entry_fmap(Entry):
if pos is not None:
pos -= entry.section.GetRootSkipAtStart()
areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
- entry.name, 0))
+ tools.FromUnicode(entry.name), 0))
entries = self.section._image.GetEntries()
areas = []
diff --git a/tools/binman/etype/gbb.py b/tools/binman/etype/gbb.py
index 8fe10f47135..a94c0fca9d5 100644
--- a/tools/binman/etype/gbb.py
+++ b/tools/binman/etype/gbb.py
@@ -64,7 +64,7 @@ class Entry_gbb(Entry):
self.gbb_flags = 0
flags_node = node.FindNode('flags')
if flags_node:
- for flag, value in gbb_flag_properties.iteritems():
+ for flag, value in gbb_flag_properties.items():
if fdt_util.GetBool(flags_node, flag):
self.gbb_flags |= value
diff --git a/tools/binman/etype/text.py b/tools/binman/etype/text.py
index c4aa510a87b..9ee04d7c9d8 100644
--- a/tools/binman/etype/text.py
+++ b/tools/binman/etype/text.py
@@ -7,6 +7,7 @@ from collections import OrderedDict
from entry import Entry, EntryArg
import fdt_util
+import tools
class Entry_text(Entry):
@@ -48,9 +49,11 @@ class Entry_text(Entry):
"""
def __init__(self, section, etype, node):
Entry.__init__(self, section, etype, node)
- self.text_label, = self.GetEntryArgsOrProps(
- [EntryArg('text-label', str)])
- self.value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
+ label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
+ self.text_label = tools.ToStr(label) if type(label) != str else label
+ value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
+ value = tools.ToBytes(value) if value is not None else value
+ self.value = value
def ObtainContents(self):
if not self.value:
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index 444c51b8b72..188888e022b 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/tools/binman/etype/u_boot_dtb_with_ucode.py
@@ -26,7 +26,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
"""
def __init__(self, section, etype, node):
Entry_blob_dtb.__init__(self, section, etype, node)
- self.ucode_data = ''
+ self.ucode_data = b''
self.collate = False
self.ucode_offset = None
self.ucode_size = None
@@ -65,7 +65,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
for node in self.ucode.subnodes:
data_prop = node.props.get('data')
if data_prop:
- self.ucode_data += ''.join(data_prop.bytes)
+ self.ucode_data += data_prop.bytes
if self.collate:
node.DeleteProp('data')
return True
diff --git a/tools/binman/etype/u_boot_spl_bss_pad.py b/tools/binman/etype/u_boot_spl_bss_pad.py
index 00b7ac50040..66a296a6f85 100644
--- a/tools/binman/etype/u_boot_spl_bss_pad.py
+++ b/tools/binman/etype/u_boot_spl_bss_pad.py
@@ -38,5 +38,5 @@ class Entry_u_boot_spl_bss_pad(Entry_blob):
bss_size = elf.GetSymbolAddress(fname, '__bss_size')
if not bss_size:
self.Raise('Expected __bss_size symbol in spl/u-boot-spl')
- self.SetContents(chr(0) * bss_size)
+ self.SetContents(tools.GetBytes(0, bss_size))
return True
diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py
index a00e530295b..dee8848db7a 100644
--- a/tools/binman/etype/u_boot_ucode.py
+++ b/tools/binman/etype/u_boot_ucode.py
@@ -69,7 +69,7 @@ class Entry_u_boot_ucode(Entry_blob):
if entry and entry.target_offset:
found = True
if not found:
- self.data = ''
+ self.data = b''
return True
# Get the microcode from the device tree entry. If it is not available
# yet, return False so we will be called later. If the section simply
@@ -87,7 +87,7 @@ class Entry_u_boot_ucode(Entry_blob):
if not fdt_entry.collate:
# This binary can be empty
- self.data = ''
+ self.data = b''
return True
# Write it out to a file
diff --git a/tools/binman/etype/vblock.py b/tools/binman/etype/vblock.py
index 334ff9f966a..91fa2f7808f 100644
--- a/tools/binman/etype/vblock.py
+++ b/tools/binman/etype/vblock.py
@@ -51,7 +51,7 @@ class Entry_vblock(Entry):
def ObtainContents(self):
# Join up the data files to be signed
- input_data = ''
+ input_data = b''
for entry_phandle in self.content:
data = self.section.GetContentsByPhandle(entry_phandle, self)
if data is None:
diff --git a/tools/binman/fmap_util.py b/tools/binman/fmap_util.py
index be3cbee87bd..d0f956b6221 100644
--- a/tools/binman/fmap_util.py
+++ b/tools/binman/fmap_util.py
@@ -8,9 +8,12 @@
import collections
import struct
+import sys
+
+import tools
# constants imported from lib/fmap.h
-FMAP_SIGNATURE = '__FMAP__'
+FMAP_SIGNATURE = b'__FMAP__'
FMAP_VER_MAJOR = 1
FMAP_VER_MINOR = 0
FMAP_STRLEN = 32
@@ -50,6 +53,8 @@ FmapArea = collections.namedtuple('FmapArea', FMAP_AREA_NAMES)
def NameToFmap(name):
+ if type(name) == bytes and sys.version_info[0] >= 3:
+ name = name.decode('utf-8') # pragma: no cover (for Python 2)
return name.replace('\0', '').replace('-', '_').upper()
def ConvertName(field_names, fields):
@@ -65,7 +70,7 @@ def ConvertName(field_names, fields):
value: value of that field (string for the ones we support)
"""
name_index = field_names.index('name')
- fields[name_index] = NameToFmap(fields[name_index])
+ fields[name_index] = tools.ToBytes(NameToFmap(fields[name_index]))
def DecodeFmap(data):
"""Decode a flashmap into a header and list of areas
@@ -106,7 +111,8 @@ def EncodeFmap(image_size, name, areas):
ConvertName(names, params)
return struct.pack(fmt, *params)
- values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size, name, len(areas))
+ values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size,
+ tools.FromUnicode(name), len(areas))
blob = _FormatBlob(FMAP_HEADER_FORMAT, FMAP_HEADER_NAMES, values)
for area in areas:
blob += _FormatBlob(FMAP_AREA_FORMAT, FMAP_AREA_NAMES, area)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index daea1ea1382..cc57ef3e04a 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -29,38 +29,38 @@ import tools
import tout
# Contents of test files, corresponding to different entry types
-U_BOOT_DATA = '1234'
-U_BOOT_IMG_DATA = 'img'
-U_BOOT_SPL_DATA = '56780123456789abcde'
-U_BOOT_TPL_DATA = 'tpl'
-BLOB_DATA = '89'
-ME_DATA = '0abcd'
-VGA_DATA = 'vga'
-U_BOOT_DTB_DATA = 'udtb'
-U_BOOT_SPL_DTB_DATA = 'spldtb'
-U_BOOT_TPL_DTB_DATA = 'tpldtb'
-X86_START16_DATA = 'start16'
-X86_START16_SPL_DATA = 'start16spl'
-X86_START16_TPL_DATA = 'start16tpl'
-PPC_MPC85XX_BR_DATA = 'ppcmpc85xxbr'
-U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here'
-U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here'
-U_BOOT_TPL_NODTB_DATA = 'tplnodtb with microcode pointer somewhere in here'
-FSP_DATA = 'fsp'
-CMC_DATA = 'cmc'
-VBT_DATA = 'vbt'
-MRC_DATA = 'mrc'
+U_BOOT_DATA = b'1234'
+U_BOOT_IMG_DATA = b'img'
+U_BOOT_SPL_DATA = b'56780123456789abcde'
+U_BOOT_TPL_DATA = b'tpl'
+BLOB_DATA = b'89'
+ME_DATA = b'0abcd'
+VGA_DATA = b'vga'
+U_BOOT_DTB_DATA = b'udtb'
+U_BOOT_SPL_DTB_DATA = b'spldtb'
+U_BOOT_TPL_DTB_DATA = b'tpldtb'
+X86_START16_DATA = b'start16'
+X86_START16_SPL_DATA = b'start16spl'
+X86_START16_TPL_DATA = b'start16tpl'
+PPC_MPC85XX_BR_DATA = b'ppcmpc85xxbr'
+U_BOOT_NODTB_DATA = b'nodtb with microcode pointer somewhere in here'
+U_BOOT_SPL_NODTB_DATA = b'splnodtb with microcode pointer somewhere in here'
+U_BOOT_TPL_NODTB_DATA = b'tplnodtb with microcode pointer somewhere in here'
+FSP_DATA = b'fsp'
+CMC_DATA = b'cmc'
+VBT_DATA = b'vbt'
+MRC_DATA = b'mrc'
TEXT_DATA = 'text'
TEXT_DATA2 = 'text2'
TEXT_DATA3 = 'text3'
-CROS_EC_RW_DATA = 'ecrw'
-GBB_DATA = 'gbbd'
-BMPBLK_DATA = 'bmp'
-VBLOCK_DATA = 'vblk'
-FILES_DATA = ("sorry I'm late\nOh, don't bother apologising, I'm " +
- "sorry you're alive\n")
-COMPRESS_DATA = 'data to compress'
-REFCODE_DATA = 'refcode'
+CROS_EC_RW_DATA = b'ecrw'
+GBB_DATA = b'gbbd'
+BMPBLK_DATA = b'bmp'
+VBLOCK_DATA = b'vblk'
+FILES_DATA = (b"sorry I'm late\nOh, don't bother apologising, I'm " +
+ b"sorry you're alive\n")
+COMPRESS_DATA = b'data to compress'
+REFCODE_DATA = b'refcode'
class TestFunctional(unittest.TestCase):
@@ -119,11 +119,11 @@ class TestFunctional(unittest.TestCase):
TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA)
# ELF file with a '_dt_ucode_base_size' symbol
- with open(self.TestFile('u_boot_ucode_ptr')) as fd:
+ with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd:
TestFunctional._MakeInputFile('u-boot', fd.read())
# Intel flash descriptor file
- with open(self.TestFile('descriptor.bin')) as fd:
+ with open(self.TestFile('descriptor.bin'), 'rb') as fd:
TestFunctional._MakeInputFile('descriptor.bin', fd.read())
shutil.copytree(self.TestFile('files'),
@@ -214,7 +214,7 @@ class TestFunctional(unittest.TestCase):
if verbosity is not None:
args.append('-v%d' % verbosity)
if entry_args:
- for arg, value in entry_args.iteritems():
+ for arg, value in entry_args.items():
args.append('-a%s=%s' % (arg, value))
if images:
for image in images:
@@ -236,7 +236,7 @@ class TestFunctional(unittest.TestCase):
"""
tools.PrepareOutputDir(None)
dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
- with open(dtb) as fd:
+ with open(dtb, 'rb') as fd:
data = fd.read()
TestFunctional._MakeInputFile(outfile, data)
tools.FinaliseOutputDir()
@@ -291,7 +291,6 @@ class TestFunctional(unittest.TestCase):
# Use the compiled test file as the u-boot-dtb input
if use_real_dtb:
dtb_data = self._SetupDtb(fname)
- infile = os.path.join(self._indir, 'u-boot.dtb')
# For testing purposes, make a copy of the DT for SPL and TPL. Add
# a node indicating which it is, so aid verification.
@@ -317,7 +316,7 @@ class TestFunctional(unittest.TestCase):
map_data = fd.read()
else:
map_data = None
- with open(image_fname) as fd:
+ with open(image_fname, 'rb') as fd:
return fd.read(), dtb_data, map_data, out_dtb_fname
finally:
# Put the test file back
@@ -379,7 +378,7 @@ class TestFunctional(unittest.TestCase):
Args:
Filename of ELF file to use as SPL
"""
- with open(self.TestFile(src_fname)) as fd:
+ with open(self.TestFile(src_fname), 'rb') as fd:
TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
@classmethod
@@ -396,7 +395,7 @@ class TestFunctional(unittest.TestCase):
for grep in grep_list:
if grep in target:
return
- self.fail("Error: '%' not found in '%s'" % (grep_list, target))
+ self.fail("Error: '%s' not found in '%s'" % (grep_list, target))
def CheckNoGaps(self, entries):
"""Check that all entries fit together without gaps
@@ -541,7 +540,7 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(len(U_BOOT_DATA), image._size)
fname = tools.GetOutputFilename('image1.bin')
self.assertTrue(os.path.exists(fname))
- with open(fname) as fd:
+ with open(fname, 'rb') as fd:
data = fd.read()
self.assertEqual(U_BOOT_DATA, data)
@@ -549,11 +548,11 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
fname = tools.GetOutputFilename('image2.bin')
self.assertTrue(os.path.exists(fname))
- with open(fname) as fd:
+ with open(fname, 'rb') as fd:
data = fd.read()
self.assertEqual(U_BOOT_DATA, data[3:7])
- self.assertEqual(chr(0) * 3, data[:3])
- self.assertEqual(chr(0) * 5, data[7:])
+ self.assertEqual(tools.GetBytes(0, 3), data[:3])
+ self.assertEqual(tools.GetBytes(0, 5), data[7:])
def testBadAlign(self):
"""Test that an invalid alignment value is detected"""
@@ -732,7 +731,8 @@ class TestFunctional(unittest.TestCase):
"""Test that the image pad byte can be specified"""
self._SetupSplElf()
data = self._DoReadFile('021_image_pad.dts')
- self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data)
+ self.assertEqual(U_BOOT_SPL_DATA + tools.GetBytes(0xff, 1) +
+ U_BOOT_DATA, data)
def testImageName(self):
"""Test that image files can be named"""
@@ -755,8 +755,8 @@ class TestFunctional(unittest.TestCase):
"""Test that entries can be sorted"""
self._SetupSplElf()
data = self._DoReadFile('024_sorted.dts')
- self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 +
- U_BOOT_DATA, data)
+ self.assertEqual(tools.GetBytes(0, 1) + U_BOOT_SPL_DATA +
+ tools.GetBytes(0, 2) + U_BOOT_DATA, data)
def testPackZeroOffset(self):
"""Test that an entry at offset 0 is not given a new offset"""
@@ -798,12 +798,12 @@ class TestFunctional(unittest.TestCase):
"""Test that a basic x86 ROM can be created"""
self._SetupSplElf()
data = self._DoReadFile('029_x86-rom.dts')
- self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA +
- chr(0) * 2, data)
+ self.assertEqual(U_BOOT_DATA + tools.GetBytes(0, 7) + U_BOOT_SPL_DATA +
+ tools.GetBytes(0, 2), data)
def testPackX86RomMeNoDesc(self):
"""Test that an invalid Intel descriptor entry is detected"""
- TestFunctional._MakeInputFile('descriptor.bin', '')
+ TestFunctional._MakeInputFile('descriptor.bin', b'')
with self.assertRaises(ValueError) as e:
self._DoTestFile('031_x86-rom-me.dts')
self.assertIn("Node '/binman/intel-descriptor': Cannot find FD "
@@ -900,8 +900,8 @@ class TestFunctional(unittest.TestCase):
"""
first, pos_and_size = self._RunMicrocodeTest('034_x86_ucode.dts',
U_BOOT_NODTB_DATA)
- self.assertEqual('nodtb with microcode' + pos_and_size +
- ' somewhere in here', first)
+ self.assertEqual(b'nodtb with microcode' + pos_and_size +
+ b' somewhere in here', first)
def _RunPackUbootSingleMicrocode(self):
"""Test that x86 microcode can be handled correctly
@@ -932,8 +932,8 @@ class TestFunctional(unittest.TestCase):
pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
len(ucode_data))
first = data[:len(U_BOOT_NODTB_DATA)]
- self.assertEqual('nodtb with microcode' + pos_and_size +
- ' somewhere in here', first)
+ self.assertEqual(b'nodtb with microcode' + pos_and_size +
+ b' somewhere in here', first)
def testPackUbootSingleMicrocode(self):
"""Test that x86 microcode can be handled correctly with fdt_normal.
@@ -970,7 +970,7 @@ class TestFunctional(unittest.TestCase):
"""Test that a U-Boot binary without the microcode symbol is detected"""
# ELF file without a '_dt_ucode_base_size' symbol
try:
- with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
+ with open(self.TestFile('u_boot_no_ucode_ptr'), 'rb') as fd:
TestFunctional._MakeInputFile('u-boot', fd.read())
with self.assertRaises(ValueError) as e:
@@ -980,7 +980,7 @@ class TestFunctional(unittest.TestCase):
finally:
# Put the original file back
- with open(self.TestFile('u_boot_ucode_ptr')) as fd:
+ with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd:
TestFunctional._MakeInputFile('u-boot', fd.read())
def testMicrocodeNotInImage(self):
@@ -993,7 +993,7 @@ class TestFunctional(unittest.TestCase):
def testWithoutMicrocode(self):
"""Test that we can cope with an image without microcode (e.g. qemu)"""
- with open(self.TestFile('u_boot_no_ucode_ptr')) as fd:
+ with open(self.TestFile('u_boot_no_ucode_ptr'), 'rb') as fd:
TestFunctional._MakeInputFile('u-boot', fd.read())
data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True)
@@ -1006,7 +1006,7 @@ class TestFunctional(unittest.TestCase):
used_len = len(U_BOOT_NODTB_DATA) + fdt_len
third = data[used_len:]
- self.assertEqual(chr(0) * (0x200 - used_len), third)
+ self.assertEqual(tools.GetBytes(0, 0x200 - used_len), third)
def testUnknownPosSize(self):
"""Test that microcode must be placed within the image"""
@@ -1035,7 +1035,8 @@ class TestFunctional(unittest.TestCase):
# ELF file with a '__bss_size' symbol
self._SetupSplElf()
data = self._DoReadFile('047_spl_bss_pad.dts')
- self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data)
+ self.assertEqual(U_BOOT_SPL_DATA + tools.GetBytes(0, 10) + U_BOOT_DATA,
+ data)
def testSplBssPadMissing(self):
"""Test that a missing symbol is detected"""
@@ -1067,8 +1068,8 @@ class TestFunctional(unittest.TestCase):
self._SetupSplElf('u_boot_ucode_ptr')
first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA,
ucode_second=ucode_second)
- self.assertEqual('splnodtb with microc' + pos_and_size +
- 'ter somewhere in here', first)
+ self.assertEqual(b'splnodtb with microc' + pos_and_size +
+ b'ter somewhere in here', first)
def testPackUbootSplMicrocode(self):
"""Test that x86 microcode can be handled correctly in SPL"""
@@ -1109,9 +1110,9 @@ class TestFunctional(unittest.TestCase):
self._SetupSplElf('u_boot_binman_syms')
data = self._DoReadFile('053_symbols.dts')
sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20)
- expected = (sym_values + U_BOOT_SPL_DATA[16:] + chr(0xff) +
- U_BOOT_DATA +
- sym_values + U_BOOT_SPL_DATA[16:])
+ expected = (sym_values + U_BOOT_SPL_DATA[16:] +
+ tools.GetBytes(0xff, 1) + U_BOOT_DATA + sym_values +
+ U_BOOT_SPL_DATA[16:])
self.assertEqual(expected, data)
def testPackUnitAddress(self):
@@ -1122,8 +1123,9 @@ class TestFunctional(unittest.TestCase):
def testSections(self):
"""Basic test of sections"""
data = self._DoReadFile('055_sections.dts')
- expected = (U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 +
- U_BOOT_DATA + '&' * 4)
+ expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) +
+ U_BOOT_DATA + tools.GetBytes(ord('a'), 12) +
+ U_BOOT_DATA + tools.GetBytes(ord('&'), 4))
self.assertEqual(expected, data)
def testMap(self):
@@ -1281,8 +1283,10 @@ class TestFunctional(unittest.TestCase):
}
data, _, _, _ = self._DoReadFileDtb('066_text.dts',
entry_args=entry_args)
- expected = (TEXT_DATA + chr(0) * (8 - len(TEXT_DATA)) + TEXT_DATA2 +
- TEXT_DATA3 + 'some text')
+ expected = (tools.ToBytes(TEXT_DATA) +
+ tools.GetBytes(0, 8 - len(TEXT_DATA)) +
+ tools.ToBytes(TEXT_DATA2) + tools.ToBytes(TEXT_DATA3) +
+ b'some text')
self.assertEqual(expected, data)
def testEntryDocs(self):
@@ -1303,32 +1307,33 @@ class TestFunctional(unittest.TestCase):
"""Basic test of generation of a flashrom fmap"""
data = self._DoReadFile('067_fmap.dts')
fhdr, fentries = fmap_util.DecodeFmap(data[32:])
- expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12
+ expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) +
+ U_BOOT_DATA + tools.GetBytes(ord('a'), 12))
self.assertEqual(expected, data[:32])
- self.assertEqual('__FMAP__', fhdr.signature)
+ self.assertEqual(b'__FMAP__', fhdr.signature)
self.assertEqual(1, fhdr.ver_major)
self.assertEqual(0, fhdr.ver_minor)
self.assertEqual(0, fhdr.base)
self.assertEqual(16 + 16 +
fmap_util.FMAP_HEADER_LEN +
fmap_util.FMAP_AREA_LEN * 3, fhdr.image_size)
- self.assertEqual('FMAP', fhdr.name)
+ self.assertEqual(b'FMAP', fhdr.name)
self.assertEqual(3, fhdr.nareas)
for fentry in fentries:
self.assertEqual(0, fentry.flags)
self.assertEqual(0, fentries[0].offset)
self.assertEqual(4, fentries[0].size)
- self.assertEqual('RO_U_BOOT', fentries[0].name)
+ self.assertEqual(b'RO_U_BOOT', fentries[0].name)
self.assertEqual(16, fentries[1].offset)
self.assertEqual(4, fentries[1].size)
- self.assertEqual('RW_U_BOOT', fentries[1].name)
+ self.assertEqual(b'RW_U_BOOT', fentries[1].name)
self.assertEqual(32, fentries[2].offset)
self.assertEqual(fmap_util.FMAP_HEADER_LEN +
fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
- self.assertEqual('FMAP', fentries[2].name)
+ self.assertEqual(b'FMAP', fentries[2].name)
def testBlobNamedByArg(self):
"""Test we can add a blob with the filename coming from an entry arg"""
@@ -1341,7 +1346,7 @@ class TestFunctional(unittest.TestCase):
def testFill(self):
"""Test for an fill entry type"""
data = self._DoReadFile('069_fill.dts')
- expected = 8 * chr(0xff) + 8 * chr(0)
+ expected = tools.GetBytes(0xff, 8) + tools.GetBytes(0, 8)
self.assertEqual(expected, data)
def testFillNoSize(self):
@@ -1357,7 +1362,7 @@ class TestFunctional(unittest.TestCase):
fname = pipe_list[0][-1]
# Append our GBB data to the file, which will happen every time the
# futility command is called.
- with open(fname, 'a') as fd:
+ with open(fname, 'ab') as fd:
fd.write(GBB_DATA)
return command.CommandResult()
@@ -1371,7 +1376,8 @@ class TestFunctional(unittest.TestCase):
data, _, _, _ = self._DoReadFileDtb('071_gbb.dts', entry_args=entry_args)
# Since futility
- expected = GBB_DATA + GBB_DATA + 8 * chr(0) + (0x2180 - 16) * chr(0)
+ expected = (GBB_DATA + GBB_DATA + tools.GetBytes(0, 8) +
+ tools.GetBytes(0, 0x2180 - 16))
self.assertEqual(expected, data)
def testGbbTooSmall(self):
@@ -1431,7 +1437,7 @@ class TestFunctional(unittest.TestCase):
def testTpl(self):
"""Test that an image with TPL and ots device tree can be created"""
# ELF file with a '__bss_size' symbol
- with open(self.TestFile('bss_data')) as fd:
+ with open(self.TestFile('bss_data'), 'rb') as fd:
TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
data = self._DoReadFile('078_u_boot_tpl.dts')
self.assertEqual(U_BOOT_TPL_DATA + U_BOOT_TPL_DTB_DATA, data)
@@ -1446,7 +1452,7 @@ class TestFunctional(unittest.TestCase):
def testFillZero(self):
"""Test for an fill entry type with a size of 0"""
data = self._DoReadFile('080_fill_empty.dts')
- self.assertEqual(chr(0) * 16, data)
+ self.assertEqual(tools.GetBytes(0, 16), data)
def testTextMissing(self):
"""Test for a text entry type where there is no text"""
@@ -1557,7 +1563,7 @@ class TestFunctional(unittest.TestCase):
out = os.path.join(self._indir, 'lz4.tmp')
with open(out, 'wb') as fd:
fd.write(data)
- return tools.Run('lz4', '-dc', out)
+ return tools.Run('lz4', '-dc', out, binary=True)
'''
try:
orig = lz4.frame.decompress(data)
@@ -1595,7 +1601,7 @@ class TestFunctional(unittest.TestCase):
files = entries['files']
entries = files._section._entries
- orig = ''
+ orig = b''
for i in range(1, 3):
key = '%d.dat' % i
start = entries[key].image_pos
@@ -1623,10 +1629,10 @@ class TestFunctional(unittest.TestCase):
"""Test an expanding entry"""
data, _, map_data, _ = self._DoReadFileDtb('088_expand_size.dts',
map=True)
- expect = ('a' * 8 + U_BOOT_DATA +
- MRC_DATA + 'b' * 1 + U_BOOT_DATA +
- 'c' * 8 + U_BOOT_DATA +
- 'd' * 8)
+ expect = (tools.GetBytes(ord('a'), 8) + U_BOOT_DATA +
+ MRC_DATA + tools.GetBytes(ord('b'), 1) + U_BOOT_DATA +
+ tools.GetBytes(ord('c'), 8) + U_BOOT_DATA +
+ tools.GetBytes(ord('d'), 8))
self.assertEqual(expect, data)
self.assertEqual('''ImagePos Offset Size Name
00000000 00000000 00000028 main-section
@@ -1658,7 +1664,7 @@ class TestFunctional(unittest.TestCase):
hash_node = dtb.GetNode('/binman/u-boot/hash').props['value']
m = hashlib.sha256()
m.update(U_BOOT_DATA)
- self.assertEqual(m.digest(), ''.join(hash_node.value))
+ self.assertEqual(m.digest(), b''.join(hash_node.value))
def testHashNoAlgo(self):
with self.assertRaises(ValueError) as e:
@@ -1681,8 +1687,8 @@ class TestFunctional(unittest.TestCase):
hash_node = dtb.GetNode('/binman/section/hash').props['value']
m = hashlib.sha256()
m.update(U_BOOT_DATA)
- m.update(16 * 'a')
- self.assertEqual(m.digest(), ''.join(hash_node.value))
+ m.update(tools.GetBytes(ord('a'), 16))
+ self.assertEqual(m.digest(), b''.join(hash_node.value))
def testPackUBootTplMicrocode(self):
"""Test that x86 microcode can be handled correctly in TPL
@@ -1693,18 +1699,18 @@ class TestFunctional(unittest.TestCase):
u-boot-tpl.dtb with the microcode removed
the microcode
"""
- with open(self.TestFile('u_boot_ucode_ptr')) as fd:
+ with open(self.TestFile('u_boot_ucode_ptr'), 'rb') as fd:
TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
first, pos_and_size = self._RunMicrocodeTest('093_x86_tpl_ucode.dts',
U_BOOT_TPL_NODTB_DATA)
- self.assertEqual('tplnodtb with microc' + pos_and_size +
- 'ter somewhere in here', first)
+ self.assertEqual(b'tplnodtb with microc' + pos_and_size +
+ b'ter somewhere in here', first)
def testFmapX86(self):
"""Basic test of generation of a flashrom fmap"""
data = self._DoReadFile('094_fmap_x86.dts')
fhdr, fentries = fmap_util.DecodeFmap(data[32:])
- expected = U_BOOT_DATA + MRC_DATA + 'a' * (32 - 7)
+ expected = U_BOOT_DATA + MRC_DATA + tools.GetBytes(ord('a'), 32 - 7)
self.assertEqual(expected, data[:32])
fhdr, fentries = fmap_util.DecodeFmap(data[32:])
@@ -1712,21 +1718,21 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(0, fentries[0].offset)
self.assertEqual(4, fentries[0].size)
- self.assertEqual('U_BOOT', fentries[0].name)
+ self.assertEqual(b'U_BOOT', fentries[0].name)
self.assertEqual(4, fentries[1].offset)
self.assertEqual(3, fentries[1].size)
- self.assertEqual('INTEL_MRC', fentries[1].name)
+ self.assertEqual(b'INTEL_MRC', fentries[1].name)
self.assertEqual(32, fentries[2].offset)
self.assertEqual(fmap_util.FMAP_HEADER_LEN +
fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
- self.assertEqual('FMAP', fentries[2].name)
+ self.assertEqual(b'FMAP', fentries[2].name)
def testFmapX86Section(self):
"""Basic test of generation of a flashrom fmap"""
data = self._DoReadFile('095_fmap_x86_section.dts')
- expected = U_BOOT_DATA + MRC_DATA + 'b' * (32 - 7)
+ expected = U_BOOT_DATA + MRC_DATA + tools.GetBytes(ord('b'), 32 - 7)
self.assertEqual(expected, data[:32])
fhdr, fentries = fmap_util.DecodeFmap(data[36:])
@@ -1734,28 +1740,28 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(0, fentries[0].offset)
self.assertEqual(4, fentries[0].size)
- self.assertEqual('U_BOOT', fentries[0].name)
+ self.assertEqual(b'U_BOOT', fentries[0].name)
self.assertEqual(4, fentries[1].offset)
self.assertEqual(3, fentries[1].size)
- self.assertEqual('INTEL_MRC', fentries[1].name)
+ self.assertEqual(b'INTEL_MRC', fentries[1].name)
self.assertEqual(36, fentries[2].offset)
self.assertEqual(fmap_util.FMAP_HEADER_LEN +
fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
- self.assertEqual('FMAP', fentries[2].name)
+ self.assertEqual(b'FMAP', fentries[2].name)
def testElf(self):
"""Basic test of ELF entries"""
self._SetupSplElf()
- with open(self.TestFile('bss_data')) as fd:
+ with open(self.TestFile('bss_data'), 'rb') as fd:
TestFunctional._MakeInputFile('-boot', fd.read())
data = self._DoReadFile('096_elf.dts')
def testElfStripg(self):
"""Basic test of ELF entries"""
self._SetupSplElf()
- with open(self.TestFile('bss_data')) as fd:
+ with open(self.TestFile('bss_data'), 'rb') as fd:
TestFunctional._MakeInputFile('-boot', fd.read())
data = self._DoReadFile('097_elf_strip.dts')
@@ -1771,7 +1777,7 @@ class TestFunctional(unittest.TestCase):
# We should not get an inmage, but there should be a map file
self.assertFalse(os.path.exists(tools.GetOutputFilename('image.bin')))
self.assertTrue(os.path.exists(map_fname))
- map_data = tools.ReadFile(map_fname)
+ map_data = tools.ReadFile(map_fname, binary=False)
self.assertEqual('''ImagePos Offset Size Name
<none> 00000000 00000007 main-section
<none> 00000000 00000004 u-boot
@@ -1797,9 +1803,12 @@ class TestFunctional(unittest.TestCase):
0000002c 00000000 00000004 u-boot
''', map_data)
self.assertEqual(data,
- 4 * chr(0x26) + U_BOOT_DATA + 12 * chr(0x21) +
- 4 * chr(0x26) + U_BOOT_DATA + 12 * chr(0x61) +
- 4 * chr(0x26) + U_BOOT_DATA + 8 * chr(0x26))
+ tools.GetBytes(0x26, 4) + U_BOOT_DATA +
+ tools.GetBytes(0x21, 12) +
+ tools.GetBytes(0x26, 4) + U_BOOT_DATA +
+ tools.GetBytes(0x61, 12) +
+ tools.GetBytes(0x26, 4) + U_BOOT_DATA +
+ tools.GetBytes(0x26, 8))
if __name__ == "__main__":
diff --git a/tools/binman/state.py b/tools/binman/state.py
index d945e4bf657..af9678649cd 100644
--- a/tools/binman/state.py
+++ b/tools/binman/state.py
@@ -7,7 +7,6 @@
import hashlib
import re
-from sets import Set
import os
import tools
@@ -24,10 +23,10 @@ entry_args = {}
use_fake_dtb = False
# Set of all device tree files references by images
-fdt_set = Set()
+fdt_set = set()
# Same as above, but excluding the main one
-fdt_subset = Set()
+fdt_subset = set()
# The DTB which contains the full image information
main_dtb = None
@@ -136,7 +135,7 @@ def Prepare(images, dtb):
main_dtb = dtb
fdt_files.clear()
fdt_files['u-boot.dtb'] = dtb
- fdt_subset = Set()
+ fdt_subset = set()
if not use_fake_dtb:
for image in images.values():
fdt_subset.update(image.GetFdtSet())