diff options
author | Craig Hesling <hesling@chromium.org> | 2021-07-29 14:02:00 -0400 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-30 05:30:06 +0000 |
commit | 77d3756d27758276c084cf20693202cfa645df3e (patch) | |
tree | 74fa071176c6b01aa7f55346bbb85d86e85a39e2 /util | |
parent | 05e69748e694ffe803ebc1422c25dda6dfc87d53 (diff) | |
download | chrome-ec-77d3756d27758276c084cf20693202cfa645df3e.tar.gz |
biod: Add fptool.py that will replace flash_fp_mcu
This is similar to gsctool, but this tool would only be in the
test image.
This comes from the effort to move away from shell script.
See http://go/deshell.
The idea is that you start with a simple wrapper for the given shell
script. Over time, features are transplanted or added-new to the python
wrapper, until the shell script is no longer needed.
BRANCH=none
BUG=b:172020576
TEST=./util/fptool.py
./util/fptool.py --help
./util/fptool.py flash --help
./util/fptool.py flash
# Error about flash_fp_mcu not existing
TEST=scp util/fptool.py $DUT:/usr/local/bin
ssh $DUT fptool.py flash /root/doesnotexist
ssh $DUT fptool.py flash
ssh $DUT fptool.py flash /opt/google/biod/fw/$(cros_config /fingerprint board)*.bin
Change-Id: I8774bda4a057ee09f70bf474ce3ba2fa0bbcf92d
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3060744
Reviewed-by: Josie Nordrum <josienordrum@google.com>
Diffstat (limited to 'util')
-rwxr-xr-x | util/fptool.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/util/fptool.py b/util/fptool.py new file mode 100755 index 0000000000..9c59c1014c --- /dev/null +++ b/util/fptool.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""A tool to manage the fingerprint system on Chrome OS.""" + +import argparse +import os +import shutil +import subprocess +import sys + + +def cmd_flash(args: argparse.Namespace) -> int: + """ + Flash the entire firmware FPMCU using the native bootloader. + + This requires the Chromebook to be in dev mode with hardware write protect + disabled. + """ + + if not shutil.which('flash_fp_mcu'): + print('Error - The flash_fp_mcu utility does not exist.') + return 1 + + cmd = ['flash_fp_mcu'] + if args.image: + if not os.path.isfile(args.image): + print(f'Error - image {args.image} is not a file.') + return 1 + cmd.append(args.image) + + print(f'Running {" ".join(cmd)}.') + sys.stdout.flush() + p = subprocess.run(cmd) + return p.returncode + + +def main(argv: list) -> int: + parser = argparse.ArgumentParser(description=__doc__) + subparsers = parser.add_subparsers(dest='subcommand', title='subcommands') + # This method of setting required is more compatible with older python. + subparsers.required = True + + # Parser for "flash" subcommand. + parser_decrypt = subparsers.add_parser('flash', help=cmd_flash.__doc__) + parser_decrypt.add_argument( + 'image', nargs='?', help='Path to the firmware image') + parser_decrypt.set_defaults(func=cmd_flash) + opts = parser.parse_args(argv) + return opts.func(opts) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) |