summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2022-02-25 12:38:57 +0800
committerCommit Bot <commit-bot@chromium.org>2022-03-01 02:41:43 +0000
commited3ae2dc822fc6607c0a669ab259424659c826f4 (patch)
tree18ffc295c81a145a2f8eec7f00f9dd8f56c2b8c2
parentcc3f48ba5dc64e91404fccdec100f6c67887b01a (diff)
downloadvboot-ed3ae2dc822fc6607c0a669ab259424659c826f4.tar.gz
futility: updater: allow writing multiple sections in one flash command
Add new function 'write_firmware_sections' so we can write update sections in one write_system_firmware (e.g., flashrom) command. BUG=b:221137867 TEST=build; and run test BRANCH=None Change-Id: Ia33ec5ac82e1c661457180ec45df6c02beae4ec3 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3490389 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/updater.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 021916a6..788e0e34 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -334,6 +334,10 @@ static int emulate_write_firmware(const char *filename,
struct firmware_section from, to;
int errorcnt = 0;
+ INFO("(emulation) Writing %s from %s to %s (emu=%s).\n",
+ section_name ? section_name : "the whole image",
+ image->file_name, image->programmer, filename);
+
from.data = image->data;
from.size = image->size;
@@ -411,39 +415,56 @@ static int is_the_same_programmer(const struct firmware_image *image1,
}
/*
- * Writes a section from given firmware image to system firmware.
- * If section_name is NULL, write whole image.
+ * Writes multiple sections from the given firmware image to the system.
+ * The 'sections' should be NULL (write the whole image) or a list of section
+ * names to write, and ended with NULL.
* Returns 0 if success, non-zero if error.
*/
-static int write_firmware(struct updater_config *cfg,
- const struct firmware_image *image,
- const char *section_name)
+static int write_firmware_sections(struct updater_config *cfg,
+ const struct firmware_image *image,
+ const char * const sections[])
{
+ int r = 0;
struct firmware_image *diff_image = NULL;
- const char *sections[2] = {0};
-
- sections[0] = section_name;
if (cfg->emulation) {
- INFO("(emulation) Writing %s from %s to %s (emu=%s).\n",
- section_name ? section_name : "whole image",
- image->file_name, image->programmer, cfg->emulation);
-
- return emulate_write_firmware(
- cfg->emulation, image, section_name);
+ int i;
+ if (!sections)
+ return emulate_write_firmware(
+ cfg->emulation, image, NULL);
+ for (i = 0; sections[i] && !r; i++) {
+ r |= emulate_write_firmware(
+ cfg->emulation, image, sections[i]);
+ }
+ return r;
}
if (cfg->use_diff_image && cfg->image_current.data &&
is_the_same_programmer(&cfg->image_current, image))
diff_image = &cfg->image_current;
- return write_system_firmware(image, diff_image,
- section_name ? sections : NULL,
+ return write_system_firmware(image, diff_image, sections,
&cfg->tempfiles, cfg->do_verify,
get_io_retries(cfg), cfg->verbosity + 1);
}
/*
+ * Writes a single section from the given firmware image to the system.
+ * Writes the whole firmware image if the section_name is NULL.
+ * Returns 0 if success, non-zero if error.
+ */
+static int write_firmware(struct updater_config *cfg,
+ const struct firmware_image *image,
+ const char *section_name)
+{
+ const char *sections[2] = {0};
+
+ sections[0] = section_name;
+ return write_firmware_sections(cfg, image,
+ section_name ? sections : NULL);
+}
+
+/*
* Returns True if we should start the update process for given image.
*/
static int has_valid_update(struct updater_config *cfg,