ec_sync: always call VbExUpdateAuxFw

call VbExUpdateAuxFw() uncontidionally, instead of when we know we
need to do an update.  Vb*AuxFw() already maintains state, so this
doesn't change when we (attempt) to update firmware.

however, this does allow us to iterate over all firmware drivers to
call their .protect() method.  previously, we would only call
.protect() after an actual firmware update.

updated unit tests to match the new logic.

BRANCH=none
BUG=b:35585700
TEST=verified i2c tunnels are protected on reef using
	ectool i2cprotect N status.

Signed-off-by: Caveh Jalali <caveh@google.com>
Reviewed-on: https://chromium-review.googlesource.com/620281
Reviewed-by: Julius Werner <jwerner@chromium.org>

(cherry picked from commit 5afa7faf7bfc4ec5efd22af5f2124a575bc64e52)

Change-Id: I9f660330002d855fdb470ed243da2be7538593ae
Reviewed-on: https://chromium-review.googlesource.com/627028
Reviewed-by: Caveh Jalali <caveh@google.com>
Commit-Queue: Caveh Jalali <caveh@google.com>
Tested-by: Caveh Jalali <caveh@google.com>
diff --git a/firmware/lib/ec_sync_all.c b/firmware/lib/ec_sync_all.c
index 43c2bb5..8e2d9a6 100644
--- a/firmware/lib/ec_sync_all.c
+++ b/firmware/lib/ec_sync_all.c
@@ -71,11 +71,9 @@
 	/*
 	 * Do software sync for devices tunneled throught the EC.
 	 */
-	if (fw_update != VB_AUX_FW_NO_UPDATE) {
-		rv = VbExUpdateAuxFw();
-		if (rv)
-			return rv;
-	}
+	rv = VbExUpdateAuxFw();
+	if (rv)
+		return rv;
 
 	/*
 	 * Reboot to unload VGA Option ROM if:
diff --git a/tests/ec_sync_tests.c b/tests/ec_sync_tests.c
index 66ea1ca..dc708c1 100644
--- a/tests/ec_sync_tests.c
+++ b/tests/ec_sync_tests.c
@@ -61,7 +61,9 @@
 static uint32_t screens_count = 0;
 
 static int ec_aux_fw_update_req;
+static VbAuxFwUpdateSeverity_t ec_aux_fw_mock_severity;
 static VbAuxFwUpdateSeverity_t ec_aux_fw_update_severity;
+static int ec_aux_fw_protected;
 
 /* Reset mock data (for use before each test) */
 static void ResetMocks(void)
@@ -121,8 +123,10 @@
 	memset(screens_displayed, 0, sizeof(screens_displayed));
 	screens_count = 0;
 
+	ec_aux_fw_mock_severity = VB_AUX_FW_NO_UPDATE;
 	ec_aux_fw_update_severity = VB_AUX_FW_NO_UPDATE;
 	ec_aux_fw_update_req = 0;
+	ec_aux_fw_protected = 0;
 }
 
 /* Mock functions */
@@ -221,13 +225,15 @@
 
 VbError_t VbExCheckAuxFw(VbAuxFwUpdateSeverity_t *severity)
 {
-	*severity = ec_aux_fw_update_severity;
+	*severity = ec_aux_fw_mock_severity;
+	ec_aux_fw_update_severity = ec_aux_fw_mock_severity;
 	return VBERROR_SUCCESS;
 }
 
 VbError_t VbExUpdateAuxFw()
 {
-	ec_aux_fw_update_req = 1;
+	ec_aux_fw_update_req = ec_aux_fw_update_severity != VB_AUX_FW_NO_UPDATE;
+	ec_aux_fw_protected = 1;
 	return VBERROR_SUCCESS;
 }
 
@@ -419,41 +425,46 @@
 
 	ResetMocks();
 	cparams.gbb->flags |= GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC;
-	ec_aux_fw_update_severity = VB_AUX_FW_FAST_UPDATE;
+	ec_aux_fw_mock_severity = VB_AUX_FW_FAST_UPDATE;
 	test_ssync(VBERROR_SUCCESS, 0,
 		   "GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC"
 		   " disables auxiliary FW update request");
 	TEST_EQ(ec_aux_fw_update_req, 0, "  aux fw update disabled");
+	TEST_EQ(ec_aux_fw_protected, 1, "  aux fw protected");
 
 	ResetMocks();
 	cparams.gbb->flags |= GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC;
-	ec_aux_fw_update_severity = VB_AUX_FW_FAST_UPDATE;
+	ec_aux_fw_mock_severity = VB_AUX_FW_FAST_UPDATE;
 	test_ssync(VBERROR_SUCCESS, 0,
 		   "GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC"
 		   " disables auxiliary FW update request");
 	TEST_EQ(ec_aux_fw_update_req, 0, "  aux fw update disabled");
+	TEST_EQ(ec_aux_fw_protected, 1, "  aux fw protected");
 
 	ResetMocks();
-	ec_aux_fw_update_severity = VB_AUX_FW_NO_UPDATE;
+	ec_aux_fw_mock_severity = VB_AUX_FW_NO_UPDATE;
 	test_ssync(VBERROR_SUCCESS, 0,
 		   "No auxiliary FW update needed");
 	TEST_EQ(screens_count, 0,
 		"  wait screen skipped");
 	TEST_EQ(ec_aux_fw_update_req, 0, "  no aux fw update requested");
+	TEST_EQ(ec_aux_fw_protected, 1, "  aux fw protected");
 
 	ResetMocks();
-	ec_aux_fw_update_severity = VB_AUX_FW_FAST_UPDATE;
+	ec_aux_fw_mock_severity = VB_AUX_FW_FAST_UPDATE;
 	test_ssync(VBERROR_SUCCESS, 0,
 		   "Fast auxiliary FW update needed");
 	TEST_EQ(screens_count, 0,
 		"  wait screen skipped");
 	TEST_EQ(ec_aux_fw_update_req, 1, "  aux fw update requested");
+	TEST_EQ(ec_aux_fw_protected, 1, "  aux fw protected");
 
 	ResetMocks();
-	ec_aux_fw_update_severity = VB_AUX_FW_SLOW_UPDATE;
+	ec_aux_fw_mock_severity = VB_AUX_FW_SLOW_UPDATE;
 	test_ssync(VBERROR_SUCCESS, 0,
 		   "Slow auxiliary FW update needed");
 	TEST_EQ(ec_aux_fw_update_req, 1, "  aux fw update requested");
+	TEST_EQ(ec_aux_fw_protected, 1, "  aux fw protected");
 	TEST_EQ(screens_displayed[0], VB_SCREEN_WAIT,
 		"  wait screen forced");
 }