summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2019-03-13 17:35:01 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-17 17:32:43 -0700
commitb5366bcd54fbe92ea77db6d2d6d981f65568880e (patch)
treea2ad1b9aaf80aa9d7b9c8b29c34f4d933022953a /extra
parent519a9c967c2e883aebcf5ee00a23131e8e51c515 (diff)
downloadchrome-ec-b5366bcd54fbe92ea77db6d2d6d981f65568880e.tar.gz
gsctool: refactor assignment of Boolean flag options
Many of gsctool command line options result in setting a Boolean flag. This patch collects all such flags in a structure, and uses a function to iterate over flags when examining command line options. BRANCH=none BUG=none TEST=verified that Boolean command line options still can be set. Change-Id: Id4a14e573ced893650c4c1c81f8ef92fc0d03bc5 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1525148 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Diffstat (limited to 'extra')
-rw-r--r--extra/usb_updater/gsctool.c91
-rw-r--r--extra/usb_updater/gsctool.h8
2 files changed, 57 insertions, 42 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c
index 44cd39938e..f93b71de50 100644
--- a/extra/usb_updater/gsctool.c
+++ b/extra/usb_updater/gsctool.c
@@ -183,6 +183,15 @@ struct upgrade_pkt {
};
} __packed;
+/*
+ * Structure used to simplify mapping command line options into Boolean
+ * variables. If an option is present, the corresponding integer value is set
+ * to 1.
+ */
+struct options_map {
+ char opt;
+ int *flag;
+};
/*
* This by far exceeds the largest vendor command response size we ever
@@ -2143,6 +2152,26 @@ static int process_tpm_mode(struct transfer_descriptor *td,
return rv;
}
+/*
+ * Search the passed in zero terminated array of options_map structures for
+ * option 'option'.
+ *
+ * If found - set the corresponding integer to 1 and return 1. If not found -
+ * return 0.
+ */
+static int check_boolean(const struct options_map *omap, char option)
+{
+ do {
+ if (omap->opt != option)
+ continue;
+
+ *omap->flag = 1;
+ return 1;
+ } while (!(++omap)->opt);
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
struct transfer_descriptor td;
@@ -2182,6 +2211,27 @@ int main(int argc, char *argv[])
uint8_t sn_inc_rma_arg;
/*
+ * All options which result in setting a Boolean flag to True, along
+ * with addresses of the flags. Terminated by a zeroed entry.
+ */
+ const struct options_map omap[] = {
+ { 'B', &td.background_update_supported},
+ { 'b', &binary_vers },
+ { 'c', &corrupt_inactive_rw },
+ { 'f', &show_fw_ver },
+ { 'I', &ccd_info },
+ { 'k', &ccd_lock },
+ { 'o', &ccd_open },
+ { 'P', &password },
+ { 'p', &td.post_reset },
+ { 'U', &ccd_unlock },
+ { 'u', &td.upstart_mode },
+ { 'V', &verbose_mode },
+ { 'w', &wp },
+ {},
+ };
+
+ /*
* Explicitly sets buffering type to line buffered so that output
* lines can be written to pipe instantly. This is needed when the
* cr50-verify-ro.sh execution in verify_ro is moved from crosh to
@@ -2203,6 +2253,8 @@ int main(int argc, char *argv[])
errorcnt = 0;
opterr = 0; /* quiet, you */
while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) {
+ if (check_boolean(omap, i))
+ continue;
switch (i) {
case 'a':
if (td.ep_type) {
@@ -2214,15 +2266,6 @@ int main(int argc, char *argv[])
/* Try dev_xfer first. */
td.ep_type = dev_xfer;
break;
- case 'B':
- td.background_update_supported = 1;
- break;
- case 'b':
- binary_vers = 1;
- break;
- case 'c':
- corrupt_inactive_rw = 1;
- break;
case 'd':
if (!parse_vidpid(optarg, &vid, &pid)) {
fprintf(stderr,
@@ -2235,15 +2278,9 @@ int main(int argc, char *argv[])
factory_mode = 1;
factory_mode_arg = optarg;
break;
- case 'f':
- show_fw_ver = 1;
- break;
case 'h':
usage(errorcnt);
break;
- case 'I':
- ccd_info = 1;
- break;
case 'i':
if (!optarg && argv[optind] && argv[optind][0] != '-')
/* optional argument present. */
@@ -2256,9 +2293,6 @@ int main(int argc, char *argv[])
errorcnt++;
}
break;
- case 'k':
- ccd_lock = 1;
- break;
case 'M':
show_machine_output = true;
break;
@@ -2272,15 +2306,6 @@ int main(int argc, char *argv[])
case 'O':
openbox_desc_file = optarg;
break;
- case 'o':
- ccd_open = 1;
- break;
- case 'p':
- td.post_reset = 1;
- break;
- case 'P':
- password = 1;
- break;
case 'r':
rma = 1;
@@ -2336,21 +2361,9 @@ int main(int argc, char *argv[])
}
td.ep_type = ts_xfer;
break;
- case 'U':
- ccd_unlock = 1;
- break;
- case 'u':
- td.upstart_mode = 1;
- break;
- case 'V':
- verbose_mode = 1;
- break;
case 'v':
report_version(); /* This will call exit(). */
break;
- case 'w':
- wp = 1;
- break;
case 0: /* auto-handled option */
break;
case '?':
diff --git a/extra/usb_updater/gsctool.h b/extra/usb_updater/gsctool.h
index 920c7f4e05..d58c3ba71f 100644
--- a/extra/usb_updater/gsctool.h
+++ b/extra/usb_updater/gsctool.h
@@ -26,12 +26,12 @@ struct transfer_descriptor {
* RW images with the same version, as they get started based on the
* header timestamp.
*/
- uint32_t upstart_mode;
+ int upstart_mode;
/*
* Override in case updater is used w/ boards that do not follow
* the cr50 versioning scheme.
*/
- uint32_t background_update_supported;
+ int background_update_supported;
/*
* offsets of RO and WR sections available for update (not currently
@@ -39,7 +39,9 @@ struct transfer_descriptor {
*/
uint32_t ro_offset;
uint32_t rw_offset;
- uint32_t post_reset;
+
+ /* Do not reset the H1 immediately after update, wait for TPM reset. */
+ int post_reset;
/* Type of channel used to communicate with Cr50. */
enum transfer_type {