summaryrefslogtreecommitdiff
path: root/futility/updater.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-10-16 12:26:20 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-22 06:16:36 -0700
commit6b5f9978fbfcfcab96b56a53429c9fd377176a9c (patch)
tree1a2b83482512608aadedbdcb9c29613eb3d370d5 /futility/updater.c
parent4e066900210883a4f502e626998daf79b9b66665 (diff)
downloadvboot-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/updater.c')
-rw-r--r--futility/updater.c36
1 files changed, 36 insertions, 0 deletions
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;
}