summaryrefslogtreecommitdiff
path: root/futility/updater.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/updater.c')
-rw-r--r--futility/updater.c91
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;
}