futility: updater: Allow --quirks=preserve_me=2 to force preserving ME

Some developers want to flash a firmware from a totally different branch
and the CSME may become totally different (and the CSME on the device
was already locked).

The `--preserve_me` quirk was designed for autoupdate, and in
recovery/factory modes we believe the device should be manually fixed so
the CSME & RO can be compatible. However, having a simple quirk to allow
developers who know their CSME/RO versions are not a problem would be
very helpful.

As a result, this patch extends the existing `--quirks=preserve_me`
so when a >=2 value is assigned then the developers can easily flash
their devices with a new firmware.

BUG=None
TEST=make runfutiltests -j
BRANCH=None

Change-Id: I894a0f9d18e12e3fea40aeda7bae31991bd87789
Signed-off-by: Hung-Te Lin <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/6491191
Reviewed-by: Yu-Ping Wu <[email protected]>
Commit-Queue: Yu-Ping Wu <[email protected]>
diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c
index c31361d..08ace47 100644
--- a/futility/updater_quirks.c
+++ b/futility/updater_quirks.c
@@ -331,16 +331,27 @@
 static int quirk_preserve_me(struct updater_config *cfg)
 {
 	/*
-	 * Only preserve the ME if performing an autoupdate-mode firmware
+	 * If the quirk config was manually set to >=2 (for developers to
+	 * manually do testing), we should also allow preserving ME in any
+	 * updating modes.
+	 *
+	 * However if the quirk config was set to 1 by default, we should
+	 * only preserve the ME if performing an autoupdate-mode firmware
 	 * update. Recovery, factory and any other update modes cannot leave the
 	 * ME as is. Otherwise, a recovery firmware update cannot be relied upon
 	 * to update the ME to a valid version for WP-disabled devices.
 	 */
-	if (cfg->try_update == TRY_UPDATE_OFF) {
-		INFO("No auto-update requested. Not preserving ME.\n");
-		return 0;
+	int mode = get_config_quirk(QUIRK_PRESERVE_ME, cfg);
+	if (mode >= 2) {
+		WARN("FORCED TO PRESERVE CSME. "
+		     "YOUR SYSTEM MAY BE UNSTABLE DUE TO USING AN INCOMPATIBLE CSME.\n");
+	} else {
+		if (cfg->try_update == TRY_UPDATE_OFF) {
+			INFO("No auto-update requested. Not preserving ME.\n");
+			return 0;
+		}
+		INFO("Auto-update requested. Preserving ME.\n");
 	}
-	INFO("Auto-update requested. Preserving ME.\n");
 
 	/*
 	 * b/213706510: subratabanik@ confirmed CSE may modify itself while we
@@ -467,7 +478,8 @@
 	quirks = &cfg->quirks[QUIRK_PRESERVE_ME];
 	quirks->name = "preserve_me";
 	quirks->help = "b/165590952; Preserve ME during firmware update except "
-		       "for factory update or developer images.";
+		       "for factory update or developer images. Add =2 to "
+		       "always preserve in any modes.";
 	quirks->apply = quirk_preserve_me;
 
 	quirks = &cfg->quirks[QUIRK_NO_CHECK_PLATFORM];
OSZAR »