Home | History | Annotate | Download | only in firmware_CorruptFwBodyA
      1 # Copyright (c) 2011 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 
      7 from autotest_lib.server.cros import vboot_constants as vboot
      8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      9 from autotest_lib.server.cros.faft.firmware_test import ConnectionError
     10 
     11 
     12 class firmware_CorruptFwBodyA(FirmwareTest):
     13     """
     14     Servo based firmware body A corruption test.
     15 
     16     The expected behavior is different if the firmware preamble USE_RO_NORMAL
     17     flag is enabled. In the case USE_RO_NORMAL ON, the firmware corruption
     18     doesn't hurt the boot results since it boots the RO path directly and does
     19     not load and verify the RW firmware body. In the case USE_RO_NORMAL OFF,
     20     the RW firwmare A corruption will result booting the firmware B.
     21     """
     22     version = 1
     23 
     24     def initialize(self, host, cmdline_args, dev_mode=False):
     25         super(firmware_CorruptFwBodyA, self).initialize(host, cmdline_args)
     26         self.backup_firmware()
     27         self.switcher.setup_mode('dev' if dev_mode else 'normal')
     28         self.setup_usbkey(usbkey=False)
     29 
     30     def cleanup(self):
     31         try:
     32             self.restore_firmware()
     33         except ConnectionError:
     34             logging.error("ERROR: DUT did not come up.  Need to cleanup!")
     35         super(firmware_CorruptFwBodyA, self).cleanup()
     36 
     37     def run_once(self):
     38         if (self.faft_client.bios.get_preamble_flags('a') &
     39                 vboot.PREAMBLE_USE_RO_NORMAL):
     40             # USE_RO_NORMAL flag is ON. Firmware body corruption doesn't
     41             # hurt the booting results.
     42             logging.info('The firmware USE_RO_NORMAL flag is enabled.')
     43             logging.info("Corrupt firmware body A.")
     44             self.check_state((self.checkers.fw_tries_checker, 'A'))
     45             self.faft_client.bios.corrupt_body('a')
     46             self.switcher.mode_aware_reboot()
     47 
     48             logging.info("Still expected firmware A boot and restore.")
     49             self.check_state((self.checkers.fw_tries_checker, 'A'))
     50             self.faft_client.bios.restore_body('a')
     51         else:
     52             logging.info('The firmware USE_RO_NORMAL flag is disabled.')
     53             logging.info("Corrupt firmware body A.")
     54             self.check_state((self.checkers.fw_tries_checker, 'A'))
     55             self.faft_client.bios.corrupt_body('a')
     56             self.switcher.mode_aware_reboot()
     57 
     58             logging.info("Expected firmware B boot and restore firmware A.")
     59             self.check_state((self.checkers.fw_tries_checker, ('B', False)))
     60             self.faft_client.bios.restore_body('a')
     61             self.switcher.mode_aware_reboot()
     62 
     63             expected_slot = 'B' if self.fw_vboot2 else 'A'
     64             logging.info("Expected firmware " + expected_slot + " boot, done.")
     65             self.check_state((self.checkers.fw_tries_checker, expected_slot))
     66