Home | History | Annotate | Download | only in firmware_SoftwareSync
      1 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging
      6 import time
      7 
      8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      9 from autotest_lib.server.cros import vboot_constants as vboot
     10 
     11 
     12 class firmware_SoftwareSync(FirmwareTest):
     13     """
     14     Servo based EC software sync test.
     15     """
     16     version = 1
     17 
     18     def initialize(self, host, cmdline_args, dev_mode=False):
     19         # This test tries to corrupt EC firmware. Should disable EC WP.
     20         super(firmware_SoftwareSync, self).initialize(host, cmdline_args,
     21                                                       ec_wp=False)
     22         # In order to test software sync, it must be enabled.
     23         self.clear_set_gbb_flags(vboot.GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC, 0)
     24         self.backup_firmware()
     25         self.switcher.setup_mode('dev' if dev_mode else 'normal')
     26         self.setup_usbkey(usbkey=False)
     27         self.setup_rw_boot()
     28         self.dev_mode = dev_mode
     29 
     30     def cleanup(self):
     31         self.restore_firmware()
     32         super(firmware_SoftwareSync, self).cleanup()
     33 
     34     def record_hash_and_corrupt(self):
     35         """Record current EC hash and corrupt EC firmware."""
     36         self._ec_hash = self.faft_client.ec.get_firmware_sha()
     37         logging.info("Stored EC hash: %s", self._ec_hash)
     38         self.faft_client.ec.corrupt_body('rw')
     39 
     40     def software_sync_checker(self):
     41         """Check EC firmware is restored by software sync."""
     42         ec_hash = self.faft_client.ec.get_firmware_sha()
     43         logging.info("Current EC hash: %s", self._ec_hash)
     44         if self._ec_hash != ec_hash:
     45             return False
     46         return self.checkers.ec_act_copy_checker('RW')
     47 
     48     def wait_software_sync_and_boot(self):
     49         """Wait for software sync to update EC."""
     50         if self.dev_mode:
     51             time.sleep(self.faft_config.software_sync_update +
     52                        self.faft_config.firmware_screen)
     53             self.servo.ctrl_d()
     54         else:
     55             time.sleep(self.faft_config.software_sync_update)
     56 
     57     def run_once(self):
     58         logging.info("Corrupt EC firmware RW body.")
     59         self.check_state((self.checkers.ec_act_copy_checker, 'RW'))
     60         self.record_hash_and_corrupt()
     61         self.sync_and_ec_reboot()
     62         self.wait_software_sync_and_boot()
     63         self.switcher.wait_for_client()
     64 
     65         logging.info("Expect EC in RW and RW is restored.")
     66         self.check_state(self.software_sync_checker)
     67