summaryrefslogtreecommitdiff
path: root/futility/updater_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/updater_utils.c')
-rw-r--r--futility/updater_utils.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index 70ed3962..51936a52 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -172,43 +172,18 @@ static int load_firmware_version(struct firmware_image *image,
return 0;
}
-/*
- * Loads a firmware image from file.
- * If archive is provided and file_name is a relative path, read the file from
- * archive.
- * Returns IMAGE_LOAD_SUCCESS on success, IMAGE_READ_FAILURE on file I/O
- * failure, or IMAGE_PARSE_FAILURE for non-vboot images.
- */
-int load_firmware_image(struct firmware_image *image, const char *file_name,
- struct archive *archive)
+static int parse_firmware_image(struct firmware_image *image)
{
int ret = IMAGE_LOAD_SUCCESS;
const char *section_a = NULL, *section_b = NULL;
- if (!file_name) {
- ERROR("No file name given\n");
- return IMAGE_READ_FAILURE;
- }
-
- VB2_DEBUG("Load image file from %s...\n", file_name);
-
- if (!archive_has_entry(archive, file_name)) {
- ERROR("Does not exist: %s\n", file_name);
- return IMAGE_READ_FAILURE;
- }
- if (archive_read_file(archive, file_name, &image->data, &image->size,
- NULL) != VB2_SUCCESS) {
- ERROR("Failed to load %s\n", file_name);
- return IMAGE_READ_FAILURE;
- }
-
VB2_DEBUG("Image size: %d\n", image->size);
assert(image->data);
- image->file_name = strdup(file_name);
+
image->fmap_header = fmap_find(image->data, image->size);
if (!image->fmap_header) {
- ERROR("Invalid image file (missing FMAP): %s\n", file_name);
+ ERROR("Invalid image file (missing FMAP): %s\n", image->file_name);
ret = IMAGE_PARSE_FAILURE;
}
@@ -222,7 +197,7 @@ int load_firmware_image(struct firmware_image *image, const char *file_name,
section_a = FMAP_RW_FWID;
section_b = FMAP_RW_FWID;
} else if (!ret) {
- ERROR("Unsupported VBoot firmware (no RW ID): %s\n", file_name);
+ ERROR("Unsupported VBoot firmware (no RW ID): %s\n", image->file_name);
ret = IMAGE_PARSE_FAILURE;
}
@@ -237,6 +212,38 @@ int load_firmware_image(struct firmware_image *image, const char *file_name,
}
/*
+ * Loads a firmware image from file.
+ * If archive is provided and file_name is a relative path, read the file from
+ * archive.
+ * Returns IMAGE_LOAD_SUCCESS on success, IMAGE_READ_FAILURE on file I/O
+ * failure, or IMAGE_PARSE_FAILURE for non-vboot images.
+ */
+int load_firmware_image(struct firmware_image *image, const char *file_name,
+ struct archive *archive)
+{
+ if (!file_name) {
+ ERROR("No file name given\n");
+ return IMAGE_READ_FAILURE;
+ }
+
+ VB2_DEBUG("Load image file from %s...\n", file_name);
+
+ if (!archive_has_entry(archive, file_name)) {
+ ERROR("Does not exist: %s\n", file_name);
+ return IMAGE_READ_FAILURE;
+ }
+ if (archive_read_file(archive, file_name, &image->data, &image->size,
+ NULL) != VB2_SUCCESS) {
+ ERROR("Failed to load %s\n", file_name);
+ return IMAGE_READ_FAILURE;
+ }
+
+ image->file_name = strdup(file_name);
+
+ return parse_firmware_image(image);
+}
+
+/*
* Generates a temporary file for snapshot of firmware image contents.
*
* Returns a file path if success, otherwise NULL.