Commit 1cfdfc064a190529c988065e867a6569cdc3c168
1 parent
8acce60b10
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
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>
Showing 1 changed file with 33 additions and 0 deletions Side-by-side Diff
tools/patman/tools.py
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | # Copyright (c) 2016 Google, Inc |
4 | 4 | # |
5 | 5 | |
6 | +from __future__ import print_function | |
7 | + | |
6 | 8 | import command |
7 | 9 | import glob |
8 | 10 | import os |
... | ... | @@ -440,4 +442,35 @@ |
440 | 442 | else: |
441 | 443 | raise ValueError("Unknown algorithm '%s'" % algo) |
442 | 444 | return data |
445 | + | |
446 | +CMD_CREATE, CMD_DELETE, CMD_ADD, CMD_REPLACE, CMD_EXTRACT = range(5) | |
447 | + | |
448 | +IFWITOOL_CMDS = { | |
449 | + CMD_CREATE: 'create', | |
450 | + CMD_DELETE: 'delete', | |
451 | + CMD_ADD: 'add', | |
452 | + CMD_REPLACE: 'replace', | |
453 | + CMD_EXTRACT: 'extract', | |
454 | + } | |
455 | + | |
456 | +def RunIfwiTool(ifwi_file, cmd, fname=None, subpart=None, entry_name=None): | |
457 | + """Run ifwitool with the given arguments: | |
458 | + | |
459 | + Args: | |
460 | + ifwi_file: IFWI file to operation on | |
461 | + cmd: Command to execute (CMD_...) | |
462 | + fname: Filename of file to add/replace/extract/create (None for | |
463 | + CMD_DELETE) | |
464 | + subpart: Name of sub-partition to operation on (None for CMD_CREATE) | |
465 | + entry_name: Name of directory entry to operate on, or None if none | |
466 | + """ | |
467 | + args = ['ifwitool', ifwi_file] | |
468 | + args.append(IFWITOOL_CMDS[cmd]) | |
469 | + if fname: | |
470 | + args += ['-f', fname] | |
471 | + if subpart: | |
472 | + args += ['-n', subpart] | |
473 | + if entry_name: | |
474 | + args += ['-d', '-e', entry_name] | |
475 | + Run(*args) |