From 5a002dd61c28cef49145b92cc7be9f9278ce0481 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Fri, 25 Feb 2022 09:33:31 +0800 Subject: futility: updater: decide if we can use diff-image by programmer 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 Change-Id: Iee61cd9b47c0db4b87001bbb348f95a89495b975 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3490386 Reviewed-by: Yu-Ping Wu Commit-Queue: Yu-Ping Wu --- futility/updater.c | 24 +++++++++++++++++++++--- 1 file 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 @@ -391,6 +391,25 @@ static int get_io_retries(struct updater_config *cfg) return 1 + get_config_quirk(QUIRK_EXTRA_RETRIES, 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. @@ -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, -- cgit v1.2.1