mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-07-06 11:16:15 +09:00
tools: binman: Open all binary files in binary mode
At present some files are opened in text mode despite containing binary data. This works on Python 2 but not always on Python 3, due to unicode problems. BC&D are not my favourite people. Adjust the affected open() statements to use binary mode. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
5097915428
commit
1d0ebf7d63
|
@ -119,11 +119,11 @@ class TestFunctional(unittest.TestCase):
|
||||||
TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA)
|
TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA)
|
||||||
|
|
||||||
# ELF file with a '_dt_ucode_base_size' symbol
|
# 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())
|
TestFunctional._MakeInputFile('u-boot', fd.read())
|
||||||
|
|
||||||
# Intel flash descriptor file
|
# 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())
|
TestFunctional._MakeInputFile('descriptor.bin', fd.read())
|
||||||
|
|
||||||
shutil.copytree(self.TestFile('files'),
|
shutil.copytree(self.TestFile('files'),
|
||||||
|
@ -236,7 +236,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
tools.PrepareOutputDir(None)
|
tools.PrepareOutputDir(None)
|
||||||
dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
|
dtb = fdt_util.EnsureCompiled(self.TestFile(fname))
|
||||||
with open(dtb) as fd:
|
with open(dtb, 'rb') as fd:
|
||||||
data = fd.read()
|
data = fd.read()
|
||||||
TestFunctional._MakeInputFile(outfile, data)
|
TestFunctional._MakeInputFile(outfile, data)
|
||||||
tools.FinaliseOutputDir()
|
tools.FinaliseOutputDir()
|
||||||
|
@ -317,7 +317,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
map_data = fd.read()
|
map_data = fd.read()
|
||||||
else:
|
else:
|
||||||
map_data = None
|
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
|
return fd.read(), dtb_data, map_data, out_dtb_fname
|
||||||
finally:
|
finally:
|
||||||
# Put the test file back
|
# Put the test file back
|
||||||
|
@ -379,7 +379,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
Args:
|
Args:
|
||||||
Filename of ELF file to use as SPL
|
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())
|
TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -541,7 +541,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
self.assertEqual(len(U_BOOT_DATA), image._size)
|
self.assertEqual(len(U_BOOT_DATA), image._size)
|
||||||
fname = tools.GetOutputFilename('image1.bin')
|
fname = tools.GetOutputFilename('image1.bin')
|
||||||
self.assertTrue(os.path.exists(fname))
|
self.assertTrue(os.path.exists(fname))
|
||||||
with open(fname) as fd:
|
with open(fname, 'rb') as fd:
|
||||||
data = fd.read()
|
data = fd.read()
|
||||||
self.assertEqual(U_BOOT_DATA, data)
|
self.assertEqual(U_BOOT_DATA, data)
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
|
self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
|
||||||
fname = tools.GetOutputFilename('image2.bin')
|
fname = tools.GetOutputFilename('image2.bin')
|
||||||
self.assertTrue(os.path.exists(fname))
|
self.assertTrue(os.path.exists(fname))
|
||||||
with open(fname) as fd:
|
with open(fname, 'rb') as fd:
|
||||||
data = fd.read()
|
data = fd.read()
|
||||||
self.assertEqual(U_BOOT_DATA, data[3:7])
|
self.assertEqual(U_BOOT_DATA, data[3:7])
|
||||||
self.assertEqual(chr(0) * 3, data[:3])
|
self.assertEqual(chr(0) * 3, data[:3])
|
||||||
|
@ -970,7 +970,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
"""Test that a U-Boot binary without the microcode symbol is detected"""
|
"""Test that a U-Boot binary without the microcode symbol is detected"""
|
||||||
# ELF file without a '_dt_ucode_base_size' symbol
|
# ELF file without a '_dt_ucode_base_size' symbol
|
||||||
try:
|
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())
|
TestFunctional._MakeInputFile('u-boot', fd.read())
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
|
@ -980,7 +980,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Put the original file back
|
# 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())
|
TestFunctional._MakeInputFile('u-boot', fd.read())
|
||||||
|
|
||||||
def testMicrocodeNotInImage(self):
|
def testMicrocodeNotInImage(self):
|
||||||
|
@ -993,7 +993,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
|
|
||||||
def testWithoutMicrocode(self):
|
def testWithoutMicrocode(self):
|
||||||
"""Test that we can cope with an image without microcode (e.g. qemu)"""
|
"""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())
|
TestFunctional._MakeInputFile('u-boot', fd.read())
|
||||||
data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True)
|
data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True)
|
||||||
|
|
||||||
|
@ -1357,7 +1357,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
fname = pipe_list[0][-1]
|
fname = pipe_list[0][-1]
|
||||||
# Append our GBB data to the file, which will happen every time the
|
# Append our GBB data to the file, which will happen every time the
|
||||||
# futility command is called.
|
# futility command is called.
|
||||||
with open(fname, 'a') as fd:
|
with open(fname, 'ab') as fd:
|
||||||
fd.write(GBB_DATA)
|
fd.write(GBB_DATA)
|
||||||
return command.CommandResult()
|
return command.CommandResult()
|
||||||
|
|
||||||
|
@ -1431,7 +1431,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
def testTpl(self):
|
def testTpl(self):
|
||||||
"""Test that an image with TPL and ots device tree can be created"""
|
"""Test that an image with TPL and ots device tree can be created"""
|
||||||
# ELF file with a '__bss_size' symbol
|
# 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())
|
TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
|
||||||
data = self._DoReadFile('078_u_boot_tpl.dts')
|
data = self._DoReadFile('078_u_boot_tpl.dts')
|
||||||
self.assertEqual(U_BOOT_TPL_DATA + U_BOOT_TPL_DTB_DATA, data)
|
self.assertEqual(U_BOOT_TPL_DATA + U_BOOT_TPL_DTB_DATA, data)
|
||||||
|
@ -1693,7 +1693,7 @@ class TestFunctional(unittest.TestCase):
|
||||||
u-boot-tpl.dtb with the microcode removed
|
u-boot-tpl.dtb with the microcode removed
|
||||||
the microcode
|
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())
|
TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
|
||||||
first, pos_and_size = self._RunMicrocodeTest('093_x86_tpl_ucode.dts',
|
first, pos_and_size = self._RunMicrocodeTest('093_x86_tpl_ucode.dts',
|
||||||
U_BOOT_TPL_NODTB_DATA)
|
U_BOOT_TPL_NODTB_DATA)
|
||||||
|
@ -1748,14 +1748,14 @@ class TestFunctional(unittest.TestCase):
|
||||||
def testElf(self):
|
def testElf(self):
|
||||||
"""Basic test of ELF entries"""
|
"""Basic test of ELF entries"""
|
||||||
self._SetupSplElf()
|
self._SetupSplElf()
|
||||||
with open(self.TestFile('bss_data')) as fd:
|
with open(self.TestFile('bss_data'), 'rb') as fd:
|
||||||
TestFunctional._MakeInputFile('-boot', fd.read())
|
TestFunctional._MakeInputFile('-boot', fd.read())
|
||||||
data = self._DoReadFile('096_elf.dts')
|
data = self._DoReadFile('096_elf.dts')
|
||||||
|
|
||||||
def testElfStripg(self):
|
def testElfStripg(self):
|
||||||
"""Basic test of ELF entries"""
|
"""Basic test of ELF entries"""
|
||||||
self._SetupSplElf()
|
self._SetupSplElf()
|
||||||
with open(self.TestFile('bss_data')) as fd:
|
with open(self.TestFile('bss_data'), 'rb') as fd:
|
||||||
TestFunctional._MakeInputFile('-boot', fd.read())
|
TestFunctional._MakeInputFile('-boot', fd.read())
|
||||||
data = self._DoReadFile('097_elf_strip.dts')
|
data = self._DoReadFile('097_elf_strip.dts')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user