Check TPM and use a factory install shim to restore for firmware update tests

After autoupdate, the firmware version will be updated in TPM. To recover, the
client needs a reboot with a facotry install shim.

BUG=chromium-os:35258
TEST=run_remote_tests.sh

Change-Id: I11afa96586b80bc8177d31042fc3bb27c9d4266f
Reviewed-on: https://gerrit.chromium.org/gerrit/35822
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
Commit-Ready: Chun-Ting Chang <ctchang@chromium.org>
Tested-by: Chun-Ting Chang <ctchang@chromium.org>
diff --git a/server/cros/faftsequence.py b/server/cros/faftsequence.py
index 80677b7..60c2ead 100644
--- a/server/cros/faftsequence.py
+++ b/server/cros/faftsequence.py
@@ -112,6 +112,8 @@
     COLD_RESET_DELAY = 0.1
     # devserver startup time
     DEVSERVER_DELAY = 10
+    # Delay of reseting TPM with factory install shim
+    RESET_TPM_WITH_INSTALL_SHIM_DELAY = 120
 
     # The developer screen timeouts fit our spec.
     DEV_SCREEN_TIMEOUT = 30
@@ -1269,6 +1271,22 @@
         self.check_lid_and_power_on()
 
 
+    def sync_and_reboot_with_factory_install_shim(self):
+        """Request the client sync and do a warm reboot to recovery mode.
+
+        After reboot, the client will use factory install shim to reset TPM
+        values. The client ignore TPM rollback, so here forces it to recovery
+        mode.
+        """
+        is_dev = self.crossystem_checker({'devsw_boot': '1'})
+        if not is_dev:
+            self.enable_dev_mode_and_reboot()
+        time.sleep(self.SYNC_DELAY)
+        self.enable_rec_mode_and_reboot()
+        time.sleep(self.RESET_TPM_WITH_INSTALL_SHIM_DELAY)
+        self.warm_reboot()
+
+
     def full_power_off_and_on(self):
         """Shutdown the device by pressing power button and power on again."""
         # Press power button to trigger Chrome OS normal shutdown process.