diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-10-16 12:26:20 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-22 06:16:36 -0700 |
commit | 6b5f9978fbfcfcab96b56a53429c9fd377176a9c (patch) | |
tree | 1a2b83482512608aadedbdcb9c29613eb3d370d5 /futility | |
parent | 4e066900210883a4f502e626998daf79b9b66665 (diff) | |
download | vboot-6b5f9978fbfcfcab96b56a53429c9fd377176a9c.tar.gz |
futility: updater: Support --mode=output and --output_dir
For backward compatibility, we need to support the 'output' mode in legacy
firmware updater. The output must select right files according to system
model, and apply all white label transform if needed.
BUG=chromium:875551
TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility
BRANCH=None
Change-Id: Ib433647317fa97387aa4a7f8f2101b47e6ca2123
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1282084
Diffstat (limited to 'futility')
-rw-r--r-- | futility/cmd_update.c | 5 | ||||
-rw-r--r-- | futility/updater.c | 36 | ||||
-rw-r--r-- | futility/updater.h | 1 |
3 files changed, 42 insertions, 0 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c index 2ba8a4e8..14b16877 100644 --- a/futility/cmd_update.c +++ b/futility/cmd_update.c @@ -34,6 +34,7 @@ static struct option const long_opts[] = { {"programmer", 1, NULL, 'p'}, {"wp", 1, NULL, 'W'}, {"emulate", 1, NULL, 'E'}, + {"output_dir", 1, NULL, 'U'}, {"sys_props", 1, NULL, 'S'}, {"debug", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, @@ -62,6 +63,7 @@ static void print_help(int argc, char *argv[]) "-m, --mode=MODE \tRun updater in given mode\n" " --factory \tAlias for --mode=factory\n" " --force \tForce update (skip checking contents)\n" + " --output_dir=DIR\tSpecify the target for --mode=output\n" "\n" "Debugging and testing options:\n" " --wp=1|0 \tSpecify write protection status\n" @@ -112,6 +114,9 @@ static int do_update(int argc, char *argv[]) case 'm': args.mode = optarg; break; + case 'U': + args.output_dir = optarg; + break; case 'M': args.model = optarg; break; diff --git a/futility/updater.c b/futility/updater.c index 0d69641b..6029612d 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -1668,6 +1668,30 @@ static int updater_load_images(struct updater_config *cfg, } /* + * Writes a firmware image to specified file. + * Returns 0 on success, otherwise failure. + */ +static int updater_output_image(const struct firmware_image *image, + const char *fname, const char *root) +{ + int r = 0; + char *fpath; + + if (!image->data) + return 0; + + ASPRINTF(&fpath, "%s/%s", root, fname); + r = vb2_write_file(fpath, image->data, image->size); + if (r) + ERROR("Failed writing firmware image to: %s", fpath); + else + printf("Firmware image saved in: %s\n", fpath); + + free(fpath); + return !!r; +} + +/* * Applies white label information to an existing model config. * Returns 0 on success, otherwise failure. */ @@ -1760,6 +1784,7 @@ int updater_setup_config(struct updater_config *cfg, { int errorcnt = 0; int check_single_image = 0, check_wp_disabled = 0; + int do_output = 0; const char *default_quirks = NULL; const char *archive_path = arg->archive; @@ -1796,6 +1821,8 @@ int updater_setup_config(struct updater_config *cfg, } else if (strcmp(arg->mode, "factory") == 0 || strcmp(arg->mode, "factory_install") == 0) { cfg->factory_update = 1; + } else if (strcmp(arg->mode, "output") == 0) { + do_output = 1; } else { errorcnt++; ERROR("Invalid mode: %s", arg->mode); @@ -1892,6 +1919,15 @@ int updater_setup_config(struct updater_config *cfg, errorcnt++; ERROR("Factory mode needs WP disabled."); } + if (!errorcnt && do_output) { + const char *r = arg->output_dir; + if (!r) + r = "."; + errorcnt += updater_output_image(&cfg->image, "bios.bin", r); + errorcnt += updater_output_image(&cfg->ec_image, "ec.bin", r); + errorcnt += updater_output_image(&cfg->pd_image, "pd.bin", r); + *do_update = 0; + } return errorcnt; } diff --git a/futility/updater.h b/futility/updater.h index ae6db16a..26e88dad 100644 --- a/futility/updater.h +++ b/futility/updater.h @@ -116,6 +116,7 @@ struct updater_config_arguments { char *archive, *quirks, *mode; char *programmer, *model, *signature_id; char *emulation, *sys_props, *write_protection; + char *output_dir; int is_factory, try_update, force_update, do_manifest; int verbosity; }; |