From d02f026a8d6635c0f38743bf257db2526a3143f0 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Wed, 27 Oct 2021 11:48:21 +1100 Subject: vboot_reference/futility: Split load_firmware_image() fn 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 Change-Id: Id61fcb0f53546a78085e0a367c21780c5885bc51 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3244679 Commit-Queue: Edward O'Callaghan Commit-Queue: Sam McNally Tested-by: Edward O'Callaghan Auto-Submit: Edward O'Callaghan Reviewed-by: Sam McNally --- futility/updater_utils.c | 65 +++++++++++++++++++++++++++--------------------- 1 file 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; } @@ -236,6 +211,38 @@ int load_firmware_image(struct firmware_image *image, const char *file_name, return ret; } +/* + * 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. * -- cgit v1.2.1