diff options
author | Edward O'Callaghan <quasisec@google.com> | 2021-10-27 11:48:21 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-28 11:06:15 +0000 |
commit | d02f026a8d6635c0f38743bf257db2526a3143f0 (patch) | |
tree | 11862bc583a1750cd32a878c665998f90a1b3ba6 | |
parent | f87910fd255c329d089d5789ff26ac226f383068 (diff) | |
download | vboot-d02f026a8d6635c0f38743bf257db2526a3143f0.tar.gz |
vboot_reference/futility: Split load_firmware_image() fnstabilize-14312.B
This is in prep for removing the need for temp files.
V.2:
Move validation into parse_firmware_image()
BUG=b:203715651
BRANCH=none
TEST=cros deploy to nocturne and ran:
`/usr/sbin/chromeos-firmware --mode=recovery`.
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Change-Id: Id61fcb0f53546a78085e0a367c21780c5885bc51
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3244679
Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Tested-by: Edward O'Callaghan <quasisec@chromium.org>
Auto-Submit: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
-rw-r--r-- | futility/updater_utils.c | 65 |
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. |