diff options
author | Simon Glass <sjg@chromium.org> | 2019-07-08 13:18:51 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2019-07-24 12:53:46 -0700 |
commit | 1cfdfc064a190529c988065e867a6569cdc3c168 (patch) | |
tree | dbc0ac02f288b258e065ac094adfe26d96ad4f88 /tools/patman/tools.py | |
parent | 8acce60b10f2d60945b71f527fd29ee62242b175 (diff) |
patman: Add a function to write ifwitool
This tool has quite a few arguments and options, so put the functionality
in a function so that we call it from one place and hopefully get it
right.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/tools.py')
-rw-r--r-- | tools/patman/tools.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 69d03d3860..e945b54fa2 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -3,6 +3,8 @@ # Copyright (c) 2016 Google, Inc # +from __future__ import print_function + import command import glob import os @@ -440,3 +442,34 @@ def Decompress(indata, algo): else: raise ValueError("Unknown algorithm '%s'" % algo) return data + +CMD_CREATE, CMD_DELETE, CMD_ADD, CMD_REPLACE, CMD_EXTRACT = range(5) + +IFWITOOL_CMDS = { + CMD_CREATE: 'create', + CMD_DELETE: 'delete', + CMD_ADD: 'add', + CMD_REPLACE: 'replace', + CMD_EXTRACT: 'extract', + } + +def RunIfwiTool(ifwi_file, cmd, fname=None, subpart=None, entry_name=None): + """Run ifwitool with the given arguments: + + Args: + ifwi_file: IFWI file to operation on + cmd: Command to execute (CMD_...) + fname: Filename of file to add/replace/extract/create (None for + CMD_DELETE) + subpart: Name of sub-partition to operation on (None for CMD_CREATE) + entry_name: Name of directory entry to operate on, or None if none + """ + args = ['ifwitool', ifwi_file] + args.append(IFWITOOL_CMDS[cmd]) + if fname: + args += ['-f', fname] + if subpart: + args += ['-n', subpart] + if entry_name: + args += ['-d', '-e', entry_name] + Run(*args) |