mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 18:41:11 +00:00
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user