summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2022-04-30 01:57:26 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-05 09:03:26 +0000
commitdd04ea86966be157e1962475c42c23a44081038d (patch)
tree9a82e3130110b144f93842e038a1055ae0d6059b
parent2f21f0f1928aa9e92fc9e69900eafaa9933f836c (diff)
downloadvboot-dd04ea86966be157e1962475c42c23a44081038d.tar.gz
futility: updater: refactor creating manifest from a simple folder
Move the creation of simple folder manifest to a new function. No changes in functionality. BUG=None TEST=make; run test BRANCH=None Change-Id: I302752183fc4f385f9b915023d26723a5cbd0c1c Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3615697 Commit-Queue: Yu-Ping Wu <yupingso@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--futility/updater_archive.c91
1 files changed, 52 insertions, 39 deletions
diff --git a/futility/updater_archive.c b/futility/updater_archive.c
index 4ed12aab..03f1827a 100644
--- a/futility/updater_archive.c
+++ b/futility/updater_archive.c
@@ -980,6 +980,56 @@ static int manifest_from_signer_config(struct manifest *manifest)
return 0;
}
+/*
+ * Creates the manifest from a simple (legacy) folder with only 1 set of
+ * firmware images.
+ * Returns 0 on success (loaded), otherwise failure.
+ */
+static int manifest_from_simple_folder(struct manifest *manifest)
+{
+ const char * const host_image_name = "image.bin",
+ * const old_host_image_name = "bios.bin",
+ * const ec_name = "ec.bin",
+ * const pd_name = "pd.bin";
+ struct archive *archive = manifest->archive;
+ const char *image_name = NULL;
+ struct firmware_image image = {0};
+ struct model_config model = {0};
+
+ /* Try to load from current folder. */
+ if (archive_has_entry(archive, old_host_image_name))
+ image_name = old_host_image_name;
+ else if (archive_has_entry(archive, host_image_name))
+ image_name = host_image_name;
+ else
+ return 1;
+
+ model.image = strdup(image_name);
+ if (archive_has_entry(archive, ec_name))
+ model.ec_image = strdup(ec_name);
+ if (archive_has_entry(archive, pd_name))
+ model.pd_image = strdup(pd_name);
+ /* Extract model name from FWID: $Vendor_$Platform.$Version */
+ if (!load_firmware_image(&image, image_name, archive)) {
+ char *token = NULL;
+ if (strtok(image.ro_version, "_"))
+ token = strtok(NULL, ".");
+ if (token && *token) {
+ str_convert(token, tolower);
+ model.name = strdup(token);
+ }
+ free_firmware_image(&image);
+ }
+ if (!model.name)
+ model.name = strdup(DEFAULT_MODEL_NAME);
+ if (manifest->has_keyset)
+ model.is_custom_label = 1;
+ manifest_add_model(manifest, &model);
+ manifest->default_model = manifest->num - 1;
+
+ return 0;
+}
+
/**
* get_manifest_key() - Wrapper to get the firmware manifest key from crosid
*
@@ -1157,11 +1207,6 @@ int model_apply_custom_label(
struct manifest *new_manifest_from_archive(struct archive *archive)
{
struct manifest manifest = {0}, *new_manifest;
- struct model_config model = {0};
- const char * const host_image_name = "image.bin",
- * const old_host_image_name = "bios.bin",
- * const ec_name = "ec.bin",
- * const pd_name = "pd.bin";
manifest.archive = archive;
manifest.default_model = -1;
@@ -1178,43 +1223,11 @@ struct manifest *new_manifest_from_archive(struct archive *archive)
VB2_DEBUG("Try to build a manifest from a */firmware folder\n");
archive_walk(archive, &manifest, manifest_scan_raw_entries);
}
-
if (manifest.num == 0) {
- const char *image_name = NULL;
- struct firmware_image image = {0};
-
VB2_DEBUG("Try to build a manifest from a simple folder\n");
- /* Try to load from current folder. */
- if (archive_has_entry(archive, old_host_image_name))
- image_name = old_host_image_name;
- else if (archive_has_entry(archive, host_image_name))
- image_name = host_image_name;
- else
- return 0;
-
- model.image = strdup(image_name);
- if (archive_has_entry(archive, ec_name))
- model.ec_image = strdup(ec_name);
- if (archive_has_entry(archive, pd_name))
- model.pd_image = strdup(pd_name);
- /* Extract model name from FWID: $Vendor_$Platform.$Version */
- if (!load_firmware_image(&image, image_name, archive)) {
- char *token = NULL;
- if (strtok(image.ro_version, "_"))
- token = strtok(NULL, ".");
- if (token && *token) {
- str_convert(token, tolower);
- model.name = strdup(token);
- }
- free_firmware_image(&image);
- }
- if (!model.name)
- model.name = strdup(DEFAULT_MODEL_NAME);
- if (manifest.has_keyset)
- model.is_custom_label = 1;
- manifest_add_model(&manifest, &model);
- manifest.default_model = manifest.num - 1;
+ manifest_from_simple_folder(&manifest);
}
+
VB2_DEBUG("%d model(s) loaded.\n", manifest.num);
if (!manifest.num) {
ERROR("No valid configurations found from archive.\n");