From c1aa66e75dbfcacab1fbca0e3e19c09e08d932d5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 29 Jan 2022 14:14:04 -0700 Subject: patman: Convert camel case in tools.py Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 320 +++++++++++++++++++++++++------------------------- 1 file changed, 160 insertions(+), 160 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 5400f76c676..21adf433fe3 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -174,7 +174,7 @@ class TestFunctional(unittest.TestCase): # ELF file with a '_dt_ucode_base_size' symbol TestFunctional._MakeInputFile('u-boot', - tools.ReadFile(cls.ElfTestFile('u_boot_ucode_ptr'))) + tools.read_file(cls.ElfTestFile('u_boot_ucode_ptr'))) # Intel flash descriptor file cls._SetupDescriptor() @@ -236,7 +236,7 @@ class TestFunctional(unittest.TestCase): if self.preserve_outdirs: print('Preserving output dir: %s' % tools.outdir) else: - tools._FinaliseForTest() + tools._finalise_for_test() def setUp(self): # Enable this to turn on debugging output @@ -262,10 +262,10 @@ class TestFunctional(unittest.TestCase): Temporary directory to use New image filename """ - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') tmpdir = tempfile.mkdtemp(prefix='binman.') updated_fname = os.path.join(tmpdir, 'image-updated.bin') - tools.WriteFile(updated_fname, tools.ReadFile(image_fname)) + tools.write_file(updated_fname, tools.read_file(image_fname)) self._CleanupOutputDir() return tmpdir, updated_fname @@ -492,14 +492,14 @@ class TestFunctional(unittest.TestCase): use_expanded=use_expanded, extra_indirs=extra_indirs, threads=threads) self.assertEqual(0, retcode) - out_dtb_fname = tools.GetOutputFilename('u-boot.dtb.out') + out_dtb_fname = tools.get_output_filename('u-boot.dtb.out') # Find the (only) image, read it and return its contents image = control.images['image'] - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') self.assertTrue(os.path.exists(image_fname)) if map: - map_fname = tools.GetOutputFilename('image.map') + map_fname = tools.get_output_filename('image.map') with open(map_fname) as fd: map_data = fd.read() else: @@ -578,7 +578,7 @@ class TestFunctional(unittest.TestCase): Filename of ELF file to use as SPL """ TestFunctional._MakeInputFile('spl/u-boot-spl', - tools.ReadFile(cls.ElfTestFile(src_fname))) + tools.read_file(cls.ElfTestFile(src_fname))) @classmethod def _SetupTplElf(cls, src_fname='bss_data'): @@ -588,7 +588,7 @@ class TestFunctional(unittest.TestCase): Filename of ELF file to use as TPL """ TestFunctional._MakeInputFile('tpl/u-boot-tpl', - tools.ReadFile(cls.ElfTestFile(src_fname))) + tools.read_file(cls.ElfTestFile(src_fname))) @classmethod def _SetupDescriptor(cls): @@ -756,7 +756,7 @@ class TestFunctional(unittest.TestCase): image = control.images['image1'] self.assertEqual(len(U_BOOT_DATA), image.size) - fname = tools.GetOutputFilename('image1.bin') + fname = tools.get_output_filename('image1.bin') self.assertTrue(os.path.exists(fname)) with open(fname, 'rb') as fd: data = fd.read() @@ -764,13 +764,13 @@ class TestFunctional(unittest.TestCase): image = control.images['image2'] self.assertEqual(3 + len(U_BOOT_DATA) + 5, image.size) - fname = tools.GetOutputFilename('image2.bin') + fname = tools.get_output_filename('image2.bin') self.assertTrue(os.path.exists(fname)) with open(fname, 'rb') as fd: data = fd.read() self.assertEqual(U_BOOT_DATA, data[3:7]) - self.assertEqual(tools.GetBytes(0, 3), data[:3]) - self.assertEqual(tools.GetBytes(0, 5), data[7:]) + self.assertEqual(tools.get_bytes(0, 3), data[:3]) + self.assertEqual(tools.get_bytes(0, 5), data[7:]) def testBadAlign(self): """Test that an invalid alignment value is detected""" @@ -838,8 +838,8 @@ class TestFunctional(unittest.TestCase): self.assertEqual(3, entry.pad_before) self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size) self.assertEqual(U_BOOT_DATA, entry.data) - self.assertEqual(tools.GetBytes(0, 3) + U_BOOT_DATA + - tools.GetBytes(0, 5), data[:entry.size]) + self.assertEqual(tools.get_bytes(0, 3) + U_BOOT_DATA + + tools.get_bytes(0, 5), data[:entry.size]) pos = entry.size # Second u-boot has an aligned size, but it has no effect @@ -857,7 +857,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(pos, entry.offset) self.assertEqual(32, entry.size) self.assertEqual(U_BOOT_DATA, entry.data) - self.assertEqual(U_BOOT_DATA + tools.GetBytes(0, 32 - len(U_BOOT_DATA)), + self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 32 - len(U_BOOT_DATA)), data[pos:pos + entry.size]) pos += entry.size @@ -867,7 +867,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(48, entry.offset) self.assertEqual(16, entry.size) self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)]) - self.assertEqual(U_BOOT_DATA + tools.GetBytes(0, 16 - len(U_BOOT_DATA)), + self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 16 - len(U_BOOT_DATA)), data[pos:pos + entry.size]) pos += entry.size @@ -877,7 +877,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(64, entry.offset) self.assertEqual(64, entry.size) self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)]) - self.assertEqual(U_BOOT_DATA + tools.GetBytes(0, 64 - len(U_BOOT_DATA)), + self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 64 - len(U_BOOT_DATA)), data[pos:pos + entry.size]) self.CheckNoGaps(entries) @@ -997,7 +997,7 @@ 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 + tools.GetBytes(0xff, 1) + + self.assertEqual(U_BOOT_SPL_DATA + tools.get_bytes(0xff, 1) + U_BOOT_DATA, data) def testImageName(self): @@ -1005,11 +1005,11 @@ class TestFunctional(unittest.TestCase): retcode = self._DoTestFile('022_image_name.dts') self.assertEqual(0, retcode) image = control.images['image1'] - fname = tools.GetOutputFilename('test-name') + fname = tools.get_output_filename('test-name') self.assertTrue(os.path.exists(fname)) image = control.images['image2'] - fname = tools.GetOutputFilename('test-name.xx') + fname = tools.get_output_filename('test-name.xx') self.assertTrue(os.path.exists(fname)) def testBlobFilename(self): @@ -1021,8 +1021,8 @@ class TestFunctional(unittest.TestCase): """Test that entries can be sorted""" self._SetupSplElf() data = self._DoReadFile('024_sorted.dts') - self.assertEqual(tools.GetBytes(0, 1) + U_BOOT_SPL_DATA + - tools.GetBytes(0, 2) + U_BOOT_DATA, data) + self.assertEqual(tools.get_bytes(0, 1) + U_BOOT_SPL_DATA + + tools.get_bytes(0, 2) + U_BOOT_DATA, data) def testPackZeroOffset(self): """Test that an entry at offset 0 is not given a new offset""" @@ -1065,8 +1065,8 @@ 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 + tools.GetBytes(0, 3) + U_BOOT_SPL_DATA + - tools.GetBytes(0, 2), data) + self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 3) + U_BOOT_SPL_DATA + + tools.get_bytes(0, 2), data) def testPackX86RomMeNoDesc(self): """Test that an invalid Intel descriptor entry is detected""" @@ -1090,7 +1090,7 @@ class TestFunctional(unittest.TestCase): def testPackX86RomMe(self): """Test that an x86 ROM with an ME region can be created""" data = self._DoReadFile('031_x86_rom_me.dts') - expected_desc = tools.ReadFile(self.TestFile('descriptor.bin')) + expected_desc = tools.read_file(self.TestFile('descriptor.bin')) if data[:0x1000] != expected_desc: self.fail('Expected descriptor binary at start of image') self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)]) @@ -1139,7 +1139,7 @@ class TestFunctional(unittest.TestCase): fdt_len = self.GetFdtLen(dtb_with_ucode) ucode_content = dtb_with_ucode[fdt_len:] ucode_pos = len(nodtb_data) + fdt_len - fname = tools.GetOutputFilename('test.dtb') + fname = tools.get_output_filename('test.dtb') with open(fname, 'wb') as fd: fd.write(dtb_with_ucode) dtb = fdt.FdtScan(fname) @@ -1244,7 +1244,7 @@ class TestFunctional(unittest.TestCase): # ELF file without a '_dt_ucode_base_size' symbol try: TestFunctional._MakeInputFile('u-boot', - tools.ReadFile(self.ElfTestFile('u_boot_no_ucode_ptr'))) + tools.read_file(self.ElfTestFile('u_boot_no_ucode_ptr'))) with self.assertRaises(ValueError) as e: self._RunPackUbootSingleMicrocode() @@ -1254,7 +1254,7 @@ class TestFunctional(unittest.TestCase): finally: # Put the original file back TestFunctional._MakeInputFile('u-boot', - tools.ReadFile(self.ElfTestFile('u_boot_ucode_ptr'))) + tools.read_file(self.ElfTestFile('u_boot_ucode_ptr'))) def testMicrocodeNotInImage(self): """Test that microcode must be placed within the image""" @@ -1267,7 +1267,7 @@ class TestFunctional(unittest.TestCase): def testWithoutMicrocode(self): """Test that we can cope with an image without microcode (e.g. qemu)""" TestFunctional._MakeInputFile('u-boot', - tools.ReadFile(self.ElfTestFile('u_boot_no_ucode_ptr'))) + tools.read_file(self.ElfTestFile('u_boot_no_ucode_ptr'))) data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True) # Now check the device tree has no microcode @@ -1279,7 +1279,7 @@ class TestFunctional(unittest.TestCase): used_len = len(U_BOOT_NODTB_DATA) + fdt_len third = data[used_len:] - self.assertEqual(tools.GetBytes(0, 0x200 - used_len), third) + self.assertEqual(tools.get_bytes(0, 0x200 - used_len), third) def testUnknownPosSize(self): """Test that microcode must be placed within the image""" @@ -1308,7 +1308,7 @@ 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 + tools.GetBytes(0, 10) + U_BOOT_DATA, + self.assertEqual(U_BOOT_SPL_DATA + tools.get_bytes(0, 10) + U_BOOT_DATA, data) def testSplBssPadMissing(self): @@ -1404,7 +1404,7 @@ class TestFunctional(unittest.TestCase): u_boot_offset + len(U_BOOT_DATA), 0x10 + u_boot_offset, 0x04) expected = (sym_values + base_data[20:] + - tools.GetBytes(0xff, 1) + U_BOOT_DATA + sym_values + + tools.get_bytes(0xff, 1) + U_BOOT_DATA + sym_values + base_data[20:]) self.assertEqual(expected, data) @@ -1426,9 +1426,9 @@ class TestFunctional(unittest.TestCase): def testSections(self): """Basic test of sections""" data = self._DoReadFile('055_sections.dts') - expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) + - U_BOOT_DATA + tools.GetBytes(ord('a'), 12) + - U_BOOT_DATA + tools.GetBytes(ord('&'), 4)) + expected = (U_BOOT_DATA + tools.get_bytes(ord('!'), 12) + + U_BOOT_DATA + tools.get_bytes(ord('a'), 12) + + U_BOOT_DATA + tools.get_bytes(ord('&'), 4)) self.assertEqual(expected, data) def testMap(self): @@ -1593,9 +1593,9 @@ class TestFunctional(unittest.TestCase): } data, _, _, _ = self._DoReadFileDtb('066_text.dts', entry_args=entry_args) - expected = (tools.ToBytes(TEXT_DATA) + - tools.GetBytes(0, 8 - len(TEXT_DATA)) + - tools.ToBytes(TEXT_DATA2) + tools.ToBytes(TEXT_DATA3) + + expected = (tools.to_bytes(TEXT_DATA) + + tools.get_bytes(0, 8 - len(TEXT_DATA)) + + tools.to_bytes(TEXT_DATA2) + tools.to_bytes(TEXT_DATA3) + b'some text' + b'more text') self.assertEqual(expected, data) @@ -1617,8 +1617,8 @@ 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 + tools.GetBytes(ord('!'), 12) + - U_BOOT_DATA + tools.GetBytes(ord('a'), 12)) + expected = (U_BOOT_DATA + tools.get_bytes(ord('!'), 12) + + U_BOOT_DATA + tools.get_bytes(ord('a'), 12)) self.assertEqual(expected, data[:32]) self.assertEqual(b'__FMAP__', fhdr.signature) self.assertEqual(1, fhdr.ver_major) @@ -1670,7 +1670,7 @@ class TestFunctional(unittest.TestCase): def testFill(self): """Test for an fill entry type""" data = self._DoReadFile('069_fill.dts') - expected = tools.GetBytes(0xff, 8) + tools.GetBytes(0, 8) + expected = tools.get_bytes(0xff, 8) + tools.get_bytes(0, 8) self.assertEqual(expected, data) def testFillNoSize(self): @@ -1700,8 +1700,8 @@ class TestFunctional(unittest.TestCase): data, _, _, _ = self._DoReadFileDtb('071_gbb.dts', entry_args=entry_args) # Since futility - expected = (GBB_DATA + GBB_DATA + tools.GetBytes(0, 8) + - tools.GetBytes(0, 0x2180 - 16)) + expected = (GBB_DATA + GBB_DATA + tools.get_bytes(0, 8) + + tools.get_bytes(0, 0x2180 - 16)) self.assertEqual(expected, data) def testGbbTooSmall(self): @@ -1751,7 +1751,7 @@ class TestFunctional(unittest.TestCase): if self._hash_data: infile = pipe_list[0][11] m = hashlib.sha256() - data = tools.ReadFile(infile) + data = tools.read_file(infile) m.update(data) fd.write(m.digest()) else: @@ -1845,7 +1845,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(tools.GetBytes(0, 16), data) + self.assertEqual(tools.get_bytes(0, 16), data) def testTextMissing(self): """Test for a text entry type where there is no text""" @@ -1875,8 +1875,8 @@ class TestFunctional(unittest.TestCase): else: self.assertNotIn(expected, stdout.getvalue()) - self.assertFalse(os.path.exists(tools.GetOutputFilename('image1.bin'))) - self.assertTrue(os.path.exists(tools.GetOutputFilename('image2.bin'))) + self.assertFalse(os.path.exists(tools.get_output_filename('image1.bin'))) + self.assertTrue(os.path.exists(tools.get_output_filename('image2.bin'))) self._CleanupOutputDir() def testUpdateFdtAll(self): @@ -1933,8 +1933,8 @@ class TestFunctional(unittest.TestCase): 'tpl/u-boot-tpl.dtb.out']: dtb = fdt.Fdt.FromData(data[start:]) size = dtb._fdt_obj.totalsize() - pathname = tools.GetOutputFilename(os.path.split(fname)[1]) - outdata = tools.ReadFile(pathname) + pathname = tools.get_output_filename(os.path.split(fname)[1]) + outdata = tools.read_file(pathname) name = os.path.split(fname)[0] if name: @@ -2027,10 +2027,10 @@ class TestFunctional(unittest.TestCase): """Test an expanding entry""" data, _, map_data, _ = self._DoReadFileDtb('088_expand_size.dts', map=True) - 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)) + expect = (tools.get_bytes(ord('a'), 8) + U_BOOT_DATA + + MRC_DATA + tools.get_bytes(ord('b'), 1) + U_BOOT_DATA + + tools.get_bytes(ord('c'), 8) + U_BOOT_DATA + + tools.get_bytes(ord('d'), 8)) self.assertEqual(expect, data) self.assertEqual('''ImagePos Offset Size Name 00000000 00000000 00000028 main-section @@ -2085,7 +2085,7 @@ class TestFunctional(unittest.TestCase): hash_node = dtb.GetNode('/binman/section/hash').props['value'] m = hashlib.sha256() m.update(U_BOOT_DATA) - m.update(tools.GetBytes(ord('a'), 16)) + m.update(tools.get_bytes(ord('a'), 16)) self.assertEqual(m.digest(), b''.join(hash_node.value)) def testPackUBootTplMicrocode(self): @@ -2107,7 +2107,7 @@ class TestFunctional(unittest.TestCase): """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 + tools.GetBytes(ord('a'), 32 - 7) + expected = U_BOOT_DATA + MRC_DATA + tools.get_bytes(ord('a'), 32 - 7) self.assertEqual(expected, data[:32]) fhdr, fentries = fmap_util.DecodeFmap(data[32:]) @@ -2129,7 +2129,7 @@ class TestFunctional(unittest.TestCase): 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 + tools.GetBytes(ord('b'), 32 - 7) + expected = U_BOOT_DATA + MRC_DATA + tools.get_bytes(ord('b'), 32 - 7) self.assertEqual(expected, data[:32]) fhdr, fentries = fmap_util.DecodeFmap(data[36:]) @@ -2177,14 +2177,14 @@ class TestFunctional(unittest.TestCase): with test_util.capture_sys_output() as (stdout, stderr): with self.assertRaises(ValueError) as e: self._DoTestFile('014_pack_overlap.dts', map=True) - map_fname = tools.GetOutputFilename('image.map') + map_fname = tools.get_output_filename('image.map') self.assertEqual("Wrote map file '%s' to show errors\n" % map_fname, stdout.getvalue()) # We should not get an inmage, but there should be a map file - self.assertFalse(os.path.exists(tools.GetOutputFilename('image.bin'))) + self.assertFalse(os.path.exists(tools.get_output_filename('image.bin'))) self.assertTrue(os.path.exists(map_fname)) - map_data = tools.ReadFile(map_fname, binary=False) + map_data = tools.read_file(map_fname, binary=False) self.assertEqual('''ImagePos Offset Size Name 00000000 00000008 main-section 00000000 00000004 u-boot @@ -2210,12 +2210,12 @@ class TestFunctional(unittest.TestCase): 0000002c 00000000 00000004 u-boot ''', map_data) self.assertEqual(data, - 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)) + tools.get_bytes(0x26, 4) + U_BOOT_DATA + + tools.get_bytes(0x21, 12) + + tools.get_bytes(0x26, 4) + U_BOOT_DATA + + tools.get_bytes(0x61, 12) + + tools.get_bytes(0x26, 4) + U_BOOT_DATA + + tools.get_bytes(0x26, 8)) def testCbfsRaw(self): """Test base handling of a Coreboot Filesystem (CBFS) @@ -2332,17 +2332,17 @@ class TestFunctional(unittest.TestCase): Args: data: Conents of output file """ - expected_desc = tools.ReadFile(self.TestFile('descriptor.bin')) + expected_desc = tools.read_file(self.TestFile('descriptor.bin')) if data[:0x1000] != expected_desc: self.fail('Expected descriptor binary at start of image') # We expect to find the TPL wil in subpart IBBP entry IBBL - image_fname = tools.GetOutputFilename('image.bin') - tpl_fname = tools.GetOutputFilename('tpl.out') + image_fname = tools.get_output_filename('image.bin') + tpl_fname = tools.get_output_filename('tpl.out') ifwitool = bintool.Bintool.create('ifwitool') ifwitool.extract(image_fname, 'IBBP', 'IBBL', tpl_fname) - tpl_data = tools.ReadFile(tpl_fname) + tpl_data = tools.read_file(tpl_fname) self.assertEqual(U_BOOT_TPL_DATA, tpl_data[:len(U_BOOT_TPL_DATA)]) def testPackX86RomIfwi(self): @@ -2403,7 +2403,7 @@ class TestFunctional(unittest.TestCase): fdtmap_data = data[len(U_BOOT_DATA):] magic = fdtmap_data[:8] self.assertEqual(b'_FDTMAP_', magic) - self.assertEqual(tools.GetBytes(0, 8), fdtmap_data[8:16]) + self.assertEqual(tools.get_bytes(0, 8), fdtmap_data[8:16]) fdt_data = fdtmap_data[16:] dtb = fdt.Fdt.FromData(fdt_data) @@ -2668,7 +2668,7 @@ class TestFunctional(unittest.TestCase): """Test reading an image and accessing its FDT map""" self._CheckLz4() data = self.data = self._DoReadFileRealDtb('128_decode_image.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') orig_image = control.images['image'] image = Image.FromFile(image_fname) self.assertEqual(orig_image.GetEntries().keys(), @@ -2684,7 +2684,7 @@ class TestFunctional(unittest.TestCase): """Test accessing an image's FDT map without an image header""" self._CheckLz4() data = self._DoReadFileRealDtb('129_decode_image_nohdr.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') image = Image.FromFile(image_fname) self.assertTrue(isinstance(image, Image)) self.assertEqual('image', image.image_name[-5:]) @@ -2692,7 +2692,7 @@ class TestFunctional(unittest.TestCase): def testReadImageFail(self): """Test failing to read an image image's FDT map""" self._DoReadFile('005_simple.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') with self.assertRaises(ValueError) as e: image = Image.FromFile(image_fname) self.assertIn("Cannot find FDT map in image", str(e.exception)) @@ -2752,7 +2752,7 @@ class TestFunctional(unittest.TestCase): """ self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') image = Image.FromFile(image_fname) lines = image.GetListEntries(paths)[1] files = [line[0].strip() for line in lines[1:]] @@ -2798,7 +2798,7 @@ class TestFunctional(unittest.TestCase): """ self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') return control.ReadEntry(image_fname, entry_name, decomp) def testExtractSimple(self): @@ -2858,7 +2858,7 @@ class TestFunctional(unittest.TestCase): def testExtractBadFile(self): """Test extracting an invalid file""" fname = os.path.join(self._indir, 'badfile') - tools.WriteFile(fname, b'') + tools.write_file(fname, b'') with self.assertRaises(ValueError) as e: control.ReadEntry(fname, 'name') @@ -2874,17 +2874,17 @@ class TestFunctional(unittest.TestCase): '-f', fname) finally: shutil.rmtree(tmpdir) - data = tools.ReadFile(fname) + data = tools.read_file(fname) self.assertEqual(U_BOOT_DATA, data) def testExtractOneEntry(self): """Test extracting a single entry fron an image """ self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') fname = os.path.join(self._indir, 'output.extact') control.ExtractEntries(image_fname, fname, None, ['u-boot']) - data = tools.ReadFile(fname) + data = tools.read_file(fname) self.assertEqual(U_BOOT_DATA, data) def _CheckExtractOutput(self, decomp): @@ -2906,7 +2906,7 @@ class TestFunctional(unittest.TestCase): expect_size: Size of data to expect in file, or None to skip """ path = os.path.join(outdir, entry_path) - data = tools.ReadFile(path) + data = tools.read_file(path) os.remove(path) if expect_data: self.assertEqual(expect_data, data) @@ -2926,7 +2926,7 @@ class TestFunctional(unittest.TestCase): os.rmdir(path) self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') outdir = os.path.join(self._indir, 'extract') einfos = control.ExtractEntries(image_fname, None, outdir, [], decomp) @@ -2962,7 +2962,7 @@ class TestFunctional(unittest.TestCase): _CheckPresent('section/root', section.data) cbfs = section_entries['cbfs'] _CheckPresent('section/cbfs/root', cbfs.data) - data = tools.ReadFile(image_fname) + data = tools.read_file(image_fname) _CheckPresent('root', data) # There should be no files left. Remove all the directories to check. @@ -2987,7 +2987,7 @@ class TestFunctional(unittest.TestCase): """Test extracting some entries""" self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') outdir = os.path.join(self._indir, 'extract') einfos = control.ExtractEntries(image_fname, None, outdir, ['*cb*', '*head*']) @@ -3002,7 +3002,7 @@ class TestFunctional(unittest.TestCase): """Test extracting some entries""" self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') with self.assertRaises(ValueError) as e: control.ExtractEntries(image_fname, 'fname', None, []) self.assertIn('Must specify an entry path to write with -f', @@ -3012,7 +3012,7 @@ class TestFunctional(unittest.TestCase): """Test extracting some entries""" self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') with self.assertRaises(ValueError) as e: control.ExtractEntries(image_fname, 'fname', None, ['a', 'b']) self.assertIn('Must specify exactly one entry path to write with -f', @@ -3113,9 +3113,9 @@ class TestFunctional(unittest.TestCase): orig_dtb_data = entries['u-boot-dtb'].data orig_fdtmap_data = entries['fdtmap'].data - image_fname = tools.GetOutputFilename('image.bin') - updated_fname = tools.GetOutputFilename('image-updated.bin') - tools.WriteFile(updated_fname, tools.ReadFile(image_fname)) + image_fname = tools.get_output_filename('image.bin') + updated_fname = tools.get_output_filename('image-updated.bin') + tools.write_file(updated_fname, tools.read_file(image_fname)) image = control.WriteEntry(updated_fname, entry_name, data, decomp, allow_resize) data = control.ReadEntry(updated_fname, entry_name, decomp) @@ -3170,8 +3170,8 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFileDtb('133_replace_multi.dts', use_real_dtb=True, update_dtb=True)[0] expected = b'x' * len(U_BOOT_DATA) - updated_fname = tools.GetOutputFilename('image-updated.bin') - tools.WriteFile(updated_fname, data) + updated_fname = tools.get_output_filename('image-updated.bin') + tools.write_file(updated_fname, data) entry_name = 'u-boot' control.WriteEntry(updated_fname, entry_name, expected, allow_resize=False) @@ -3182,9 +3182,9 @@ class TestFunctional(unittest.TestCase): self.assertEqual('/binman/image', state.fdt_path_prefix) # Now check we can write the first image - image_fname = tools.GetOutputFilename('first-image.bin') - updated_fname = tools.GetOutputFilename('first-updated.bin') - tools.WriteFile(updated_fname, tools.ReadFile(image_fname)) + image_fname = tools.get_output_filename('first-image.bin') + updated_fname = tools.get_output_filename('first-updated.bin') + tools.write_file(updated_fname, tools.read_file(image_fname)) entry_name = 'u-boot' control.WriteEntry(updated_fname, entry_name, expected, allow_resize=False) @@ -3348,8 +3348,8 @@ class TestFunctional(unittest.TestCase): self._CheckLz4() expected = b'x' * len(U_BOOT_DATA) data = self._DoReadFileRealDtb('142_replace_cbfs.dts') - updated_fname = tools.GetOutputFilename('image-updated.bin') - tools.WriteFile(updated_fname, data) + updated_fname = tools.get_output_filename('image-updated.bin') + tools.write_file(updated_fname, data) entry_name = 'section/cbfs/u-boot' control.WriteEntry(updated_fname, entry_name, expected, allow_resize=True) @@ -3361,8 +3361,8 @@ class TestFunctional(unittest.TestCase): self._CheckLz4() expected = U_BOOT_DATA + b'x' data = self._DoReadFileRealDtb('142_replace_cbfs.dts') - updated_fname = tools.GetOutputFilename('image-updated.bin') - tools.WriteFile(updated_fname, data) + updated_fname = tools.get_output_filename('image-updated.bin') + tools.write_file(updated_fname, data) entry_name = 'section/cbfs/u-boot' control.WriteEntry(updated_fname, entry_name, expected, allow_resize=True) @@ -3383,23 +3383,23 @@ class TestFunctional(unittest.TestCase): """ data = self._DoReadFileRealDtb('143_replace_all.dts') - updated_fname = tools.GetOutputFilename('image-updated.bin') - tools.WriteFile(updated_fname, data) + updated_fname = tools.get_output_filename('image-updated.bin') + tools.write_file(updated_fname, data) outdir = os.path.join(self._indir, 'extract') einfos = control.ExtractEntries(updated_fname, None, outdir, []) expected1 = b'x' + U_BOOT_DATA + b'y' u_boot_fname1 = os.path.join(outdir, 'u-boot') - tools.WriteFile(u_boot_fname1, expected1) + tools.write_file(u_boot_fname1, expected1) expected2 = b'a' + U_BOOT_DATA + b'b' u_boot_fname2 = os.path.join(outdir, 'u-boot2') - tools.WriteFile(u_boot_fname2, expected2) + tools.write_file(u_boot_fname2, expected2) expected_text = b'not the same text' text_fname = os.path.join(outdir, 'text') - tools.WriteFile(text_fname, expected_text) + tools.write_file(text_fname, expected_text) dtb_fname = os.path.join(outdir, 'u-boot-dtb') dtb = fdt.FdtScan(dtb_fname) @@ -3475,10 +3475,10 @@ class TestFunctional(unittest.TestCase): fname = os.path.join(tmpdir, 'update-u-boot.bin') expected = b'x' * len(U_BOOT_DATA) - tools.WriteFile(fname, expected) + tools.write_file(fname, expected) self._DoBinman('replace', '-i', updated_fname, 'u-boot', '-f', fname) - data = tools.ReadFile(updated_fname) + data = tools.read_file(updated_fname) self.assertEqual(expected, data[:len(expected)]) map_fname = os.path.join(tmpdir, 'image-updated.map') self.assertFalse(os.path.exists(map_fname)) @@ -3493,7 +3493,7 @@ class TestFunctional(unittest.TestCase): self._DoBinman('replace', '-i', updated_fname, '-I', outdir, 'u-boot2', 'text') - tools.PrepareOutputDir(None) + tools.prepare_output_dir(None) image = Image.FromFile(updated_fname) image.LoadData() entries = image.GetEntries() @@ -3531,7 +3531,7 @@ class TestFunctional(unittest.TestCase): fname = os.path.join(self._indir, 'update-u-boot.bin') expected = b'x' * len(U_BOOT_DATA) - tools.WriteFile(fname, expected) + tools.write_file(fname, expected) self._DoBinman('replace', '-i', updated_fname, 'u-boot', '-f', fname, '-m') @@ -3543,7 +3543,7 @@ class TestFunctional(unittest.TestCase): def testReplaceNoEntryPaths(self): """Test replacing an entry without an entry path""" self._DoReadFileRealDtb('143_replace_all.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') with self.assertRaises(ValueError) as e: control.ReplaceEntries(image_fname, 'fname', None, []) self.assertIn('Must specify an entry path to read with -f', @@ -3552,7 +3552,7 @@ class TestFunctional(unittest.TestCase): def testReplaceTooManyEntryPaths(self): """Test extracting some entries""" self._DoReadFileRealDtb('143_replace_all.dts') - image_fname = tools.GetOutputFilename('image.bin') + image_fname = tools.get_output_filename('image.bin') with self.assertRaises(ValueError) as e: control.ReplaceEntries(image_fname, 'fname', None, ['a', 'b']) self.assertIn('Must specify exactly one entry path to write with -f', @@ -3597,15 +3597,15 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile(dts) sym_values = struct.pack(' Date: Sat, 29 Jan 2022 14:14:05 -0700 Subject: patman: Convert camel case in command.py Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 21adf433fe3..f85581ccd42 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -282,7 +282,7 @@ class TestFunctional(unittest.TestCase): Arguments to pass, as a list of strings kwargs: Arguments to pass to Command.RunPipe() """ - result = command.RunPipe([[self._binman_pathname] + list(args)], + result = command.run_pipe([[self._binman_pathname] + list(args)], capture=True, capture_stderr=True, raise_on_error=False) if result.return_code and kwargs.get('raise_on_error', True): raise Exception("Error running '%s': %s" % (' '.join(args), -- cgit v1.2.3 From f3385a5b1c2024e33e276aef829a4da43ceee0fe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 29 Jan 2022 14:14:15 -0700 Subject: patman: Convert camel case in tout.py Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index f85581ccd42..123fdb15f78 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -240,7 +240,7 @@ class TestFunctional(unittest.TestCase): def setUp(self): # Enable this to turn on debugging output - # tout.Init(tout.DEBUG) + # tout.init(tout.DEBUG) command.test_result = None def tearDown(self): -- cgit v1.2.3 From 21353311ffe9bf28e168ab7d69ec670f0093cf96 Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Tue, 8 Feb 2022 01:08:04 +0300 Subject: binman: Fix subentry expansion for FIT entry type Binman tries to expand some entries into parts that make it up, e.g. 'u-boot' into a 'u-boot-expanded' section that contains 'u-boot-nodtb' and 'u-boot-dtb'. Entries with child entries must call ExpandEntries() on them to build a correct image, as it's possible that unexpanded child entries have no data of their own. The FIT entry type doesn't currently do this, which means putting a "u-boot" entry inside it doesn't work as expected. Implement ExpandEntries() for FIT and add a copy of a simple FIT image test that checks subentry expansion in FIT entries. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/ftest.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 123fdb15f78..16956e00e94 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -61,6 +61,9 @@ 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' +U_BOOT_EXP_DATA = U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA +U_BOOT_SPL_EXP_DATA = U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA +U_BOOT_TPL_EXP_DATA = U_BOOT_TPL_NODTB_DATA + U_BOOT_TPL_DTB_DATA FSP_DATA = b'fsp' CMC_DATA = b'cmc' VBT_DATA = b'vbt' @@ -3713,13 +3716,7 @@ class TestFunctional(unittest.TestCase): """Test that zero-size overlapping regions are ignored""" self._DoTestFile('160_pack_overlap_zero.dts') - def testSimpleFit(self): - """Test an image with a FIT inside""" - data = self._DoReadFile('161_fit.dts') - self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)]) - self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) - fit_data = data[len(U_BOOT_DATA):-len(U_BOOT_NODTB_DATA)] - + def _CheckSimpleFitData(self, fit_data, kernel_data, fdt1_data): # The data should be inside the FIT dtb = fdt.Fdt.FromData(fit_data) dtb.Scan() @@ -3752,8 +3749,26 @@ class TestFunctional(unittest.TestCase): self.assertIsNotNone(data_sizes) self.assertEqual(2, len(data_sizes)) # Format is "4 Bytes = 0.00 KiB = 0.00 MiB" so take the first word - self.assertEqual(len(U_BOOT_DATA), int(data_sizes[0].split()[0])) - self.assertEqual(len(U_BOOT_SPL_DTB_DATA), int(data_sizes[1].split()[0])) + self.assertEqual(len(kernel_data), int(data_sizes[0].split()[0])) + self.assertEqual(len(fdt1_data), int(data_sizes[1].split()[0])) + + def testSimpleFit(self): + """Test an image with a FIT inside""" + data = self._DoReadFile('161_fit.dts') + self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)]) + self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) + fit_data = data[len(U_BOOT_DATA):-len(U_BOOT_NODTB_DATA)] + + self._CheckSimpleFitData(fit_data, U_BOOT_DATA, U_BOOT_SPL_DTB_DATA) + + def testSimpleFitExpandsSubentries(self): + """Test that FIT images expand their subentries""" + data = self._DoReadFileDtb('161_fit.dts', use_expanded=True)[0] + self.assertEqual(U_BOOT_EXP_DATA, data[:len(U_BOOT_EXP_DATA)]) + self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) + fit_data = data[len(U_BOOT_EXP_DATA):-len(U_BOOT_NODTB_DATA)] + + self._CheckSimpleFitData(fit_data, U_BOOT_EXP_DATA, U_BOOT_SPL_DTB_DATA) def testFitExternal(self): """Test an image with an FIT with external images""" -- cgit v1.2.3 From ed293c322188d9d41bf6f26e01ad6343974150d1 Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Tue, 8 Feb 2022 01:08:05 +0300 Subject: binman: Register and check bintools from FIT subentries Binman keeps track of binary tools each entry wants to use. The implementation of this for the FIT entry only adds "mkimage", but not the tools that would be used by its subentries. Register the binary tools that FIT subentries will use in addition to the one FIT itself uses, and check their existence by copying the appropriate method from Section entry type. Also add tests that check if these subentries can use and warn about binary tools. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- tools/binman/ftest.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 16956e00e94..dc14a74904a 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5133,6 +5133,31 @@ fdt fdtmap Extract the devicetree blob from the fdtmap finally: shutil.rmtree(tmpdir) + def testFitSubentryUsesBintool(self): + """Test that binman FIT subentries can use bintools""" + command.test_result = self._HandleGbbCommand + entry_args = { + 'keydir': 'devkeys', + 'bmpblk': 'bmpblk.bin', + } + data, _, _, _ = self._DoReadFileDtb('220_fit_subentry_bintool.dts', + entry_args=entry_args) + + expected = (GBB_DATA + GBB_DATA + tools.GetBytes(0, 8) + + tools.GetBytes(0, 0x2180 - 16)) + self.assertIn(expected, data) + + def testFitSubentryMissingBintool(self): + """Test that binman reports missing bintools for FIT subentries""" + entry_args = { + 'keydir': 'devkeys', + } + with test_util.capture_sys_output() as (_, stderr): + self._DoTestFile('220_fit_subentry_bintool.dts', + force_missing_bintools='futility', entry_args=entry_args) + err = stderr.getvalue() + self.assertRegex(err, + "Image 'main-section'.*missing bintools.*: futility") if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From f3078d4ea707931c2307a623ecf6e4d215b413d5 Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Tue, 8 Feb 2022 01:08:07 +0300 Subject: binman: Convert FIT entry type to a subclass of Section entry type The binman FIT entry type shares some code with the Section entry type. This shared code is bound to grow, since FIT entries are conceptually a variation of Section entries. Make FIT entry type a subclass of Section entry type, simplifying it a bit and providing us the features that Section implements. Also fix the subentry alignment test which now attempts to write symbols to a nonexistent SPL ELF test file by creating it first. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass Avoid AddMissingProperties() and SetCalculatedProperties() with FIT: Signed-off-by: Simon Glass --- tools/binman/ftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/binman/ftest.py') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index dc14a74904a..59b6d52fbe4 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -3850,6 +3850,7 @@ class TestFunctional(unittest.TestCase): def testFitImageSubentryAlignment(self): """Test relative alignability of FIT image subentries""" + self._SetupSplElf() entry_args = { 'test-id': TEXT_DATA, } @@ -5143,8 +5144,8 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data, _, _, _ = self._DoReadFileDtb('220_fit_subentry_bintool.dts', entry_args=entry_args) - expected = (GBB_DATA + GBB_DATA + tools.GetBytes(0, 8) + - tools.GetBytes(0, 0x2180 - 16)) + expected = (GBB_DATA + GBB_DATA + tools.get_bytes(0, 8) + + tools.get_bytes(0, 0x2180 - 16)) self.assertIn(expected, data) def testFitSubentryMissingBintool(self): -- cgit v1.2.3