faft: Corrupt the active RW slot for EC EFS

There are 2 RW sections for EC EFS. Change the corruption code to
corrupt the active RW slot, instead of A, to verify the software
sync behavior.

The scenarios:
 * non-EFS: Corrupt A, software sync to A, reboot to A
 * EFS-A-boot: Corrupt A, software sync to B, reboot to B
 * EFS-B-boot: Corrupt B, software sync to A, reboot to A

BUG=b:69921268
TEST=Ran the modified firmware_SoftwareSync on both Fizz (EFS) and
Soraka (non-EFS).

Change-Id: Ibc870b8918343f03252a6b7342498ad95a96e75d
Reviewed-on: https://chromium-review.googlesource.com/817537
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index 314b10e..9410452 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -461,6 +461,11 @@
             raise
 
 
+    def get_ec_active_copy(self):
+        """Get the active copy of the EC image."""
+        return self.get('ec_active_copy')
+
+
     def _get_xmlrpclib_exception(self, xmlexc):
         """Get meaningful exception string from xmlrpc.
 
diff --git a/server/site_tests/firmware_SoftwareSync/firmware_SoftwareSync.py b/server/site_tests/firmware_SoftwareSync/firmware_SoftwareSync.py
index e67c17b..f07cfec 100644
--- a/server/site_tests/firmware_SoftwareSync/firmware_SoftwareSync.py
+++ b/server/site_tests/firmware_SoftwareSync/firmware_SoftwareSync.py
@@ -5,6 +5,7 @@
 import logging
 import time
 
+from autotest_lib.client.common_lib import error
 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
 from autotest_lib.server.cros import vboot_constants as vboot
 
@@ -34,16 +35,28 @@
             logging.error("Caught exception: %s", str(e))
         super(firmware_SoftwareSync, self).cleanup()
 
-    def record_hash_and_corrupt(self):
-        """Record current EC hash and corrupt EC firmware."""
+    def record_hash(self):
+        """Record current EC hash."""
         self._ec_hash = self.faft_client.ec.get_active_hash()
         logging.info("Stored EC hash: %s", self._ec_hash)
-        self.faft_client.ec.corrupt_body('rw')
+
+    def corrupt_active_rw(self):
+        """Corrupt the active RW portion."""
+        section = 'rw'
+        try:
+            if self.servo.get_ec_active_copy() == 'RW_B':
+                section = 'rw_b'
+        except error.TestFail:
+            # Skip the failure, as ec_active_copy is new.
+            # TODO(waihong): Remove this except clause.
+            pass
+        logging.info("Corrupt the EC section: %s", section)
+        self.faft_client.ec.corrupt_body(section)
 
     def software_sync_checker(self):
         """Check EC firmware is restored by software sync."""
         ec_hash = self.faft_client.ec.get_active_hash()
-        logging.info("Current EC hash: %s", self._ec_hash)
+        logging.info("Current EC hash: %s", ec_hash)
         if self._ec_hash != ec_hash:
             return False
         return self.checkers.ec_act_copy_checker('RW')
@@ -60,7 +73,8 @@
     def run_once(self):
         logging.info("Corrupt EC firmware RW body.")
         self.check_state((self.checkers.ec_act_copy_checker, 'RW'))
-        self.record_hash_and_corrupt()
+        self.record_hash()
+        self.corrupt_active_rw()
         logging.info("Reboot AP, check EC hash, and software sync it.")
         self.switcher.simple_reboot(reboot_type='warm')
         self.wait_software_sync_and_boot()