Convert this file to snake case and update all files which use it.
Signed-off-by: Simon Glass <sjg@chromium.org>
name = os.path.expanduser(self.name) # Expand paths containing ~
all_args = (name,) + args
env = tools.get_env_with_path()
- tout.Detail(f"bintool: {' '.join(all_args)}")
+ tout.detail(f"bintool: {' '.join(all_args)}")
result = command.run_pipe(
[all_args], capture=True, capture_stderr=True, env=env,
raise_on_error=False, binary=binary)
# try to run it (as above) since RunPipe() allows faking the tool's
# output
if not any([result.stdout, result.stderr, tools.tool_find(name)]):
- tout.Info(f"bintool '{name}' not found")
+ tout.info(f"bintool '{name}' not found")
return None
if raise_on_error:
- tout.Info(f"bintool '{name}' failed")
+ tout.info(f"bintool '{name}' failed")
raise ValueError("Error %d running '%s': %s" %
(result.return_code, ' '.join(all_args),
result.stderr or result.stdout))
if result.stdout:
- tout.Debug(result.stdout)
+ tout.debug(result.stdout)
if result.stderr:
- tout.Debug(result.stderr)
+ tout.debug(result.stderr)
return result
def run_cmd(self, *args, binary=False):
return result
def _ShowBlobHelp(path, text):
- tout.Warning('\n%s:' % path)
+ tout.warning('\n%s:' % path)
for line in text.splitlines():
- tout.Warning(' %s' % line)
+ tout.warning(' %s' % line)
def _ShowHelpForMissingBlobs(missing_list):
"""Show help for each missing blob to help the user take action
entry = image.FindEntryPath(entry_paths[0])
data = entry.ReadData(decomp, alt_format)
tools.write_file(output_fname, data)
- tout.Notice("Wrote %#x bytes to file '%s'" % (len(data), output_fname))
+ tout.notice("Wrote %#x bytes to file '%s'" % (len(data), output_fname))
return
# Otherwise we will output to a path given by the entry path of each entry.
# This means that entries will appear in subdirectories if they are part of
# a sub-section.
einfos = image.GetListEntries(entry_paths)[0]
- tout.Notice('%d entries match and will be written' % len(einfos))
+ tout.notice('%d entries match and will be written' % len(einfos))
for einfo in einfos:
entry = einfo.entry
data = entry.ReadData(decomp, alt_format)
if fname and not os.path.exists(fname):
os.makedirs(fname)
fname = os.path.join(fname, 'root')
- tout.Notice("Write entry '%s' size %x to '%s'" %
+ tout.notice("Write entry '%s' size %x to '%s'" %
(entry.GetPath(), len(data), fname))
tools.write_file(fname, data)
return einfos
of the entries), False to raise an exception
write_map: True to write a map file
"""
- tout.Info('Processing image')
+ tout.info('Processing image')
ProcessImage(image, update_fdt=True, write_map=write_map,
get_contents=False, allow_resize=allow_resize)
def WriteEntryToImage(image, entry, data, do_compress=True, allow_resize=True,
write_map=False):
BeforeReplace(image, allow_resize)
- tout.Info('Writing data to %s' % entry.GetPath())
+ tout.info('Writing data to %s' % entry.GetPath())
ReplaceOneEntry(image, entry, data, do_compress, allow_resize)
AfterReplace(image, allow_resize=allow_resize, write_map=write_map)
Returns:
Image object that was updated
"""
- tout.Info("Write entry '%s', file '%s'" % (entry_path, image_fname))
+ tout.info("Write entry '%s', file '%s'" % (entry_path, image_fname))
image = Image.FromFile(image_fname)
entry = image.FindEntryPath(entry_path)
WriteEntryToImage(image, entry, data, do_compress=do_compress,
raise ValueError('Must specify exactly one entry path to write with -f')
entry = image.FindEntryPath(entry_paths[0])
data = tools.read_file(input_fname)
- tout.Notice("Read %#x bytes from file '%s'" % (len(data), 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)
return
# This means that files must appear in subdirectories if they are part of
# a sub-section.
einfos = image.GetListEntries(entry_paths)[0]
- tout.Notice("Replacing %d matching entries in image '%s'" %
+ tout.notice("Replacing %d matching entries in image '%s'" %
(len(einfos), image_fname))
BeforeReplace(image, allow_resize)
for einfo in einfos:
entry = einfo.entry
if entry.GetEntries():
- tout.Info("Skipping section entry '%s'" % entry.GetPath())
+ tout.info("Skipping section entry '%s'" % entry.GetPath())
continue
path = entry.GetPath()[1:]
fname = os.path.join(indir, path)
if os.path.exists(fname):
- tout.Notice("Write entry '%s' from file '%s'" %
+ tout.notice("Write entry '%s' from file '%s'" %
(entry.GetPath(), fname))
data = tools.read_file(fname)
ReplaceOneEntry(image, entry, data, do_compress, allow_resize)
else:
- tout.Warning("Skipping entry '%s' from missing file '%s'" %
+ tout.warning("Skipping entry '%s' from missing file '%s'" %
(entry.GetPath(), fname))
AfterReplace(image, allow_resize=allow_resize, write_map=write_map)
else:
skip.append(name)
images = new_images
- tout.Notice('Skipping images: %s' % ', '.join(skip))
+ tout.notice('Skipping images: %s' % ', '.join(skip))
state.Prepare(images, dtb)
if sizes_ok:
break
image.ResetForPack()
- tout.Info('Pack completed after %d pass(es)' % (pack_pass + 1))
+ tout.info('Pack completed after %d pass(es)' % (pack_pass + 1))
if not sizes_ok:
image.Raise('Entries changed size after packing (tried %s passes)' %
passes)
missing_list = []
image.CheckMissing(missing_list)
if missing_list:
- tout.Warning("Image '%s' is missing external blobs and is non-functional: %s" %
+ tout.warning("Image '%s' is missing external blobs and is non-functional: %s" %
(image.name, ' '.join([e.name for e in missing_list])))
_ShowHelpForMissingBlobs(missing_list)
faked_list = []
image.CheckFakedBlobs(faked_list)
if faked_list:
- tout.Warning(
+ tout.warning(
"Image '%s' has faked external blobs and is non-functional: %s" %
(image.name, ' '.join([os.path.basename(e.GetDefaultFilename())
for e in faked_list])))
missing_bintool_list = []
image.check_missing_bintools(missing_bintool_list)
if missing_bintool_list:
- tout.Warning(
+ tout.warning(
"Image '%s' has missing bintools and is non-functional: %s" %
(image.name, ' '.join([os.path.basename(bintool.name)
for bintool in missing_bintool_list])))
if args.cmd in ['ls', 'extract', 'replace', 'tool']:
try:
- tout.Init(args.verbosity)
+ tout.init(args.verbosity)
tools.prepare_output_dir(None)
if args.cmd == 'ls':
ListEntries(args.image, args.paths)
args.indir.append(board_pathname)
try:
- tout.Init(args.verbosity)
+ tout.init(args.verbosity)
elf.debug = args.debug
cbfs_util.VERBOSE = args.verbosity > 2
state.use_fake_dtb = args.fake_dtb
elf.UpdateFile(*elf_params, data)
if invalid:
- tout.Warning("\nSome images are invalid")
+ tout.warning("\nSome images are invalid")
# Use this to debug the time take to pack the image
#state.TimingShow()
finally:
tools.finalise_output_dir()
finally:
- tout.Uninit()
+ tout.uninit()
return 0
value = -1
pack_string = pack_string.lower()
value_bytes = struct.pack(pack_string, value)
- tout.Debug('%s:\n insert %s, offset %x, value %x, length %d' %
+ tout.debug('%s:\n insert %s, offset %x, value %x, length %d' %
(msg, name, offset, value, len(value_bytes)))
entry.data = (entry.data[:offset] + value_bytes +
entry.data[offset + sym.size:])
mem_end - data_start)
def UpdateFile(infile, outfile, start_sym, end_sym, insert):
- tout.Notice("Creating file '%s' with data length %#x (%d) between symbols '%s' and '%s'" %
+ tout.notice("Creating file '%s' with data length %#x (%d) between symbols '%s' and '%s'" %
(outfile, len(insert), len(insert), start_sym, end_sym))
syms = GetSymbolFileOffset(infile, [start_sym, end_sym])
if len(syms) != 2:
newdata += insert + tools.get_bytes(0, size - len(insert))
newdata += data[syms[end_sym].offset:]
tools.write_file(outfile, newdata)
- tout.Info('Written to offset %#x' % syms[start_sym].offset)
+ tout.info('Written to offset %#x' % syms[start_sym].offset)
def testDebug(self):
"""Check that enabling debug in the elf module produced debug output"""
try:
- tout.Init(tout.DEBUG)
+ tout.init(tout.DEBUG)
entry = FakeEntry(20)
section = FakeSection()
elf_fname = self.ElfTestFile('u_boot_binman_syms')
syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
self.assertTrue(len(stdout.getvalue()) > 0)
finally:
- tout.Init(tout.WARNING)
+ tout.init(tout.WARNING)
def testMakeElf(self):
"""Test for the MakeElf function"""
data += tools.get_bytes(0, self.contents_size - new_size)
if not size_ok:
- tout.Debug("Entry '%s' size change from %s to %s" % (
+ tout.debug("Entry '%s' size change from %s to %s" % (
self._node.path, to_hex(self.contents_size),
to_hex(new_size)))
self.SetContents(data)
def Info(self, msg):
"""Convenience function to log info referencing a node"""
tag = "Info '%s'" % self._node.path
- tout.Detail('%30s: %s' % (tag, msg))
+ tout.detail('%30s: %s' % (tag, msg))
def Detail(self, msg):
"""Convenience function to log detail referencing a node"""
tag = "Node '%s'" % self._node.path
- tout.Detail('%30s: %s' % (tag, msg))
+ tout.detail('%30s: %s' % (tag, msg))
def GetEntryArgsOrProps(self, props, required=False):
"""Return the values of a set of properties
"""
# Use True here so that we get an uncompressed section to work from,
# although compressed sections are currently not supported
- tout.Debug("ReadChildData section '%s', entry '%s'" %
+ tout.debug("ReadChildData section '%s', entry '%s'" %
(self.section.GetPath(), self.GetPath()))
data = self.section.ReadChildData(self, decomp, alt_format)
return data
Returns:
True to use this entry type, False to use the original one
"""
- tout.Info("Node '%s': etype '%s': %s selected" %
+ tout.info("Node '%s': etype '%s': %s selected" %
(node.path, etype, new_etype))
return True
"""
def _AddEntries(areas, entry):
entries = entry.GetEntries()
- tout.Debug("fmap: Add entry '%s' type '%s' (%s subentries)" %
+ tout.debug("fmap: Add entry '%s' type '%s' (%s subentries)" %
(entry.GetPath(), entry.etype, to_hex_size(entries)))
if entries and entry.etype != 'cbfs':
# Create an area for the section, which encompasses all entries
return self._sort
def ReadData(self, decomp=True, alt_format=None):
- tout.Info("ReadData path='%s'" % self.GetPath())
+ tout.info("ReadData path='%s'" % self.GetPath())
parent_data = self.section.ReadData(True, alt_format)
offset = self.offset - self.section._skip_at_start
data = parent_data[offset:offset + self.size]
- tout.Info(
+ tout.info(
'%s: Reading data from offset %#x-%#x (real %#x), size %#x, got %#x' %
(self.GetPath(), self.offset, self.offset + self.size, offset,
self.size, len(data)))
return data
def ReadChildData(self, child, decomp=True, alt_format=None):
- tout.Debug(f"ReadChildData for child '{child.GetPath()}'")
+ tout.debug(f"ReadChildData for child '{child.GetPath()}'")
parent_data = self.ReadData(True, alt_format)
offset = child.offset - self._skip_at_start
- tout.Debug("Extract for child '%s': offset %#x, skip_at_start %#x, result %#x" %
+ tout.debug("Extract for child '%s': offset %#x, skip_at_start %#x, result %#x" %
(child.GetPath(), child.offset, self._skip_at_start, offset))
data = parent_data[offset:offset + child.size]
if decomp:
indata = data
data = comp_util.decompress(indata, child.compress)
if child.uncomp_size:
- tout.Info("%s: Decompressing data size %#x with algo '%s' to data size %#x" %
+ tout.info("%s: Decompressing data size %#x with algo '%s' to data size %#x" %
(child.GetPath(), len(indata), child.compress,
len(data)))
if alt_format:
@classmethod
def UseExpanded(cls, node, etype, new_etype):
val = state.GetEntryArgBool('spl-dtb')
- tout.DoOutput(tout.INFO if val else tout.DETAIL,
+ tout.do_output(tout.INFO if val else tout.DETAIL,
"Node '%s': etype '%s': %s %sselected" %
(node.path, etype, new_etype, '' if val else 'not '))
return val
@classmethod
def UseExpanded(cls, node, etype, new_etype):
val = state.GetEntryArgBool('tpl-dtb')
- tout.DoOutput(tout.INFO if val else tout.DETAIL,
+ tout.do_output(tout.INFO if val else tout.DETAIL,
"Node '%s': etype '%s': %s %sselected" %
(node.path, etype, new_etype, '' if val else 'not '))
return val
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):
def BuildImage(self):
"""Write the image to a file"""
fname = tools.get_output_filename(self._filename)
- tout.Info("Writing image to '%s'" % fname)
+ tout.info("Writing image to '%s'" % fname)
with open(fname, 'wb') as fd:
data = self.GetPaddedData()
fd.write(data)
- tout.Info("Wrote %#x bytes" % len(data))
+ tout.info("Wrote %#x bytes" % len(data))
def WriteMap(self):
"""Write a map of the image to a .map file
return entry
def ReadData(self, decomp=True, alt_format=None):
- tout.Debug("Image '%s' ReadData(), size=%#x" %
+ tout.debug("Image '%s' ReadData(), size=%#x" %
(self.GetPath(), len(self._data)))
return self._data
global entry_args
entry_args = {}
- tout.Debug('Processing entry args:')
+ tout.debug('Processing entry args:')
if args:
for arg in args:
m = re.match('([^=]*)=(.*)', arg)
if not m:
raise ValueError("Invalid entry arguemnt '%s'" % arg)
name, value = m.groups()
- tout.Debug(' %20s = %s' % (name, value))
+ tout.debug(' %20s = %s' % (name, value))
entry_args[name] = value
- tout.Debug('Processing entry args done')
+ tout.debug('Processing entry args done')
def GetEntryArg(name):
"""Get the value of an entry argument
"""
global output_fdt_info, main_dtb, fdt_path_prefix
- tout.Info('Preparing device trees')
+ tout.info('Preparing device trees')
output_fdt_info.clear()
fdt_path_prefix = ''
output_fdt_info['fdtmap'] = [image.fdtmap_dtb, 'u-boot.dtb']
main_dtb = None
- tout.Info(" Found device tree type 'fdtmap' '%s'" % image.fdtmap_dtb.name)
+ tout.info(" Found device tree type 'fdtmap' '%s'" % image.fdtmap_dtb.name)
for etype, value in image.GetFdts().items():
entry, fname = value
out_fname = tools.get_output_filename('%s.dtb' % entry.etype)
- tout.Info(" Found device tree type '%s' at '%s' path '%s'" %
+ tout.info(" Found device tree type '%s' at '%s' path '%s'" %
(etype, out_fname, entry.GetPath()))
entry._filename = entry.GetDefaultFilename()
data = entry.ReadData()
image_node = dtb.GetNode('/binman/%s' % image.image_node)
fdt_path_prefix = image_node.path
output_fdt_info[etype] = [dtb, None]
- tout.Info(" FDT path prefix '%s'" % fdt_path_prefix)
+ tout.info(" FDT path prefix '%s'" % fdt_path_prefix)
def GetAllFdts():
for_repack: True is this property is only needed for repacking
"""
for n in GetUpdateNodes(node, for_repack):
- tout.Detail("File %s: Update node '%s' prop '%s' to %#x" %
+ tout.detail("File %s: Update node '%s' prop '%s' to %#x" %
(n.GetFdt().name, n.path, prop, value))
n.SetInt(prop, value)
count = len(patch_dict)
num_commits = len(series.commits)
if count != num_commits:
- tout.Warning('Warning: Patchwork reports %d patches, series has %d' %
+ tout.warning('Warning: Patchwork reports %d patches, series has %d' %
(count, num_commits))
patches = []
patch.parse_subject(pw_patch['name'])
patches.append(patch)
if warn_count > 1:
- tout.Warning(' (total of %d warnings)' % warn_count)
+ tout.warning(' (total of %d warnings)' % warn_count)
# Sort patches by patch number
patches = sorted(patches, key=lambda x: x.seq)
patch_for_commit, _, warnings = compare_with_series(series, patches)
for warn in warnings:
- tout.Warning(warn)
+ tout.warning(warn)
patch_list = [patch_for_commit.get(c) for c in range(len(series.commits))]
except OSError as err:
raise CmdError("Cannot make output directory '%s': '%s'" %
(outdir, err.strerror))
- tout.Debug("Using output directory '%s'" % outdir)
+ tout.debug("Using output directory '%s'" % outdir)
else:
outdir = tempfile.mkdtemp(prefix='binman.')
- tout.Debug("Using temporary directory '%s'" % outdir)
+ tout.debug("Using temporary directory '%s'" % outdir)
def _remove_output_dir():
global outdir
shutil.rmtree(outdir)
- tout.Debug("Deleted temporary directory '%s'" % outdir)
+ tout.debug("Deleted temporary directory '%s'" % outdir)
outdir = None
def finalise_output_dir():
global indir
indir = dirname
- tout.Debug("Using input directories %s" % indir)
+ tout.debug("Using input directories %s" % indir)
def get_input_filename(fname, allow_missing=False):
"""Return a filename for use as input.
def __exit__(unused1, unused2, unused3):
"""Clean up and remove any progress message."""
- ClearProgress()
+ clear_progress()
return False
-def UserIsPresent():
+def user_is_present():
"""This returns True if it is likely that a user is present.
Sometimes we want to prompt the user, but if no one is there then this
"""
return stdout_is_tty and verbose > 0
-def ClearProgress():
+def clear_progress():
"""Clear any active progress message on the terminal."""
global in_progress
if verbose > 0 and stdout_is_tty and in_progress:
_stdout.flush()
in_progress = False
-def Progress(msg, warning=False, trailer='...'):
+def progress(msg, warning=False, trailer='...'):
"""Display progress information.
Args:
msg: Message to display.
warning: True if this is a warning."""
global in_progress
- ClearProgress()
+ clear_progress()
if verbose > 0:
_progress = msg + trailer
if stdout_is_tty:
else:
_stdout.write(_progress + '\n')
-def _Output(level, msg, color=None):
+def _output(level, msg, color=None):
"""Output a message to the terminal.
Args:
error: True if this is an error message, else False.
"""
if verbose >= level:
- ClearProgress()
+ clear_progress()
if color:
msg = _color.Color(color, msg)
if level < NOTICE:
else:
print(msg)
-def DoOutput(level, msg):
+def do_output(level, msg):
"""Output a message to the terminal.
Args:
this as high as the currently selected level.
msg; Message to display.
"""
- _Output(level, msg)
+ _output(level, msg)
-def Error(msg):
+def error(msg):
"""Display an error message
Args:
msg; Message to display.
"""
- _Output(ERROR, msg, _color.RED)
+ _output(ERROR, msg, _color.RED)
-def Warning(msg):
+def warning(msg):
"""Display a warning message
Args:
msg; Message to display.
"""
- _Output(WARNING, msg, _color.YELLOW)
+ _output(WARNING, msg, _color.YELLOW)
-def Notice(msg):
+def notice(msg):
"""Display an important infomation message
Args:
msg; Message to display.
"""
- _Output(NOTICE, msg)
+ _output(NOTICE, msg)
-def Info(msg):
+def info(msg):
"""Display an infomation message
Args:
msg; Message to display.
"""
- _Output(INFO, msg)
+ _output(INFO, msg)
-def Detail(msg):
+def detail(msg):
"""Display a detailed message
Args:
msg; Message to display.
"""
- _Output(DETAIL, msg)
+ _output(DETAIL, msg)
-def Debug(msg):
+def debug(msg):
"""Display a debug message
Args:
msg; Message to display.
"""
- _Output(DEBUG, msg)
+ _output(DEBUG, msg)
-def UserOutput(msg):
+def user_output(msg):
"""Display a message regardless of the current output level.
This is used when the output was specifically requested by the user.
Args:
msg; Message to display.
"""
- _Output(0, msg)
+ _output(0, msg)
-def Init(_verbose=WARNING, stdout=sys.stdout):
+def init(_verbose=WARNING, stdout=sys.stdout):
"""Initialize a new output object.
Args:
stdout_is_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
stderr_is_tty = hasattr(sys.stderr, 'isatty') and sys.stderr.isatty()
-def Uninit():
- ClearProgress()
+def uninit():
+ clear_progress()
-Init()
+init()