cr50_test: restore cr50 image before ccd state

In cleanup handle updating cr50 before restoring the ccd state.
Restoring the cr50 image involves updating to debug images. Updating to
debug images will completely reset the ccd state. cleanup wastes a lot
of time restoring ccd only to clear that state while restoring the
correct cr50 version and board id.

BUG=none
BRANCH=none
TEST=run firmware_Cr50BID

Change-Id: Ie5eec8ca79e8093b2c62e5ea8abf8c122112d97b
Reviewed-on: https://chromium-review.googlesource.com/1542123
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Kevin Shelton <kmshelton@chromium.org>
diff --git a/server/cros/faft/cr50_test.py b/server/cros/faft/cr50_test.py
index d17188e..80b8d82 100644
--- a/server/cros/faft/cr50_test.py
+++ b/server/cros/faft/cr50_test.py
@@ -416,6 +416,13 @@
 
     def _restore_cr50_state(self):
         """Restore cr50 state, so the device can be used for further testing"""
+        state_mismatch = self._check_original_state()
+        if state_mismatch and not self._provision_update:
+            self._restore_original_state()
+            if self._raise_error_on_mismatch:
+                raise error.TestError('Unexpected state mismatch during '
+                                      'cleanup %s' % state_mismatch)
+
         # Try to open cr50 and enable testlab mode if it isn't enabled.
         try:
             self.fast_open(True)
@@ -443,13 +450,6 @@
         tpm_utils.ClearTPMOwnerRequest(self.host, wait_for_ready=True)
         self.clear_fwmp()
 
-        state_mismatch = self._check_original_state()
-        if state_mismatch and not self._provision_update:
-            self._restore_original_state()
-            if self._raise_error_on_mismatch:
-                raise error.TestError('Unexpected state mismatch during '
-                                      'cleanup %s' % state_mismatch)
-
         # Restore the ccd privilege level
         if hasattr(self, 'original_ccd_level'):
             self._reset_ccd_settings()