futility: updater: Add new quirk 'allow_empty_wltag'

There were devices shipped as "only device" (no key set) and then became
one of the "white label" family. This is now no longer valid on newer
devices but we have to support the legacy ones, for example Reks.

BUG=chromium:906962
TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility
BRANCH=None

Change-Id: I437be08726ab2c46229062689bf765ac6837ca5d
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1345610
Reviewed-by: Youcheng Syu <youcheng@chromium.org>
diff --git a/futility/updater.c b/futility/updater.c
index 2f7a29c..1c71c45 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -1847,6 +1847,11 @@
 	if (!model)
 		return ++errorcnt;
 
+	/* Load images now so we can get quirks in WL checks. */
+	errorcnt += updater_load_images(
+			cfg, arg, model->image, model->ec_image,
+			model->pd_image);
+
 	if (model->is_white_label) {
 		/*
 		 * It is fine to fail in updater_apply_white_label for factory
@@ -1856,17 +1861,17 @@
 		updater_apply_white_label(cfg, (struct model_config *)model,
 					  arg->signature_id);
 		if (!model->patches.rootkey) {
-			if (!is_factory) {
+			if (is_factory ||
+			    is_write_protection_enabled(cfg) ||
+			    get_config_quirk(QUIRK_ALLOW_EMPTY_WLTAG, cfg)) {
+				fprintf(stderr,
+					"Warning: No VPD for white label.\n");
+			} else {
 				ERROR("Need VPD set for white label.");
 				return ++errorcnt;
 			}
-			fprintf(stderr, "Warning: No VPD for white label.\n");
 		}
 	}
-
-	errorcnt += updater_load_images(
-			cfg, arg, model->image, model->ec_image,
-			model->pd_image);
 	errorcnt += patch_image_by_model(&cfg->image, model, ar);
 	return errorcnt;
 }
diff --git a/futility/updater.h b/futility/updater.h
index 5698f9e..341a9b1 100644
--- a/futility/updater.h
+++ b/futility/updater.h
@@ -87,6 +87,7 @@
 	QUIRK_UNLOCK_ME_FOR_UPDATE,
 	QUIRK_DAISY_SNOW_DUAL_MODEL,
 	QUIRK_EVE_SMM_STORE,
+	QUIRK_ALLOW_EMPTY_WLTAG,
 	QUIRK_MAX,
 };
 
diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c
index 5480d3c..76b040c 100644
--- a/futility/updater_quirks.c
+++ b/futility/updater_quirks.c
@@ -41,6 +41,17 @@
 	{ .match = "Google_Scarlet.", .quirks = "min_platform_version=1" },
 
 	{ .match = "Google_Snow.", .quirks = "daisy_snow_dual_model" },
+
+        /* Legacy white label units. */
+        { .match = "Google_Enguarde.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Expresso.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Hana.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Jaq.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Jerry.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Mighty.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Reks.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Relm.", .quirks = "allow_empty_wltag" },
+        { .match = "Google_Wizpig.", .quirks = "allow_empty_wltag" },
 };
 
 /*
@@ -329,6 +340,12 @@
 	quirks->help = "b/70682365; preserve UEFI SMM store without "
 		       "dedicated FMAP section.";
 	quirks->apply = quirk_eve_smm_store;
+
+	quirks = &cfg->quirks[QUIRK_ALLOW_EMPTY_WLTAG];
+	quirks->name = "allow_empty_wltag";
+	quirks->help = "chromium/906962; allow devices without white label "
+		       "tags set to use default keys.";
+	quirks->apply = NULL;  /* Simple config. */
 }
 
 /*
diff --git a/tests/futility/test_update.sh b/tests/futility/test_update.sh
index 740e53c..294517d 100755
--- a/tests/futility/test_update.sh
+++ b/tests/futility/test_update.sh
@@ -337,6 +337,10 @@
 	"${LINK_BIOS}" "${A}/bios.bin" \
 	-a "${A}" --wp=0 --sys_props 0,0x10001,1,3 --mode=factory
 
+test_update "Full update (--archive, whitelabel, no VPD - quirk mode)" \
+	"${LINK_BIOS}" "${A}/bios.bin" \
+	-a "${A}" --wp=0 --sys_props 0,0x10001,1,3 --quirks=allow_empty_wltag
+
 test_update "Full update (--archive, WL, single package)" \
 	"${A}/bios.bin" "${LINK_BIOS}" \
 	-a "${A}" --wp=0 --sys_props 0,0x10001,1,3 --signature_id=WL