diff options
author | Hung-Te Lin <hungte@chromium.org> | 2022-02-25 11:27:54 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-03-01 02:41:41 +0000 |
commit | cc3f48ba5dc64e91404fccdec100f6c67887b01a (patch) | |
tree | 355d61887d2935459ee87cb64a06329f189c53dd /futility/updater_utils.c | |
parent | 07a7bc69641129e937ab702b95e893d4a5ba45fd (diff) | |
download | vboot-cc3f48ba5dc64e91404fccdec100f6c67887b01a.tar.gz |
futility: flashrom_drv: support partial write for multiple regions
When we have multiple regions to update, invoking flashrom_write_image
multiple times will take much longer because for each write it has to
read the whole flash, write and then verify whole flash (also timer
calibration and programmer init/shutdown every time).
As a result, we want to support writing multiple regions - just like
that flashrom can take arbitrary numbers of "-i REGION".
This change only extended flashrom_write_image, and the firmware updater
is calling flashrom_drv multiple times. That will be addressed in the
follow up changes.
BUG=b:221137867
TEST=build; and run test
BRANCH=None
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Change-Id: Id335cc9f816f1384f1886422efa97fe2c7b81aec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3490388
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'futility/updater_utils.c')
-rw-r--r-- | futility/updater_utils.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c index 9f91129e..18e40000 100644 --- a/futility/updater_utils.c +++ b/futility/updater_utils.c @@ -543,31 +543,49 @@ int load_system_firmware(struct firmware_image *image, } /* - * Writes a section from given firmware image to system firmware. - * If section_name is NULL, write whole image. + * Writes sections from a given firmware image to the system firmware. + * Regions should be NULL for writing the whole image, or a list of + * FMAP section names (and ended with a NULL). * Returns 0 if success, non-zero if error. */ int write_system_firmware(const struct firmware_image *image, const struct firmware_image *diff_image, - const char *section_name, + const char * const sections[], struct tempfile *tempfiles, int do_verify, int retries, int verbosity) { - int r, i; + int r, i, len = 0; + char *partial = NULL; + + for (i = 0; sections && sections[i]; i++) + len += strlen(sections[i]) + strlen(" -i "); + if (len) { + partial = (char *)malloc(len + 1); + if (!partial) { + ERROR("Failed to allocate a string buffer.\n"); + return -1; + } + partial[0] = '\0'; + for (i = 0; sections[i]; i++) { + strcat(partial, " -i "); + strcat(partial, sections[i]); + } + assert(strlen(partial) == len); + } - INFO("flashrom -w <IMAGE> -p %s%s%s%s%s%s\n", + INFO("flashrom -w <IMAGE> -p %s%s%s%s%s\n", image->programmer, diff_image ? " --flash-contents <DIFF_IMAGE>" : "", do_verify ? "" : " --noverify", verbosity > 1 ? " -V" : "", - section_name ? " -i " : "", - section_name ? section_name : ""); + partial ? partial : ""); + free(partial); for (i = 1, r = -1; i <= retries && r != 0; i++) { if (i > 1) WARN("Retry writing firmware (%d/%d)...\n", i, retries); - r = flashrom_write_image(image, section_name, diff_image, - do_verify, verbosity + 1); + r = flashrom_write_image(image, sections, diff_image, do_verify, + verbosity + 1); /* * Force a newline to flush stdout in case if * flashrom_write_image left some messages in the buffer. |