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 <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>
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index 70ed396..51936a5 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -172,6 +172,45 @@
 	return 0;
 }
 
+static int parse_firmware_image(struct firmware_image *image)
+{
+	int ret = IMAGE_LOAD_SUCCESS;
+	const char *section_a = NULL, *section_b = NULL;
+
+	VB2_DEBUG("Image size: %d\n", image->size);
+	assert(image->data);
+
+	image->fmap_header = fmap_find(image->data, image->size);
+
+	if (!image->fmap_header) {
+		ERROR("Invalid image file (missing FMAP): %s\n", image->file_name);
+		ret = IMAGE_PARSE_FAILURE;
+	}
+
+	if (load_firmware_version(image, FMAP_RO_FRID, &image->ro_version))
+		ret = IMAGE_PARSE_FAILURE;
+
+	if (firmware_section_exists(image, FMAP_RW_FWID_A)) {
+		section_a = FMAP_RW_FWID_A;
+		section_b = FMAP_RW_FWID_B;
+	} else if (firmware_section_exists(image, FMAP_RW_FWID)) {
+		section_a = FMAP_RW_FWID;
+		section_b = FMAP_RW_FWID;
+	} else if (!ret) {
+		ERROR("Unsupported VBoot firmware (no RW ID): %s\n", image->file_name);
+		ret = IMAGE_PARSE_FAILURE;
+	}
+
+	/*
+	 * Load and initialize both RW A and B sections.
+	 * Note some unit tests will create only RW A.
+	 */
+	load_firmware_version(image, section_a, &image->rw_version_a);
+	load_firmware_version(image, section_b, &image->rw_version_b);
+
+	return ret;
+}
+
 /*
  * Loads a firmware image from file.
  * If archive is provided and file_name is a relative path, read the file from
@@ -182,9 +221,6 @@
 int load_firmware_image(struct firmware_image *image, const char *file_name,
 			struct archive *archive)
 {
-	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;
@@ -202,38 +238,9 @@
 		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);
-		ret = IMAGE_PARSE_FAILURE;
-	}
-
-	if (load_firmware_version(image, FMAP_RO_FRID, &image->ro_version))
-		ret = IMAGE_PARSE_FAILURE;
-
-	if (firmware_section_exists(image, FMAP_RW_FWID_A)) {
-		section_a = FMAP_RW_FWID_A;
-		section_b = FMAP_RW_FWID_B;
-	} else if (firmware_section_exists(image, FMAP_RW_FWID)) {
-		section_a = FMAP_RW_FWID;
-		section_b = FMAP_RW_FWID;
-	} else if (!ret) {
-		ERROR("Unsupported VBoot firmware (no RW ID): %s\n", file_name);
-		ret = IMAGE_PARSE_FAILURE;
-	}
-
-	/*
-	 * Load and initialize both RW A and B sections.
-	 * Note some unit tests will create only RW A.
-	 */
-	load_firmware_version(image, section_a, &image->rw_version_a);
-	load_firmware_version(image, section_b, &image->rw_version_b);
-
-	return ret;
+	return parse_firmware_image(image);
 }
 
 /*