summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2019-04-16 12:22:19 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-04-18 03:27:45 -0700
commit266ec6ba6c86be22a998265a610da0513c0bb2b0 (patch)
treed9ad12f0306269492f760582c3e5e52e9f7999c0
parent8ac919aefac73c6debcee4f70b019ff42177670d (diff)
downloadvboot-stabilize-12121.B.tar.gz
For options only available in long-form (--something), we should encode using enum OPT_SOMETHING instead of random characters. Also added dummy --update_ec, --update_pd, and --check_keys because getopt* needs to have them explicitly defined (while the original shflags will generate both --cmd and --nocmd automatically). BUG=chromium:943262 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I701d88f6f5c346581651ed4f8bf004203672e209 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1569145
-rw-r--r--futility/cmd_update.c156
1 files changed, 90 insertions, 66 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index 1a56c4f4..da06d6fc 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -16,48 +16,71 @@
enum {
OPT_DUMMY = 0x100,
+
OPT_CCD,
+ OPT_EMULATE,
+ OPT_FACTORY,
OPT_FAST,
+ OPT_FORCE,
+ OPT_HOST_ONLY,
+ OPT_MANIFEST,
+ OPT_MODEL,
+ OPT_OUTPUT_DIR,
+ OPT_PD_IMAGE,
+ OPT_QUIRKS,
+ OPT_QUIRKS_LIST,
+ OPT_REPACK,
+ OPT_SIGNATURE,
+ OPT_SYS_PROPS,
+ OPT_UNPACK,
+ OPT_WRITE_PROTECTION,
};
/* Command line options */
static struct option const long_opts[] = {
/* name has_arg *flag val */
+ {"help", 0, NULL, 'h'},
+ {"debug", 0, NULL, 'd'},
+ {"verbose", 0, NULL, 'v'},
+
{"image", 1, NULL, 'i'},
{"ec_image", 1, NULL, 'e'},
- {"pd_image", 1, NULL, 'P'},
{"try", 0, NULL, 't'},
{"archive", 1, NULL, 'a'},
- {"quirks", 1, NULL, 'f'},
- {"list-quirks", 0, NULL, 'L'},
- {"mode", 1, NULL, 'm'},
- {"model", 1, NULL, 'M'},
- {"signature_id", 1, NULL, 'G'},
- {"manifest", 0, NULL, 'A'},
- {"repack", 1, NULL, 'k'},
- {"unpack", 1, NULL, 'u'},
- {"factory", 0, NULL, 'Y'},
- {"fast", 0, NULL, OPT_FAST},
- {"force", 0, NULL, 'F'},
{"programmer", 1, NULL, 'p'},
- {"wp", 1, NULL, 'W'},
- {"host_only", 0, NULL, 'H'},
- {"emulate", 1, NULL, 'E'},
+ {"mode", 1, NULL, 'm'},
+
{"ccd", 0, NULL, OPT_CCD},
- {"output_dir", 1, NULL, 'U'},
- {"sys_props", 1, NULL, 'S'},
- {"debug", 0, NULL, 'd'},
- {"verbose", 0, NULL, 'v'},
- {"help", 0, NULL, 'h'},
+ {"emulate", 1, NULL, OPT_EMULATE},
+ {"factory", 0, NULL, OPT_FACTORY},
+ {"fast", 0, NULL, OPT_FAST},
+ {"force", 0, NULL, OPT_FORCE},
+ {"host_only", 0, NULL, OPT_HOST_ONLY},
+ {"list-quirks", 0, NULL, OPT_QUIRKS_LIST},
+ {"manifest", 0, NULL, OPT_MANIFEST},
+ {"model", 1, NULL, OPT_MODEL},
+ {"output_dir", 1, NULL, OPT_OUTPUT_DIR},
+ {"pd_image", 1, NULL, OPT_PD_IMAGE},
+ {"quirks", 1, NULL, OPT_QUIRKS},
+ {"repack", 1, NULL, OPT_REPACK},
+ {"signature_id", 1, NULL, OPT_SIGNATURE},
+ {"sys_props", 1, NULL, OPT_SYS_PROPS},
+ {"unpack", 1, NULL, OPT_UNPACK},
+ {"wp", 1, NULL, OPT_WRITE_PROTECTION},
+
/* TODO(hungte) Remove following deprecated options. */
- {"noupdate_ec", 0, NULL, 'H'}, /* --host_only */
- {"noupdate_pd", 0, NULL, 'H'}, /* --host_only */
- {"nocheck_keys", 0, NULL, 'F'}, /* --force */
+ {"noupdate_ec", 0, NULL, OPT_HOST_ONLY},
+ {"noupdate_pd", 0, NULL, OPT_HOST_ONLY},
+ {"nocheck_keys", 0, NULL, OPT_FORCE},
{"update_main", 0, NULL, OPT_DUMMY},
+ {"update_ec", 0, NULL, OPT_DUMMY},
+ {"update_pd", 0, NULL, OPT_DUMMY},
+ {"check_keys", 0, NULL, OPT_DUMMY},
+
{NULL, 0, NULL, 0},
};
-static const char * const short_opts = "hi:e:ta:m:p:dv";
+static const char * const short_opts = "hdvi:e:ta:m:p:";
static void print_help(int argc, char *argv[])
{
@@ -109,92 +132,93 @@ static int do_update(int argc, char *argv[])
opterr = 0;
while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) {
switch (i) {
+ case 'h':
+ print_help(argc, argv);
+ return !!errorcnt;
+ case 'd':
+ debugging_enabled = 1;
+ args.verbosity++;
+ break;
+ case 'v':
+ args.verbosity++;
+ break;
case 'i':
args.image = optarg;
break;
case 'e':
args.ec_image = optarg;
break;
- case 'P':
- args.pd_image = optarg;
- break;
case 't':
args.try_update = 1;
break;
case 'a':
args.archive = optarg;
break;
- case 'k':
+ case 'm':
+ args.mode = optarg;
+ break;
+ case 'p':
+ args.programmer = optarg;
+ break;
+
+ case OPT_PD_IMAGE:
+ args.pd_image = optarg;
+ break;
+ case OPT_REPACK:
args.repack = optarg;
break;
- case 'u':
+ case OPT_UNPACK:
args.unpack = optarg;
break;
- case 'f':
+ case OPT_QUIRKS:
args.quirks = optarg;
break;
- case 'L':
+ case OPT_QUIRKS_LIST:
updater_list_config_quirks(cfg);
return 0;
- case 'm':
- args.mode = optarg;
- break;
- case 'U':
+ case OPT_OUTPUT_DIR:
args.output_dir = optarg;
break;
- case 'M':
+ case OPT_MODEL:
args.model = optarg;
break;
- case 'G':
+ case OPT_SIGNATURE:
args.signature_id = optarg;
break;
- case 'A':
- args.do_manifest = 1;
- break;
- case 'Y':
- args.is_factory = 1;
- break;
- case 'W':
+ case OPT_WRITE_PROTECTION:
args.write_protection = optarg;
break;
- case 'H':
- args.host_only = 1;
- break;
- case 'E':
+ case OPT_EMULATE:
args.emulation = optarg;
break;
- case 'p':
- args.programmer = optarg;
+ case OPT_SYS_PROPS:
+ args.sys_props = optarg;
break;
- case 'F':
- args.force_update = 1;
+ case OPT_MANIFEST:
+ args.do_manifest = 1;
break;
- case 'S':
- args.sys_props = optarg;
+ case OPT_FACTORY:
+ args.is_factory = 1;
break;
- case 'v':
- args.verbosity++;
+ case OPT_HOST_ONLY:
+ args.host_only = 1;
break;
- case 'd':
- debugging_enabled = 1;
- args.verbosity++;
+ case OPT_FORCE:
+ args.force_update = 1;
+ break;
+ case OPT_FAST:
+ args.fast_update = 1;
break;
-
case OPT_CCD:
args.fast_update = 1;
args.force_update = 1;
args.write_protection = 0;
args.programmer = "raiden_debug_spi";
break;
- case OPT_FAST:
- args.fast_update = 1;
- break;
case OPT_DUMMY:
break;
- case 'h':
- print_help(argc, argv);
- return !!errorcnt;
+
case '?':
errorcnt++;
if (optopt)