From 6b5f9978fbfcfcab96b56a53429c9fd377176a9c Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Tue, 16 Oct 2018 12:26:20 +0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/1282084 --- futility/updater.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'futility/updater.c') diff --git a/futility/updater.c b/futility/updater.c index 0d69641b..6029612d 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -1667,6 +1667,30 @@ static int updater_load_images(struct updater_config *cfg, return errorcnt; } +/* + * 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; } -- cgit v1.2.1