diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-10-15 14:57:34 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-22 06:16:35 -0700 |
commit | 92fe37cef28d58f6d64c625b30e72fab99ff42a5 (patch) | |
tree | b9ed716ec51119af8d8555e7589931201cfa0d94 /futility/updater.c | |
parent | 4d4c36e9df592548ae169cf6f145ecc9399a7963 (diff) | |
download | vboot-92fe37cef28d58f6d64c625b30e72fab99ff42a5.tar.gz |
futility: updater: Add '--model' and select images by system model
For devices using Unified Build, we have to select and load images from
archive by model configuration (setvars.sh). The system model can be
retrieved by $(mosys platform model), but for developers who want to
simulate or get images for particular platform, a command line argument
--model is needed.
BUG=chromium:875551
TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility
BRANCH=None
Change-Id: I8f4a6735b34bc694a05808b001c7309623b2afa3
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1278419
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/updater.c')
-rw-r--r-- | futility/updater.c | 91 |
1 files changed, 73 insertions, 18 deletions
diff --git a/futility/updater.c b/futility/updater.c index 5cd29f4a..17b12a2b 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -630,7 +630,8 @@ int load_firmware_image(struct firmware_image *image, const char *file_name, * Loads the active system firmware image (usually from SPI flash chip). * Returns 0 if success, non-zero if error. */ -int load_system_firmware(struct updater_config *cfg, struct firmware_image *image) +int load_system_firmware(struct updater_config *cfg, + struct firmware_image *image) { const char *tmp_file = updater_create_temp_file(cfg); @@ -1667,17 +1668,47 @@ static int updater_load_images(struct updater_config *cfg, } /* + * Setup what the updater has to do against an archive. + * Returns number of failures, or 0 on success. + */ +static int updater_setup_archive( + struct updater_config *cfg, + const struct updater_config_arguments *arg, + struct manifest *manifest) +{ + int errorcnt = 0; + struct archive *ar = cfg->archive; + const struct model_config *model; + + if (arg->do_manifest) { + assert(!arg->image); + print_json_manifest(manifest); + /* No additional error. */ + return errorcnt; + } + + model = manifest_find_model(manifest, arg->model); + if (!model) + return ++errorcnt; + + errorcnt += updater_load_images( + cfg, model->image, model->ec_image, model->pd_image); + errorcnt += patch_image_by_model(&cfg->image, model, ar); + return errorcnt; +} + +/* * Helper function to setup an allocated updater_config object. * Returns number of failures, or 0 on success. */ int updater_setup_config(struct updater_config *cfg, - const struct updater_config_arguments *arg) + const struct updater_config_arguments *arg, + int *do_update) { int errorcnt = 0; int check_single_image = 0, check_wp_disabled = 0; const char *default_quirks = NULL; const char *archive_path = arg->archive; - struct manifest *manifest = NULL; /* Setup values that may change output or decision of other argument. */ cfg->verbosity = arg->verbosity; @@ -1686,9 +1717,17 @@ int updater_setup_config(struct updater_config *cfg, cfg->force_update = 1; /* Check incompatible options and return early. */ - if (arg->do_manifest && !arg->archive) { - ERROR("Manifest is only available for archive."); - return ++errorcnt; + if (arg->do_manifest) { + if (!!arg->archive == !!arg->image) { + ERROR("--manifest needs either -a or -i"); + return ++errorcnt; + } + if (arg->archive && (arg->ec_image || arg->pd_image)) { + ERROR("--manifest for archive (-a) does not accept " + "additional images (--ec_image, --pd_image)."); + return ++errorcnt; + } + *do_update = 0; } /* Setup update mode. */ @@ -1740,6 +1779,11 @@ int updater_setup_config(struct updater_config *cfg, errorcnt += !!load_firmware_image( &cfg->image_current, arg->emulation, NULL); } + + /* Always load images specified from command line directly. */ + errorcnt += updater_load_images( + cfg, arg->image, arg->ec_image, arg->pd_image); + if (!archive_path) archive_path = "."; cfg->archive = archive_open(archive_path); @@ -1748,17 +1792,30 @@ int updater_setup_config(struct updater_config *cfg, return ++errorcnt; } - errorcnt += updater_load_images( - cfg, arg->image, arg->ec_image, arg->pd_image); - - if (arg->do_manifest) { - manifest = new_manifest_from_archive(cfg->archive); - if (!manifest) { - ERROR("Failure in archive: %s", archive_path); - return ++errorcnt; + /* Load images from archive. */ + if (arg->archive) { + struct manifest *m = new_manifest_from_archive(cfg->archive); + if (m) { + errorcnt += updater_setup_archive(cfg, arg, m); + delete_manifest(m); + } else { + ERROR("Failure in archive: %s", arg->archive); + ++errorcnt; } - print_json_manifest(manifest); - return errorcnt; + } else if (arg->do_manifest) { + char name[] = "default"; + struct model_config model = { + .name = name, + .image = arg->image, + .ec_image = arg->ec_image, + .pd_image = arg->pd_image, + }; + struct manifest manifest = { + .num = 1, + .models = &model, + }; + assert(model.image); + print_json_manifest(&manifest); } /* @@ -1781,8 +1838,6 @@ int updater_setup_config(struct updater_config *cfg, errorcnt++; ERROR("Factory mode needs WP disabled."); } - if (manifest) - delete_manifest(manifest); return errorcnt; } |