summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2022-02-25 09:33:31 +0800
committerCommit Bot <commit-bot@chromium.org>2022-02-26 19:01:16 +0000
commit5a002dd61c28cef49145b92cc7be9f9278ce0481 (patch)
treeeaf7160648daa9ca1a238d46be75e32668aa91ea
parentf1144f4c25a38a78df7ac302f834d446270428e7 (diff)
downloadvboot-stabilize-14536.B.tar.gz
futility: updater: decide if we can use diff-image by programmerstabilize-14536.B
Previously we decide if the flash command can use the image_current as the diff image by comparing if the target image pointer is identical to the host image to write (cfg->image). This may not work properly if we try to write a temporary firmware image object loaded separately. A more correct way to is check if the image has the same programmer from the diff image (e.g., image_current). BUG=b:221137867 TEST=build and run futility tests. BRANCH=None Signed-off-by: Hung-Te Lin <hungte@chromium.org> Change-Id: Iee61cd9b47c0db4b87001bbb348f95a89495b975 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3490386 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--futility/updater.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 66f42e48..bc68040e 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -392,6 +392,25 @@ static int get_io_retries(struct updater_config *cfg)
}
/*
+ * Returns 1 if the programmers in image1 and image2 are the same.
+ */
+static int is_the_same_programmer(const struct firmware_image *image1,
+ const struct firmware_image *image2)
+{
+ assert(image1 && image2);
+
+ /* Including if both are NULL. */
+ if (image1->programmer == image2->programmer)
+ return 1;
+
+ /* Not the same if either one is NULL. */
+ if (!image1->programmer || !image2->programmer)
+ return 0;
+
+ return strcmp(image1->programmer, image2->programmer) == 0;
+}
+
+/*
* Writes a section from given firmware image to system firmware.
* If section_name is NULL, write whole image.
* Returns 0 if success, non-zero if error.
@@ -411,10 +430,9 @@ static int write_firmware(struct updater_config *cfg,
cfg->emulation, image, section_name);
}
- if (cfg->use_diff_image && image == &cfg->image &&
- cfg->image_current.data) {
+ 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,
&cfg->tempfiles, cfg->do_verify,