vboot: Add flag to indicate VbInit is run before option rom loading

This commit adds a new VbInit() flag which will indicate that it is
being called before option roms are loaded and can therefore respond
to the VbNv flag without needing an immediate reboot.

When the BIOS calls VbInit() in firmware it may not yet know if the
system is in developer mode if there is a virtual developer mode
switch, instead it relies on the VbNv flag that is prepared by VbInit().

So this new flag only affects VbInit() checks itself, the later checks
still do the right thing because OPROM_LOADED can be set based on the
VbNv value that is set by VbInit().

BUG=chrome-os-partner:32379
BRANCH=samus
TEST=pass FAFT tests on samus

Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: I7a12f3d318a04ff43ac1ddfc0ba8baa112253bad
Reviewed-on: https://chromium-review.googlesource.com/230885
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 526c1e4..8124058 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -227,6 +227,8 @@
  * can (and should) be used for additional physical presence checks.
  */
 #define VB_INIT_FLAG_VIRTUAL_REC_SWITCH  0x00001000
+/* Set when we are calling VbInit() before loading Option ROMs */
+#define VB_INIT_FLAG_BEFORE_OPROM_LOAD   0x00002000
 
 /*
  * Output flags for VbInitParams.out_flags.  Used to indicate potential boot
diff --git a/firmware/lib/vboot_api_init.c b/firmware/lib/vboot_api_init.c
index 38bc879..ce89715 100644
--- a/firmware/lib/vboot_api_init.c
+++ b/firmware/lib/vboot_api_init.c
@@ -301,7 +301,13 @@
 		if ((iparams->flags & VB_INIT_FLAG_OPROM_MATTERS) &&
 		    !(iparams->flags & VB_INIT_FLAG_OPROM_LOADED)) {
 			VbNvSet(&vnc, VBNV_OPROM_NEEDED, 1);
-			retval = VBERROR_VGA_OPROM_MISMATCH;
+			/*
+			 * If VbInit() is run before Option ROMs are run it
+			 * can still respond to the VbNv flag and does not
+			 * need to reboot here.
+			 */
+			if (!(iparams->flags & VB_INIT_FLAG_BEFORE_OPROM_LOAD))
+				retval = VBERROR_VGA_OPROM_MISMATCH;
 			VBDEBUG(("VbInit() needs oprom, doesn't have it\n"));
 		}
 
@@ -332,12 +338,11 @@
 		    (iparams->flags & VB_INIT_FLAG_OPROM_LOADED)) {
 			VbNvSet(&vnc, VBNV_OPROM_NEEDED, 0);
 			/*
-			 * If this is a system with slow EC update then don't
-			 * reboot immediately in case VGA option ROM is still
-			 * needed to display an update screen.  The reboot will
-			 * be requested after EC software sync is complete.
+			 * If VbInit() is run before Option ROMs are run it
+			 * can still respond to the VbNv flag and does not
+			 * need to reboot here.
 			 */
-			if (!(iparams->flags & VB_INIT_FLAG_EC_SLOW_UPDATE))
+			if (!(iparams->flags & VB_INIT_FLAG_BEFORE_OPROM_LOAD))
 				retval = VBERROR_VGA_OPROM_MISMATCH;
 			VBDEBUG(("VbInit() has oprom, doesn't need it\n"));
 		}