faft: Backup the original firmware before re-flashing the firmware

If the arguments 'image' and 'firmware_update' are specified, we will
reimage the OS and reflash the firmware before running a test. Sometime the
reflash may fail and leave the DUT in a broken state. We should backup
the original firmware first. The reset_client method, triggered by reboot
timeout, would restore it to the original firmware.

BUG=chromium-os:23309
TEST=manual, run the following test which reflashes the firmware:
$ run_remote_tests.sh --board link --remote dut -a \
      "image=/path/to/chromiumos_test_image.bin firmware_update=True" \
      TryFwB/control$

Change-Id: Iaf36f6b3b5e79b951cf8650d1d2f0f4937901464
Reviewed-on: https://gerrit.chromium.org/gerrit/36654
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Tom Wai-Hong Tam <waihong@chromium.org>
Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
diff --git a/server/cros/faftsequence.py b/server/cros/faftsequence.py
index 73dfd33..e3be601 100644
--- a/server/cros/faftsequence.py
+++ b/server/cros/faftsequence.py
@@ -456,6 +456,7 @@
         install_cmd = 'chromeos-install --yes'
         if firmware_update:
             install_cmd += ' && chromeos-firmwareupdate --mode recovery'
+            self.backup_firmware()
 
         self.register_faft_sequence((
             {   # Step 1, request recovery boot
@@ -483,6 +484,10 @@
             },
         ))
         self.run_faft_sequence()
+
+        if firmware_update:
+            self.clear_saved_firmware()
+
         # 'Unplug' any USB keys in the servo from the dut.
         self.servo.enable_usb_hub(host=True)
         # Mark usb_check done so it won't check a test image in USB anymore.
@@ -1540,6 +1545,11 @@
         return self._backup_firmware_sha != ()
 
 
+    def clear_saved_firmware(self):
+        """Clear the firmware saved by the method backup_firmware."""
+        self._backup_firmware_sha = ()
+
+
     def restore_firmware(self, suffix='.original'):
         """Restore firmware from host in resultsdir.