diff options
author | Evan Benn <evanbenn@chromium.org> | 2022-12-01 16:27:57 +1100 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-06 21:42:19 +0000 |
commit | 0b6b689d650f89eaa619ef4207f0737eb8aca34a (patch) | |
tree | 27e8910bb9b01d0aa29c86eae8ab5c5964ecd9e2 | |
parent | ecb87bfcbaca7cb33e0fdcfa27e9745a59676e80 (diff) | |
download | vboot-0b6b689d650f89eaa619ef4207f0737eb8aca34a.tar.gz |
futility: Move some argument handling to shared file
Updater arguments dealing with flash and servo control will be common
with other commands. Move those to a shared file.
BUG=b:260531154
BRANCH=None
TEST=FEATURES=test emerge-grunt vboot_reference
TEST=futility gbb -s --flags 0x0 /tmp/bios /tmp/bios2
Change-Id: I0a6c992425cf7ca529b3857cfabc654ae2b1be81
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4075308
Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r-- | futility/cmd_update.c | 57 | ||||
-rw-r--r-- | futility/updater.c | 37 | ||||
-rw-r--r-- | futility/updater.h | 41 |
3 files changed, 87 insertions, 48 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c index 2f34c556..c47ab325 100644 --- a/futility/cmd_update.c +++ b/futility/cmd_update.c @@ -16,11 +16,8 @@ #ifdef USE_FLASHROM enum { - OPT_DUMMY = 0x100, - - OPT_CCD, + OPT_DUMMY = 0x1000, OPT_DETECT_MODEL_ONLY, - OPT_EMULATE, OPT_FACTORY, OPT_FAST, OPT_FORCE, @@ -33,9 +30,7 @@ enum { OPT_QUIRKS, OPT_QUIRKS_LIST, OPT_REPACK, - OPT_SERVO, OPT_SERVO_NORESET, - OPT_SERVO_PORT, OPT_SIGNATURE, OPT_SYS_PROPS, OPT_UNPACK, @@ -44,6 +39,7 @@ enum { /* Command line options */ static struct option const long_opts[] = { + SHARED_FLASH_ARGS_LONGOPTS /* name has_arg *flag val */ {"help", 0, NULL, 'h'}, {"debug", 0, NULL, 'd'}, @@ -53,25 +49,20 @@ static struct option const long_opts[] = { {"ec_image", 1, NULL, 'e'}, {"try", 0, NULL, 't'}, {"archive", 1, NULL, 'a'}, - {"programmer", 1, NULL, 'p'}, {"mode", 1, NULL, 'm'}, - {"ccd", 0, NULL, OPT_CCD}, - {"servo", 0, NULL, OPT_SERVO}, - {"servo_port", 1, NULL, OPT_SERVO_PORT}, {"detect-model-only", 0, NULL, OPT_DETECT_MODEL_ONLY}, - {"emulate", 1, NULL, OPT_EMULATE}, {"factory", 0, NULL, OPT_FACTORY}, {"fast", 0, NULL, OPT_FAST}, {"force", 0, NULL, OPT_FORCE}, {"gbb_flags", 1, NULL, OPT_GBB_FLAGS}, {"host_only", 0, NULL, OPT_HOST_ONLY}, + {"quirks", 1, NULL, OPT_QUIRKS}, {"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}, @@ -90,7 +81,8 @@ static struct option const long_opts[] = { {NULL, 0, NULL, 0}, }; -static const char * const short_opts = "hdvi:e:ta:m:p:"; +static const char *const short_opts = + "hdvi:e:ta:m:" SHARED_FLASH_ARGS_SHORTOPTS; static void print_help(int argc, char *argv[]) { @@ -114,12 +106,12 @@ static void print_help(int argc, char *argv[]) "-t, --try \tTry A/B update on reboot if possible\n" "-a, --archive=PATH \tRead resources from archive\n" " --unpack=DIR \tExtracts archive to DIR\n" - "-p, --programmer=PRG\tChange AP (host) flashrom programmer\n" " --fast \tReduce read cycles and do not verify\n" " --quirks=LIST \tSpecify the quirks to apply\n" " --list-quirks \tPrint all available quirks\n" "-m, --mode=MODE \tRun updater in the specified mode\n" " --manifest \tScan the archive to print a manifest in JSON\n" + SHARED_FLASH_ARGS_HELP "\n" " * If both --manifest and --fast are specified, the updater\n" " will not scan the archive and simply dump the previously\n" @@ -133,13 +125,9 @@ static void print_help(int argc, char *argv[]) "Debugging and testing options:\n" " --wp=1|0 \tSpecify write protection status\n" " --host_only \tUpdate only AP (host) firmware\n" - " --emulate=FILE \tEmulate system firmware using file\n" " --model=MODEL \tOverride system model for images\n" " --detect-model-only\tDetect model by reading the FRID and exit\n" " --gbb_flags=FLAG\tOverride new GBB flags\n" - " --ccd \tDo fast,force,wp=0,p=raiden_debug_spi\n" - " --servo \tFlash using Servo (v2, v4, micro, ...)\n" - " --servo_port=PRT\tOverride servod port, implies --servo\n" " --signature_id=S\tOverride signature ID for key files\n" " --sys_props=LIST\tList of system properties to override\n" "-d, --debug \tPrint debugging messages\n" @@ -153,7 +141,6 @@ static int do_update(int argc, char *argv[]) struct updater_config *cfg; struct updater_config_arguments args = {0}; int i, errorcnt = 0, update_needed = 1; - int detect_servo = 0; const char *prepare_ctrl_name = NULL; char *servo_programmer = NULL; char *endptr; @@ -163,6 +150,8 @@ static int do_update(int argc, char *argv[]) opterr = 0; while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) { + if (handle_flash_argument(&args, i, optarg)) + continue; switch (i) { case 'h': print_help(argc, argv); @@ -190,9 +179,6 @@ static int do_update(int argc, char *argv[]) case 'm': args.mode = optarg; break; - case 'p': - args.programmer = optarg; - break; case OPT_PD_IMAGE: args.pd_image = optarg; @@ -227,9 +213,6 @@ static int do_update(int argc, char *argv[]) case OPT_WRITE_PROTECTION: args.write_protection = optarg; break; - case OPT_EMULATE: - args.emulation = optarg; - break; case OPT_SYS_PROPS: args.sys_props = optarg; break; @@ -257,28 +240,6 @@ static int do_update(int argc, char *argv[]) args.override_gbb_flags = 1; } break; - case OPT_CCD: - args.fast_update = 1; - args.force_update = 1; - args.write_protection = "0"; - args.programmer = "raiden_debug_spi:target=AP"; - break; - case OPT_SERVO: - args.fast_update = 1; - args.force_update = 1; - args.write_protection = "0"; - args.host_only = 1; - detect_servo = 1; - break; - case OPT_SERVO_PORT: - setenv(ENV_SERVOD_PORT, optarg, 1); - args.fast_update = 1; - args.force_update = 1; - args.write_protection = "0"; - args.host_only = 1; - detect_servo = 1; - break; - case OPT_DUMMY: break; @@ -302,7 +263,7 @@ static int do_update(int argc, char *argv[]) ERROR("Unexpected arguments.\n"); } - if (!errorcnt && detect_servo) { + if (!errorcnt && args.detect_servo) { servo_programmer = host_detect_servo(&prepare_ctrl_name); if (!servo_programmer) diff --git a/futility/updater.c b/futility/updater.c index 5b3eed61..909339e0 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -1709,6 +1709,43 @@ int updater_setup_config(struct updater_config *cfg, return errorcnt; } +int handle_flash_argument(struct updater_config_arguments *args, int opt, + char *optarg) +{ + switch (opt) { + case 'p': + args->programmer = optarg; + break; + case OPT_CCD: + args->fast_update = 1; + args->force_update = 1; + args->write_protection = "0"; + args->programmer = "raiden_debug_spi:target=AP"; + break; + case OPT_EMULATE: + args->emulation = optarg; + break; + case OPT_SERVO: + args->detect_servo = 1; + args->fast_update = 1; + args->force_update = 1; + args->write_protection = "0"; + args->host_only = 1; + break; + case OPT_SERVO_PORT: + setenv(ENV_SERVOD_PORT, optarg, 1); + args->detect_servo = 1; + args->fast_update = 1; + args->force_update = 1; + args->write_protection = "0"; + args->host_only = 1; + break; + default: + return 0; + } + return 1; +} + /* * Releases all resources in an updater configuration object. */ diff --git a/futility/updater.h b/futility/updater.h index 4af2ccaf..7e249346 100644 --- a/futility/updater.h +++ b/futility/updater.h @@ -103,10 +103,44 @@ struct updater_config_arguments { int fast_update; int verbosity; int override_gbb_flags; + int detect_servo; uint32_t gbb_flags; bool detect_model_only; }; +/* + * Shared getopt arguments controlling flash behaviour. + * These are shared by multiple commands. + */ +enum { + OPT_CCD = 0x100, + OPT_EMULATE, + OPT_SERVO, + OPT_SERVO_PORT, +}; + +#ifdef USE_FLASHROM +#define SHARED_FLASH_ARGS_SHORTOPTS "p:" + +#define SHARED_FLASH_ARGS_LONGOPTS \ + {"programmer", 1, NULL, 'p'}, \ + {"ccd", 0, NULL, OPT_CCD}, \ + {"servo", 0, NULL, OPT_SERVO}, \ + {"servo_port", 1, NULL, OPT_SERVO_PORT}, \ + {"emulate", 1, NULL, OPT_EMULATE}, + +#define SHARED_FLASH_ARGS_HELP \ + "-p, --programmer=PRG\tChange AP (host) flashrom programmer\n" \ + " --ccd \tDo fast,force,wp=0,p=raiden_debug_spi\n" \ + " --emulate=FILE \tEmulate system firmware using file\n" \ + " --servo \tFlash using Servo (v2, v4, micro, ...)\n" \ + " --servo_port=PRT\tOverride servod port, implies --servo\n" +#else +#define SHARED_FLASH_ARGS_HELP +#define SHARED_FLASH_ARGS_LONGOPTS +#define SHARED_FLASH_ARGS_SHORTOPTS +#endif /* USE_FLASHROM */ + struct patch_config { char *rootkey; char *vblock_a; @@ -172,6 +206,13 @@ struct updater_config *updater_new_config(void); void updater_delete_config(struct updater_config *cfg); /* + * Handle an argument if it is a shared updater option. + * Returns 1 if argument was used. + */ +int handle_flash_argument(struct updater_config_arguments *args, int opt, + char *optarg); + +/* * Helper function to setup an allocated updater_config object. * Returns number of failures, or 0 on success. */ |