diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-01-05 12:16:27 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-05 03:14:37 -0800 |
commit | 9de2d245cf0168131ddc8fda284e8ee169012fa3 (patch) | |
tree | ce282ec71090d46951a077d7f26bbdcb3be3c426 /extra | |
parent | cfc69f6fb868b802a6033580ffe0cf73c092aca8 (diff) | |
download | chrome-ec-9de2d245cf0168131ddc8fda284e8ee169012fa3.tar.gz |
gsctool: Add option '--any' to auto-detect -s/-t availability.
For partners and developers, it's usually better to have a single simple
instruction to invoke commands. Currently gsctool needs either -s (if
/dev/tpm is not locked) or -t (if trunksd is running) and partners have
to either try both commands (-s or -t) or read the error messages and
try to figure out which option to use.
For example, see the extra logic in CL:831787.
Instead of putting the check everywhere in scripting, it seems easier
and more convenient to have a simple switch - "--any (-a)" that
automatically selects between -s and -t.
BUG=b:70184153
TEST=gsctool -f -a; stop trunksd; gsctool -f -a
Change-Id: Ie1590b0b8fef882178465ceee64a7150eda6b0dd
Reviewed-on: https://chromium-review.googlesource.com/851612
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'extra')
-rw-r--r-- | extra/usb_updater/gsctool.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index a0b4c28c7a..481231df27 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -238,9 +238,10 @@ struct transfer_descriptor { static uint32_t protocol_version; static char *progname; -static char *short_opts = "bcd:fhiPprstu"; +static char *short_opts = "abcd:fhiPprstu"; static const struct option long_opts[] = { /* name hasarg *flag val */ + {"any", 0, NULL, 'a'}, {"binvers", 0, NULL, 'b'}, {"board_id", 2, NULL, 'i'}, {"corrupt", 0, NULL, 'c'}, @@ -535,6 +536,8 @@ static void usage(int errs) "\n" "Options:\n" "\n" + " -a,--any Try any interfaces to find Cr50" + " (-d, -s, -t are all ignored)\n" " -b,--binvers Report versions of image's " "RW and RO headers, do not update\n" " -c,--corrupt Corrupt the inactive rw\n" @@ -1746,8 +1749,9 @@ int main(int argc, char *argv[]) struct board_id bid; enum board_id_action bid_action; int password = 0; + int try_all_transfer = 0; const char *exclusive_opt_error = - "Options -s and -t are mutually exclusive\n"; + "Options -a, -s and -t are mutually exclusive\n"; progname = strrchr(argv[0], '/'); if (progname) @@ -1764,6 +1768,16 @@ int main(int argc, char *argv[]) opterr = 0; /* quiet, you */ while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) { switch (i) { + case 'a': + if (td.ep_type) { + errorcnt++; + fprintf(stderr, "%s", exclusive_opt_error); + break; + } + try_all_transfer = 1; + /* Try dev_xfer first. */ + td.ep_type = dev_xfer; + break; case 'b': binary_vers = 1; break; @@ -1806,7 +1820,7 @@ int main(int argc, char *argv[]) rma_auth_code = optarg; break; case 's': - if (td.ep_type) { + if (td.ep_type || try_all_transfer) { errorcnt++; fprintf(stderr, "%s", exclusive_opt_error); break; @@ -1814,7 +1828,7 @@ int main(int argc, char *argv[]) td.ep_type = dev_xfer; break; case 't': - if (td.ep_type) { + if (td.ep_type || try_all_transfer) { errorcnt++; fprintf(stderr, "%s", exclusive_opt_error); break; @@ -1890,8 +1904,11 @@ int main(int argc, char *argv[]) } else if (td.ep_type == dev_xfer) { td.tpm_fd = open("/dev/tpm0", O_RDWR); if (td.tpm_fd < 0) { - perror("Could not open TPM"); - exit(update_error); + if (!try_all_transfer) { + perror("Could not open TPM"); + exit(update_error); + } + td.ep_type = ts_xfer; } } |