diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py index e2e5660d16..068d766c50 100644 --- a/tools/binman/bintool.py +++ b/tools/binman/bintool.py @@ -327,9 +327,9 @@ class Bintool: """ tmpdir = tempfile.mkdtemp(prefix='binmanf.') print(f"- clone git repo '{git_repo}' to '{tmpdir}'") - tools.Run('git', 'clone', '--depth', '1', git_repo, tmpdir) + tools.run('git', 'clone', '--depth', '1', git_repo, tmpdir) print(f"- build target '{make_target}'") - tools.Run('make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}', + tools.run('make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}', make_target) fname = os.path.join(tmpdir, bintool_path) if not os.path.exists(fname): @@ -349,8 +349,8 @@ class Bintool: str: Filename of fetched file to copy to a suitable directory str: Name of temp directory to remove, or None """ - fname, tmpdir = tools.Download(url) - tools.Run('chmod', 'a+x', fname) + fname, tmpdir = tools.download(url) + tools.run('chmod', 'a+x', fname) return fname, tmpdir @classmethod @@ -384,7 +384,7 @@ class Bintool: """ args = ['sudo', 'apt', 'install', '-y', package] print('- %s' % ' '.join(args)) - tools.Run(*args) + tools.run(*args) return True @staticmethod diff --git a/tools/binman/bintool_test.py b/tools/binman/bintool_test.py index 3d6bcdab9d..7efb8391db 100644 --- a/tools/binman/bintool_test.py +++ b/tools/binman/bintool_test.py @@ -80,7 +80,7 @@ class TestBintool(unittest.TestCase): Args: fake_download (function): Function to call instead of - tools.Download() + tools.download() method (bintool.FETCH_...: Fetch method to use Returns: @@ -88,7 +88,7 @@ class TestBintool(unittest.TestCase): """ btest = Bintool.create('_testing') col = terminal.Color() - with unittest.mock.patch.object(tools, 'Download', + with unittest.mock.patch.object(tools, 'download', side_effect=fake_download): with test_util.capture_sys_output() as (stdout, _): btest.fetch_tool(method, col, False) @@ -97,7 +97,7 @@ class TestBintool(unittest.TestCase): def test_fetch_url_err(self): """Test an error while fetching a tool from a URL""" def fail_download(url): - """Take the tools.Download() function by raising an exception""" + """Take the tools.download() function by raising an exception""" raise urllib.error.URLError('my error') stdout = self.check_fetch_url(fail_download, bintool.FETCH_ANY) @@ -114,7 +114,7 @@ class TestBintool(unittest.TestCase): def test_fetch_method(self): """Test fetching using a particular method""" def fail_download(url): - """Take the tools.Download() function by raising an exception""" + """Take the tools.download() function by raising an exception""" raise urllib.error.URLError('my error') stdout = self.check_fetch_url(fail_download, bintool.FETCH_BIN) @@ -123,11 +123,11 @@ class TestBintool(unittest.TestCase): def test_fetch_pass_fail(self): """Test fetching multiple tools with some passing and some failing""" def handle_download(_): - """Take the tools.Download() function by writing a file""" + """Take the tools.download() function by writing a file""" if self.seq: raise urllib.error.URLError('not found') self.seq += 1 - tools.WriteFile(fname, expected) + tools.write_file(fname, expected) return fname, dirname expected = b'this is a test' @@ -140,12 +140,12 @@ class TestBintool(unittest.TestCase): self.seq = 0 with unittest.mock.patch.object(bintool, 'DOWNLOAD_DESTDIR', destdir): - with unittest.mock.patch.object(tools, 'Download', + with unittest.mock.patch.object(tools, 'download', side_effect=handle_download): with test_util.capture_sys_output() as (stdout, _): Bintool.fetch_tools(bintool.FETCH_ANY, ['_testing'] * 2) self.assertTrue(os.path.exists(dest_fname)) - data = tools.ReadFile(dest_fname) + data = tools.read_file(dest_fname) self.assertEqual(expected, data) lines = stdout.getvalue().splitlines() @@ -245,14 +245,14 @@ class TestBintool(unittest.TestCase): tmpdir = cmd[2] self.fname = os.path.join(tmpdir, 'pathname') if write_file: - tools.WriteFile(self.fname, b'hello') + tools.write_file(self.fname, b'hello') btest = Bintool.create('_testing') col = terminal.Color() self.fname = None with unittest.mock.patch.object(bintool, 'DOWNLOAD_DESTDIR', self._indir): - with unittest.mock.patch.object(tools, 'Run', side_effect=fake_run): + with unittest.mock.patch.object(tools, 'run', side_effect=fake_run): with test_util.capture_sys_output() as (stdout, _): btest.fetch_tool(bintool.FETCH_BUILD, col, False) fname = os.path.join(self._indir, '_testing') @@ -275,7 +275,7 @@ class TestBintool(unittest.TestCase): btest = Bintool.create('_testing') btest.install = True col = terminal.Color() - with unittest.mock.patch.object(tools, 'Run', return_value=None): + with unittest.mock.patch.object(tools, 'run', return_value=None): with test_util.capture_sys_output() as _: result = btest.fetch_tool(bintool.FETCH_BIN, col, False) self.assertEqual(bintool.FETCHED, result) @@ -292,8 +292,8 @@ class TestBintool(unittest.TestCase): def test_all_bintools(self): """Test that all bintools can handle all available fetch types""" def handle_download(_): - """Take the tools.Download() function by writing a file""" - tools.WriteFile(fname, expected) + """Take the tools.download() function by writing a file""" + tools.write_file(fname, expected) return fname, dirname def fake_run(*cmd): @@ -301,15 +301,15 @@ class TestBintool(unittest.TestCase): # See Bintool.build_from_git() tmpdir = cmd[2] self.fname = os.path.join(tmpdir, 'pathname') - tools.WriteFile(self.fname, b'hello') + tools.write_file(self.fname, b'hello') expected = b'this is a test' dirname = os.path.join(self._indir, 'download_dir') os.mkdir(dirname) fname = os.path.join(dirname, 'downloaded') - with unittest.mock.patch.object(tools, 'Run', side_effect=fake_run): - with unittest.mock.patch.object(tools, 'Download', + with unittest.mock.patch.object(tools, 'run', side_effect=fake_run): + with unittest.mock.patch.object(tools, 'download', side_effect=handle_download): with test_util.capture_sys_output() as _: for name in Bintool.get_tool_list(): @@ -320,7 +320,7 @@ class TestBintool(unittest.TestCase): if result is not True and result is not None: result_fname, _ = result self.assertTrue(os.path.exists(result_fname)) - data = tools.ReadFile(result_fname) + data = tools.read_file(result_fname) self.assertEqual(expected, data) os.remove(result_fname) diff --git a/tools/binman/btool/lz4.py b/tools/binman/btool/lz4.py index d165f52da9..f09c5c8904 100644 --- a/tools/binman/btool/lz4.py +++ b/tools/binman/btool/lz4.py @@ -88,8 +88,8 @@ class Bintoollz4(bintool.Bintool): bytes: Compressed data """ with tempfile.NamedTemporaryFile(prefix='comp.tmp', - dir=tools.GetOutputDir()) as tmp: - tools.WriteFile(tmp.name, indata) + dir=tools.get_output_dir()) as tmp: + tools.write_file(tmp.name, indata) args = ['--no-frame-crc', '-B4', '-5', '-c', tmp.name] return self.run_cmd(*args, binary=True) @@ -103,8 +103,8 @@ class Bintoollz4(bintool.Bintool): bytes: Decompressed data """ with tempfile.NamedTemporaryFile(prefix='decomp.tmp', - dir=tools.GetOutputDir()) as inf: - tools.WriteFile(inf.name, indata) + dir=tools.get_output_dir()) as inf: + tools.write_file(inf.name, indata) args = ['-cd', inf.name] return self.run_cmd(*args, binary=True) diff --git a/tools/binman/btool/lzma_alone.py b/tools/binman/btool/lzma_alone.py index d7c62dfd2a..52a960fd2f 100644 --- a/tools/binman/btool/lzma_alone.py +++ b/tools/binman/btool/lzma_alone.py @@ -65,13 +65,13 @@ class Bintoollzma_alone(bintool.Bintool): bytes: Compressed data """ with tempfile.NamedTemporaryFile(prefix='comp.tmp', - dir=tools.GetOutputDir()) as inf: - tools.WriteFile(inf.name, indata) + dir=tools.get_output_dir()) as inf: + tools.write_file(inf.name, indata) with tempfile.NamedTemporaryFile(prefix='compo.otmp', - dir=tools.GetOutputDir()) as outf: + dir=tools.get_output_dir()) as outf: args = ['e', inf.name, outf.name, '-lc1', '-lp0', '-pb0', '-d8'] self.run_cmd(*args, binary=True) - return tools.ReadFile(outf.name) + return tools.read_file(outf.name) def decompress(self, indata): """Decompress data with lzma_alone @@ -83,13 +83,13 @@ class Bintoollzma_alone(bintool.Bintool): bytes: Decompressed data """ with tempfile.NamedTemporaryFile(prefix='decomp.tmp', - dir=tools.GetOutputDir()) as inf: - tools.WriteFile(inf.name, indata) + dir=tools.get_output_dir()) as inf: + tools.write_file(inf.name, indata) with tempfile.NamedTemporaryFile(prefix='compo.otmp', - dir=tools.GetOutputDir()) as outf: + dir=tools.get_output_dir()) as outf: args = ['d', inf.name, outf.name] self.run_cmd(*args, binary=True) - return tools.ReadFile(outf.name, binary=True) + return tools.read_file(outf.name, binary=True) def fetch(self, method): """Fetch handler for lzma_alone diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py index eea7868b16..9cad03886f 100644 --- a/tools/binman/cbfs_util.py +++ b/tools/binman/cbfs_util.py @@ -189,9 +189,9 @@ def _pack_string(instr): Returns: String with required padding (at least one 0x00 byte) at the end """ - val = tools.ToBytes(instr) + val = tools.to_bytes(instr) pad_len = align_int(len(val) + 1, FILENAME_ALIGN) - return val + tools.GetBytes(0, pad_len - len(val)) + return val + tools.get_bytes(0, pad_len - len(val)) class CbfsFile(object): @@ -371,7 +371,7 @@ class CbfsFile(object): FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN, self.compress, self.memlen) elif self.ftype == TYPE_EMPTY: - data = tools.GetBytes(self.erase_byte, self.size) + data = tools.get_bytes(self.erase_byte, self.size) else: raise ValueError('Unknown type %#x when writing\n' % self.ftype) if attr: @@ -388,7 +388,7 @@ class CbfsFile(object): # possible. raise ValueError("Internal error: CBFS file '%s': Requested offset %#x but current output position is %#x" % (self.name, self.cbfs_offset, offset)) - pad = tools.GetBytes(pad_byte, pad_len) + pad = tools.get_bytes(pad_byte, pad_len) hdr_len += pad_len # This is the offset of the start of the file's data, @@ -414,7 +414,7 @@ class CbfsWriter(object): Usage is something like: cbw = CbfsWriter(size) - cbw.add_file_raw('u-boot', tools.ReadFile('u-boot.bin')) + cbw.add_file_raw('u-boot', tools.read_file('u-boot.bin')) ... data, cbfs_offset = cbw.get_data_and_offset() @@ -482,7 +482,7 @@ class CbfsWriter(object): if fd.tell() > offset: raise ValueError('No space for data before offset %#x (current offset %#x)' % (offset, fd.tell())) - fd.write(tools.GetBytes(self._erase_byte, offset - fd.tell())) + fd.write(tools.get_bytes(self._erase_byte, offset - fd.tell())) def _pad_to(self, fd, offset): """Write out pad bytes and/or an empty file until a given offset diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py index 494f6145ed..f86b295149 100755 --- a/tools/binman/cbfs_util_test.py +++ b/tools/binman/cbfs_util_test.py @@ -36,7 +36,7 @@ class TestCbfs(unittest.TestCase): def setUpClass(cls): # Create a temporary directory for test files cls._indir = tempfile.mkdtemp(prefix='cbfs_util.') - tools.SetInputDirs([cls._indir]) + tools.set_input_dirs([cls._indir]) # Set up some useful data files TestCbfs._make_input_file('u-boot.bin', U_BOOT_DATA) @@ -45,7 +45,7 @@ class TestCbfs(unittest.TestCase): # Set up a temporary output directory, used by the tools library when # compressing files - tools.PrepareOutputDir(None) + tools.prepare_output_dir(None) cls.cbfstool = bintool.Bintool.create('cbfstool') cls.have_cbfstool = cls.cbfstool.is_present() @@ -58,7 +58,7 @@ class TestCbfs(unittest.TestCase): if cls._indir: shutil.rmtree(cls._indir) cls._indir = None - tools.FinaliseOutputDir() + tools.finalise_output_dir() @classmethod def _make_input_file(cls, fname, contents): @@ -71,7 +71,7 @@ class TestCbfs(unittest.TestCase): Full pathname of file created """ pathname = os.path.join(cls._indir, fname) - tools.WriteFile(pathname, contents) + tools.write_file(pathname, contents) return pathname def _check_hdr(self, data, size, offset=0, arch=cbfs_util.ARCHITECTURE_X86): @@ -176,12 +176,12 @@ class TestCbfs(unittest.TestCase): base = [(1 << 32) - size + b for b in base] self.cbfstool.add_raw( cbfs_fname, 'u-boot', - tools.GetInputFilename(compress and 'compress' or 'u-boot.bin'), + tools.get_input_filename(compress and 'compress' or 'u-boot.bin'), compress[0] if compress else None, base[0] if base else None) self.cbfstool.add_raw( cbfs_fname, 'u-boot-dtb', - tools.GetInputFilename(compress and 'compress' or 'u-boot.dtb'), + tools.get_input_filename(compress and 'compress' or 'u-boot.dtb'), compress[1] if compress else None, base[1] if base else None) return cbfs_fname @@ -198,10 +198,10 @@ class TestCbfs(unittest.TestCase): """ if not self.have_cbfstool or not self.have_lz4: return - expect = tools.ReadFile(cbfstool_fname) + expect = tools.read_file(cbfstool_fname) if expect != data: - tools.WriteFile('/tmp/expect', expect) - tools.WriteFile('/tmp/actual', data) + tools.write_file('/tmp/expect', expect) + tools.write_file('/tmp/actual', data) print('diff -y <(xxd -g1 /tmp/expect) <(xxd -g1 /tmp/actual) | colordiff') self.fail('cbfstool produced a different result') @@ -482,7 +482,7 @@ class TestCbfs(unittest.TestCase): size = 0xb0 cbw = CbfsWriter(size) - cbw.add_file_stage('u-boot', tools.ReadFile(elf_fname)) + cbw.add_file_stage('u-boot', tools.read_file(elf_fname)) data = cbw.get_data() cbfs = self._check_hdr(data, size) diff --git a/tools/binman/control.py b/tools/binman/control.py index 2daad05b80..305f14bad3 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -258,7 +258,7 @@ def ExtractEntries(image_fname, output_fname, outdir, entry_paths, raise ValueError('Must specify exactly one entry path to write with -f') entry = image.FindEntryPath(entry_paths[0]) data = entry.ReadData(decomp, alt_format) - tools.WriteFile(output_fname, data) + tools.write_file(output_fname, data) tout.Notice("Wrote %#x bytes to file '%s'" % (len(data), output_fname)) return @@ -281,7 +281,7 @@ def ExtractEntries(image_fname, output_fname, outdir, entry_paths, fname = os.path.join(fname, 'root') tout.Notice("Write entry '%s' size %x to '%s'" % (entry.GetPath(), len(data), fname)) - tools.WriteFile(fname, data) + tools.write_file(fname, data) return einfos @@ -398,7 +398,7 @@ def ReplaceEntries(image_fname, input_fname, indir, entry_paths, if len(entry_paths) != 1: raise ValueError('Must specify exactly one entry path to write with -f') entry = image.FindEntryPath(entry_paths[0]) - data = tools.ReadFile(input_fname) + data = tools.read_file(input_fname) tout.Notice("Read %#x bytes from file '%s'" % (len(data), input_fname)) WriteEntryToImage(image, entry, data, do_compress=do_compress, allow_resize=allow_resize, write_map=write_map) @@ -425,7 +425,7 @@ def ReplaceEntries(image_fname, input_fname, indir, entry_paths, if os.path.exists(fname): tout.Notice("Write entry '%s' from file '%s'" % (entry.GetPath(), fname)) - data = tools.ReadFile(fname) + data = tools.read_file(fname) ReplaceOneEntry(image, entry, data, do_compress, allow_resize) else: tout.Warning("Skipping entry '%s' from missing file '%s'" % @@ -468,8 +468,8 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): # output into a file in our output directly. Then scan it for use # in binman. dtb_fname = fdt_util.EnsureCompiled(dtb_fname) - fname = tools.GetOutputFilename('u-boot.dtb.out') - tools.WriteFile(fname, tools.ReadFile(dtb_fname)) + fname = tools.get_output_filename('u-boot.dtb.out') + tools.write_file(fname, tools.read_file(dtb_fname)) dtb = fdt.FdtScan(fname) node = _FindBinmanNode(dtb) @@ -618,7 +618,7 @@ def Binman(args): global state if args.full_help: - tools.PrintFullHelp( + tools.print_full_help( os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README.rst') ) return 0 @@ -630,7 +630,7 @@ def Binman(args): if args.cmd in ['ls', 'extract', 'replace', 'tool']: try: tout.Init(args.verbosity) - tools.PrepareOutputDir(None) + tools.prepare_output_dir(None) if args.cmd == 'ls': ListEntries(args.image, args.paths) @@ -644,7 +644,7 @@ def Binman(args): allow_resize=not args.fix_size, write_map=args.map) if args.cmd == 'tool': - tools.SetToolPaths(args.toolpath) + tools.set_tool_paths(args.toolpath) if args.list: bintool.Bintool.list_all() elif args.fetch: @@ -658,7 +658,7 @@ def Binman(args): except: raise finally: - tools.FinaliseOutputDir() + tools.finalise_output_dir() return 0 elf_params = None @@ -694,9 +694,9 @@ def Binman(args): # runtime. use_expanded = not args.no_expanded try: - tools.SetInputDirs(args.indir) - tools.PrepareOutputDir(args.outdir, args.preserve) - tools.SetToolPaths(args.toolpath) + tools.set_input_dirs(args.indir) + tools.prepare_output_dir(args.outdir, args.preserve) + tools.set_tool_paths(args.toolpath) state.SetEntryArgs(args.entry_arg) state.SetThreads(args.threads) @@ -717,7 +717,7 @@ def Binman(args): # Write the updated FDTs to our output files for dtb_item in state.GetAllFdts(): - tools.WriteFile(dtb_item._fname, dtb_item.GetContents()) + tools.write_file(dtb_item._fname, dtb_item.GetContents()) if elf_params: data = state.GetFdtForEtype('u-boot-dtb').GetContents() @@ -729,7 +729,7 @@ def Binman(args): # Use this to debug the time take to pack the image #state.TimingShow() finally: - tools.FinaliseOutputDir() + tools.finalise_output_dir() finally: tout.Uninit() diff --git a/tools/binman/elf.py b/tools/binman/elf.py index de2bb4651f..d22a0d4bf5 100644 --- a/tools/binman/elf.py +++ b/tools/binman/elf.py @@ -54,7 +54,7 @@ def GetSymbols(fname, patterns): key: Name of symbol value: Hex value of symbol """ - stdout = tools.Run('objdump', '-t', fname) + stdout = tools.run('objdump', '-t', fname) lines = stdout.splitlines() if patterns: re_syms = re.compile('|'.join(patterns)) @@ -154,7 +154,7 @@ def LookupAndWriteSymbols(elf_fname, entry, section): entry: Entry to process section: Section which can be used to lookup symbol values """ - fname = tools.GetInputFilename(elf_fname) + fname = tools.get_input_filename(elf_fname) syms = GetSymbols(fname, ['image', 'binman']) if not syms: return @@ -282,7 +282,7 @@ SECTIONS # text section at the start # -m32: Build for 32-bit x86 # -T...: Specifies the link script, which sets the start address - cc, args = tools.GetTargetCompileTool('cc') + cc, args = tools.get_target_compile_tool('cc') args += ['-static', '-nostdlib', '-Wl,--build-id=none', '-m32', '-T', lds_file, '-o', elf_fname, s_file] stdout = command.Output(cc, *args) @@ -363,9 +363,9 @@ def UpdateFile(infile, outfile, start_sym, end_sym, insert): raise ValueError("Not enough space in '%s' for data length %#x (%d); size is %#x (%d)" % (infile, len(insert), len(insert), size, size)) - data = tools.ReadFile(infile) + data = tools.read_file(infile) newdata = data[:syms[start_sym].offset] - newdata += insert + tools.GetBytes(0, size - len(insert)) + newdata += insert + tools.get_bytes(0, size - len(insert)) newdata += data[syms[end_sym].offset:] - tools.WriteFile(outfile, newdata) + tools.write_file(outfile, newdata) tout.Info('Written to offset %#x' % syms[start_sym].offset) diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index f727258487..b531062f4a 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -27,7 +27,7 @@ class FakeEntry: """ def __init__(self, contents_size): self.contents_size = contents_size - self.data = tools.GetBytes(ord('a'), contents_size) + self.data = tools.get_bytes(ord('a'), contents_size) def GetPath(self): return 'entry_path' @@ -72,7 +72,7 @@ def BuildElfTestFiles(target_dir): if 'MAKEFLAGS' in os.environ: del os.environ['MAKEFLAGS'] try: - tools.Run('make', '-C', target_dir, '-f', + tools.run('make', '-C', target_dir, '-f', os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir) except ValueError as e: # The test system seems to suppress this in a strange way @@ -83,7 +83,7 @@ class TestElf(unittest.TestCase): @classmethod def setUpClass(cls): cls._indir = tempfile.mkdtemp(prefix='elf.') - tools.SetInputDirs(['.']) + tools.set_input_dirs(['.']) BuildElfTestFiles(cls._indir) @classmethod @@ -166,7 +166,7 @@ class TestElf(unittest.TestCase): section = FakeSection(sym_value=None) elf_fname = self.ElfTestFile('u_boot_binman_syms') syms = elf.LookupAndWriteSymbols(elf_fname, entry, section) - self.assertEqual(tools.GetBytes(255, 20) + tools.GetBytes(ord('a'), 4), + self.assertEqual(tools.get_bytes(255, 20) + tools.get_bytes(ord('a'), 4), entry.data) def testDebug(self): @@ -193,7 +193,7 @@ class TestElf(unittest.TestCase): # Make an Elf file and then convert it to a fkat binary file. This # should produce the original data. elf.MakeElf(elf_fname, expected_text, expected_data) - objcopy, args = tools.GetTargetCompileTool('objcopy') + objcopy, args = tools.get_target_compile_tool('objcopy') args += ['-O', 'binary', elf_fname, bin_fname] stdout = command.Output(objcopy, *args) with open(bin_fname, 'rb') as fd: @@ -210,7 +210,7 @@ class TestElf(unittest.TestCase): expected_data = b'wxyz' elf_fname = os.path.join(outdir, 'elf') elf.MakeElf(elf_fname, expected_text, expected_data) - data = tools.ReadFile(elf_fname) + data = tools.read_file(elf_fname) load = 0xfef20000 entry = load + 2 @@ -231,7 +231,7 @@ class TestElf(unittest.TestCase): offset = elf.GetSymbolFileOffset(fname, ['embed_start', 'embed_end']) start = offset['embed_start'].offset end = offset['embed_end'].offset - data = tools.ReadFile(fname) + data = tools.read_file(fname) embed_data = data[start:end] expect = struct.pack('%s, size %s->%s' % - (ToHex(self.offset), ToHex(self.orig_offset), - ToHex(self.size), ToHex(self.orig_size))) + (to_hex(self.offset), to_hex(self.orig_offset), + to_hex(self.size), to_hex(self.orig_size))) self.pre_reset_size = self.size self.offset = self.orig_offset self.size = self.orig_size @@ -444,20 +444,20 @@ class Entry(object): New section offset pointer (after this entry) """ self.Detail('Packing: offset=%s, size=%s, content_size=%x' % - (ToHex(self.offset), ToHex(self.size), + (to_hex(self.offset), to_hex(self.size), self.contents_size)) if self.offset is None: if self.offset_unset: self.Raise('No offset set with offset-unset: should another ' 'entry provide this correct offset?') - self.offset = tools.Align(offset, self.align) + self.offset = tools.align(offset, self.align) needed = self.pad_before + self.contents_size + self.pad_after - needed = tools.Align(needed, self.align_size) + needed = tools.align(needed, self.align_size) size = self.size if not size: size = needed new_offset = self.offset + size - aligned_offset = tools.Align(new_offset, self.align_end) + aligned_offset = tools.align(new_offset, self.align_end) if aligned_offset != new_offset: size = aligned_offset - self.offset new_offset = aligned_offset @@ -471,10 +471,10 @@ class Entry(object): # Check that the alignment is correct. It could be wrong if the # and offset or size values were provided (i.e. not calculated), but # conflict with the provided alignment values - if self.size != tools.Align(self.size, self.align_size): + if self.size != tools.align(self.size, self.align_size): self.Raise("Size %#x (%d) does not match align-size %#x (%d)" % (self.size, self.size, self.align_size, self.align_size)) - if self.offset != tools.Align(self.offset, self.align): + if self.offset != tools.align(self.offset, self.align): self.Raise("Offset %#x (%d) does not match align %#x (%d)" % (self.offset, self.offset, self.align, self.align)) self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' % @@ -541,7 +541,7 @@ class Entry(object): bytes content of the entry, excluding any padding. If the entry is compressed, the compressed data is returned """ - self.Detail('GetData: size %s' % ToHexSize(self.data)) + self.Detail('GetData: size %s' % to_hex_size(self.data)) return self.data def GetPaddedData(self, data=None): @@ -991,7 +991,7 @@ features to produce new behaviours. fname (str): Filename of faked file """ if self.allow_fake and not pathlib.Path(fname).is_file(): - outfname = tools.GetOutputFilename(os.path.basename(fname)) + outfname = tools.get_output_filename(os.path.basename(fname)) with open(outfname, "wb") as out: out.truncate(1024) self.faked = True diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 1b59c9056e..7ed9b262bb 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -17,10 +17,10 @@ from patman import tools class TestEntry(unittest.TestCase): def setUp(self): - tools.PrepareOutputDir(None) + tools.prepare_output_dir(None) def tearDown(self): - tools.FinaliseOutputDir() + tools.finalise_output_dir() def GetNode(self): binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) diff --git a/tools/binman/etype/atf_fip.py b/tools/binman/etype/atf_fip.py index 07e6c645b0..6ecd95b71f 100644 --- a/tools/binman/etype/atf_fip.py +++ b/tools/binman/etype/atf_fip.py @@ -181,7 +181,7 @@ class Entry_atf_fip(Entry_section): self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0) self._fip_flags = fdt_util.GetInt64(self._node, 'fip-hdr-flags', 0) self._fip_align = fdt_util.GetInt(self._node, 'fip-align', 1) - if tools.NotPowerOfTwo(self._fip_align): + if tools.not_power_of_two(self._fip_align): raise ValueError("Node '%s': FIP alignment %s must be a power of two" % (self._node.path, self._fip_align)) self.ReadEntries() diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py index 59728f368e..25ec5d26c9 100644 --- a/tools/binman/etype/blob.py +++ b/tools/binman/etype/blob.py @@ -37,7 +37,7 @@ class Entry_blob(Entry): def ObtainContents(self): self._filename = self.GetDefaultFilename() - self._pathname = tools.GetInputFilename(self._filename, + self._pathname = tools.get_input_filename(self._filename, self.external and self.section.GetAllowMissing()) # Allow the file to be missing if not self._pathname: @@ -68,7 +68,7 @@ class Entry_blob(Entry): bytes: Data read """ state.TimingStart('read') - indata = tools.ReadFile(pathname) + indata = tools.read_file(pathname) state.TimingAccum('read') state.TimingStart('compress') data = self.CompressData(indata) diff --git a/tools/binman/etype/blob_ext_list.py b/tools/binman/etype/blob_ext_list.py index 29c9092dc3..76ad32a1ee 100644 --- a/tools/binman/etype/blob_ext_list.py +++ b/tools/binman/etype/blob_ext_list.py @@ -38,7 +38,7 @@ class Entry_blob_ext_list(Entry_blob): pathnames = [] for fname in self._filenames: fname = self.check_fake_fname(fname) - pathname = tools.GetInputFilename( + pathname = tools.get_input_filename( fname, self.external and self.section.GetAllowMissing()) # Allow the file to be missing if not pathname: diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index aaaf2de438..76e8dbe818 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -140,7 +140,7 @@ class Entry_fdtmap(Entry): fdt.pack() outfdt = Fdt.FromData(fdt.as_bytearray()) data = outfdt.GetContents() - data = FDTMAP_MAGIC + tools.GetBytes(0, 8) + data + data = FDTMAP_MAGIC + tools.get_bytes(0, 8) + data return data def ObtainContents(self): diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py index 927d0f071d..0650a69c55 100644 --- a/tools/binman/etype/files.py +++ b/tools/binman/etype/files.py @@ -47,7 +47,7 @@ class Entry_files(Entry_section): 'require-matches') def ExpandEntries(self): - files = tools.GetInputFilenameGlob(self._pattern) + files = tools.get_input_filename_glob(self._pattern) if self._require_matches and not files: self.Raise("Pattern '%s' matched no files" % self._pattern) for fname in files: diff --git a/tools/binman/etype/fill.py b/tools/binman/etype/fill.py index efb2d13e91..cd38279919 100644 --- a/tools/binman/etype/fill.py +++ b/tools/binman/etype/fill.py @@ -31,5 +31,5 @@ class Entry_fill(Entry): self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0) def ObtainContents(self): - self.SetContents(tools.GetBytes(self.fill_value, self.size)) + self.SetContents(tools.get_bytes(self.fill_value, self.size)) return True diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 6ad4a686df..954cbc3d85 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -200,19 +200,19 @@ class Entry_fit(Entry): for seq, fdt_fname in enumerate(self._fdts): node_name = subnode.name[1:].replace('SEQ', str(seq + 1)) - fname = tools.GetInputFilename(fdt_fname + '.dtb') + fname = tools.get_input_filename(fdt_fname + '.dtb') with fsw.add_node(node_name): for pname, prop in subnode.props.items(): val = prop.bytes.replace( - b'NAME', tools.ToBytes(fdt_fname)) + b'NAME', tools.to_bytes(fdt_fname)) val = val.replace( - b'SEQ', tools.ToBytes(str(seq + 1))) + b'SEQ', tools.to_bytes(str(seq + 1))) fsw.property(pname, val) # Add data for 'fdt' nodes (but not 'config') if depth == 1 and in_images: fsw.property('data', - tools.ReadFile(fname)) + tools.read_file(fname)) else: if self._fdts is None: if self._fit_list_prop: @@ -246,10 +246,10 @@ class Entry_fit(Entry): # self._BuildInput() either returns bytes or raises an exception. data = self._BuildInput(self._fdt) uniq = self.GetUniqueName() - input_fname = tools.GetOutputFilename('%s.itb' % uniq) - output_fname = tools.GetOutputFilename('%s.fit' % uniq) - tools.WriteFile(input_fname, data) - tools.WriteFile(output_fname, data) + input_fname = tools.get_output_filename('%s.itb' % uniq) + output_fname = tools.get_output_filename('%s.fit' % uniq) + tools.write_file(input_fname, data) + tools.write_file(output_fname, data) args = {} ext_offset = self._fit_props.get('fit,external-offset') @@ -260,11 +260,11 @@ class Entry_fit(Entry): } if self.mkimage.run(reset_timestamp=True, output_fname=output_fname, **args) is not None: - self.SetContents(tools.ReadFile(output_fname)) + self.SetContents(tools.read_file(output_fname)) else: # Bintool is missing; just use empty data as the output self.record_missing_bintool(self.mkimage) - self.SetContents(tools.GetBytes(0, 1024)) + self.SetContents(tools.get_bytes(0, 1024)) return True diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py index cac99b60eb..72b44a7869 100644 --- a/tools/binman/etype/fmap.py +++ b/tools/binman/etype/fmap.py @@ -8,7 +8,7 @@ from binman.entry import Entry from binman import fmap_util from patman import tools -from patman.tools import ToHexSize +from patman.tools import to_hex_size from patman import tout @@ -47,7 +47,7 @@ class Entry_fmap(Entry): def _AddEntries(areas, entry): entries = entry.GetEntries() tout.Debug("fmap: Add entry '%s' type '%s' (%s subentries)" % - (entry.GetPath(), entry.etype, ToHexSize(entries))) + (entry.GetPath(), entry.etype, to_hex_size(entries))) if entries and entry.etype != 'cbfs': # Create an area for the section, which encompasses all entries # within it diff --git a/tools/binman/etype/gbb.py b/tools/binman/etype/gbb.py index ca8af1be42..e32fae27ce 100644 --- a/tools/binman/etype/gbb.py +++ b/tools/binman/etype/gbb.py @@ -70,14 +70,14 @@ class Entry_gbb(Entry): def ObtainContents(self): gbb = 'gbb.bin' - fname = tools.GetOutputFilename(gbb) + fname = tools.get_output_filename(gbb) if not self.size: self.Raise('GBB must have a fixed size') gbb_size = self.size bmpfv_size = gbb_size - 0x2180 if bmpfv_size < 0: self.Raise('GBB is too small (minimum 0x2180 bytes)') - keydir = tools.GetInputFilename(self.keydir) + keydir = tools.get_input_filename(self.keydir) stdout = self.futility.gbb_create( fname, [0x100, 0x1000, bmpfv_size, 0x1000]) @@ -88,14 +88,14 @@ class Entry_gbb(Entry): rootkey='%s/root_key.vbpubk' % keydir, recoverykey='%s/recovery_key.vbpubk' % keydir, flags=self.gbb_flags, - bmpfv=tools.GetInputFilename(self.bmpblk)) + bmpfv=tools.get_input_filename(self.bmpblk)) if stdout is not None: - self.SetContents(tools.ReadFile(fname)) + self.SetContents(tools.read_file(fname)) else: # Bintool is missing; just use the required amount of zero data self.record_missing_bintool(self.futility) - self.SetContents(tools.GetBytes(0, gbb_size)) + self.SetContents(tools.get_bytes(0, gbb_size)) return True diff --git a/tools/binman/etype/intel_ifwi.py b/tools/binman/etype/intel_ifwi.py index ed14046ba6..46bdf116e6 100644 --- a/tools/binman/etype/intel_ifwi.py +++ b/tools/binman/etype/intel_ifwi.py @@ -58,11 +58,11 @@ class Entry_intel_ifwi(Entry_blob_ext): # Create the IFWI file if needed if self._convert_fit: inname = self._pathname - outname = tools.GetOutputFilename('ifwi.bin') + outname = tools.get_output_filename('ifwi.bin') if self.ifwitool.create_ifwi(inname, outname) is None: # Bintool is missing; just create a zeroed ifwi.bin self.record_missing_bintool(self.ifwitool) - self.SetContents(tools.GetBytes(0, 1024)) + self.SetContents(tools.get_bytes(0, 1024)) self._filename = 'ifwi.bin' self._pathname = outname @@ -74,15 +74,15 @@ class Entry_intel_ifwi(Entry_blob_ext): if self.ifwitool.delete_subpart(outname, 'OBBP') is None: # Bintool is missing; just use zero data self.record_missing_bintool(self.ifwitool) - self.SetContents(tools.GetBytes(0, 1024)) + self.SetContents(tools.get_bytes(0, 1024)) return True for entry in self._ifwi_entries.values(): # First get the input data and put it in a file data = entry.GetPaddedData() uniq = self.GetUniqueName() - input_fname = tools.GetOutputFilename('input.%s' % uniq) - tools.WriteFile(input_fname, data) + input_fname = tools.get_output_filename('input.%s' % uniq) + tools.write_file(input_fname, data) # At this point we know that ifwitool is present, so we don't need # to check for None here @@ -107,7 +107,7 @@ class Entry_intel_ifwi(Entry_blob_ext): After that we delete the OBBP sub-partition and add each of the files that we want in the IFWI file, one for each sub-entry of the IWFI node. """ - self._pathname = tools.GetInputFilename(self._filename, + self._pathname = tools.get_input_filename(self._filename, self.section.GetAllowMissing()) # Allow the file to be missing if not self._pathname: diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py index 201ee4b569..baa16f36f3 100644 --- a/tools/binman/etype/mkimage.py +++ b/tools/binman/etype/mkimage.py @@ -48,12 +48,12 @@ class Entry_mkimage(Entry): return False data += entry.GetData() uniq = self.GetUniqueName() - input_fname = tools.GetOutputFilename('mkimage.%s' % uniq) - tools.WriteFile(input_fname, data) - output_fname = tools.GetOutputFilename('mkimage-out.%s' % uniq) + input_fname = tools.get_output_filename('mkimage.%s' % uniq) + tools.write_file(input_fname, data) + output_fname = tools.get_output_filename('mkimage-out.%s' % uniq) if self.mkimage.run_cmd('-d', input_fname, *self._args, output_fname) is not None: - self.SetContents(tools.ReadFile(output_fname)) + self.SetContents(tools.read_file(output_fname)) else: # Bintool is missing; just use the input data as the output self.record_missing_bintool(self.mkimage) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index bb375e9063..b3d7302394 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -19,7 +19,7 @@ from binman import state from dtoc import fdt_util from patman import tools from patman import tout -from patman.tools import ToHexSize +from patman.tools import to_hex_size class Entry_section(Entry): @@ -269,19 +269,19 @@ class Entry_section(Entry): data = bytearray() # Handle padding before the entry if entry.pad_before: - data += tools.GetBytes(self._pad_byte, entry.pad_before) + data += tools.get_bytes(self._pad_byte, entry.pad_before) # Add in the actual entry data data += entry_data # Handle padding after the entry if entry.pad_after: - data += tools.GetBytes(self._pad_byte, entry.pad_after) + data += tools.get_bytes(self._pad_byte, entry.pad_after) if entry.size: - data += tools.GetBytes(pad_byte, entry.size - len(data)) + data += tools.get_bytes(pad_byte, entry.size - len(data)) - self.Detail('GetPaddedDataForEntry: size %s' % ToHexSize(self.data)) + self.Detail('GetPaddedDataForEntry: size %s' % to_hex_size(self.data)) return data @@ -316,7 +316,7 @@ class Entry_section(Entry): # Handle empty space before the entry pad = (entry.offset or 0) - self._skip_at_start - len(section_data) if pad > 0: - section_data += tools.GetBytes(self._pad_byte, pad) + section_data += tools.get_bytes(self._pad_byte, pad) # Add in the actual entry data section_data += data @@ -709,14 +709,14 @@ class Entry_section(Entry): if not size: data = self.GetPaddedData(self.data) size = len(data) - size = tools.Align(size, self.align_size) + size = tools.align(size, self.align_size) if self.size and contents_size > self.size: self._Raise("contents size %#x (%d) exceeds section size %#x (%d)" % (contents_size, contents_size, self.size, self.size)) if not self.size: self.size = size - if self.size != tools.Align(self.size, self.align_size): + if self.size != tools.align(self.size, self.align_size): self._Raise("Size %#x (%d) does not match align-size %#x (%d)" % (self.size, self.size, self.align_size, self.align_size)) diff --git a/tools/binman/etype/text.py b/tools/binman/etype/text.py index 45dfcc401e..c55e0233b1 100644 --- a/tools/binman/etype/text.py +++ b/tools/binman/etype/text.py @@ -60,14 +60,14 @@ class Entry_text(Entry): super().__init__(section, etype, node) value = fdt_util.GetString(self._node, 'text') if value: - value = tools.ToBytes(value) + value = tools.to_bytes(value) else: label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)]) self.text_label = label if self.text_label: value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)]) - value = tools.ToBytes(value) if value is not None else value + value = tools.to_bytes(value) if value is not None else value self.value = value def ObtainContents(self): diff --git a/tools/binman/etype/u_boot_elf.py b/tools/binman/etype/u_boot_elf.py index 6614a75faf..3ec774f38a 100644 --- a/tools/binman/etype/u_boot_elf.py +++ b/tools/binman/etype/u_boot_elf.py @@ -27,9 +27,9 @@ class Entry_u_boot_elf(Entry_blob): def ReadBlobContents(self): if self._strip: uniq = self.GetUniqueName() - out_fname = tools.GetOutputFilename('%s.stripped' % uniq) - tools.WriteFile(out_fname, tools.ReadFile(self._pathname)) - tools.Run('strip', out_fname) + out_fname = tools.get_output_filename('%s.stripped' % uniq) + tools.write_file(out_fname, tools.read_file(self._pathname)) + tools.run('strip', out_fname) self._pathname = out_fname super().ReadBlobContents() return True diff --git a/tools/binman/etype/u_boot_env.py b/tools/binman/etype/u_boot_env.py index 1694c2a6ee..c38340b256 100644 --- a/tools/binman/etype/u_boot_env.py +++ b/tools/binman/etype/u_boot_env.py @@ -27,7 +27,7 @@ class Entry_u_boot_env(Entry_blob): self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0) def ReadBlobContents(self): - indata = tools.ReadFile(self._pathname) + indata = tools.read_file(self._pathname) data = b'' for line in indata.splitlines(): data += line + b'\0' @@ -35,7 +35,7 @@ class Entry_u_boot_env(Entry_blob): pad = self.size - len(data) - 5 if pad < 0: self.Raise("'u-boot-env' entry too small to hold data (need %#x more bytes)" % -pad) - data += tools.GetBytes(self.fill_value, pad) + data += tools.get_bytes(self.fill_value, pad) crc = zlib.crc32(data) buf = struct.pack(' 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('