From ec240b9688b5240ff9e76baa62b83db3a427ddda Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 26 Jan 2022 10:28:42 +0800 Subject: futility: updater: allow changing GBB flags on erased flash The --gbb_flags supports changing GBB flags but the value will be ignored if the device flash was erased (e.g., no valid GBB section). To fix that we should check the 'to' and 'from' flash contents separately when preserving GBB data. BUG=b:216295706 TEST=build; emerge test BRANCH=None Change-Id: Ie02138dd4234b461ca1913bef1cabde8becf57c9 Signed-off-by: Hung-Te Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3414190 Reviewed-by: Yu-Ping Wu Commit-Queue: Yu-Ping Wu --- futility/updater.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/futility/updater.c b/futility/updater.c index 9a98adea..d58ea399 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -484,19 +484,27 @@ static int preserve_gbb(const struct firmware_image *image_from, const struct vb2_gbb_header *gbb_from; struct vb2_gbb_header *gbb_to; - gbb_from = find_gbb(image_from); - /* We do want to change GBB contents later. */ + /* Cast to non-const because we do want to change GBB contents later. */ gbb_to = (struct vb2_gbb_header *)find_gbb(image_to); - if (!gbb_from || !gbb_to) + /* + * For all cases, we need a valid gbb_to. Note for 'override GBB flags + * on a erased device', we only need gbb_to, not gbb_from. + */ + if (!gbb_to) return -1; + gbb_from = find_gbb(image_from); + /* Preserve (for non-factory mode) or override flags. */ if (override_flags) gbb_to->flags = override_value; - else if (preserve_flags) + else if (preserve_flags && gbb_from) gbb_to->flags = gbb_from->flags; + if (!gbb_from) + return -1; + /* Preserve HWID. */ return futil_set_gbb_hwid( gbb_to, (const char *)gbb_from + gbb_from->hwid_offset); -- cgit v1.2.1