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 10 11 class firmware_CorruptBothFwSigAB(FirmwareTest): 12 """ 13 Servo based both firmware signature A and B corruption test. 14 15 This test requires a USB disk plugged-in, which contains a Chrome OS test 16 image (built by "build_image --test"). On runtime, this test corrupts 17 both firmware signature A and B. On next reboot, the firmware verification 18 fails and enters recovery mode. This test then checks the success of the 19 recovery boot. 20 """ 21 version = 1 22 23 def initialize(self, host, cmdline_args, dev_mode=False): 24 super(firmware_CorruptBothFwSigAB, self).initialize(host, cmdline_args) 25 self.backup_firmware() 26 self.switcher.setup_mode('dev' if dev_mode else 'normal') 27 self.setup_usbkey(usbkey=True, host=False) 28 29 def cleanup(self): 30 try: 31 self.restore_firmware() 32 except Exception as e: 33 logging.error("Caught exception: %s", str(e)) 34 super(firmware_CorruptBothFwSigAB, self).cleanup() 35 36 def run_once(self, dev_mode=False): 37 logging.info("Corrupt both firmware signature A and B.") 38 self.check_state((self.checkers.crossystem_checker, { 39 'mainfw_type': 'developer' if dev_mode else 'normal', 40 })) 41 self.faft_client.bios.corrupt_sig(('a', 'b'),) 42 43 # Older devices (without BROKEN screen) didn't wait for removal in 44 # dev mode. Make sure the USB key is not plugged in so they won't 45 # start booting immediately and get interrupted by unplug/replug. 46 self.servo.switch_usbkey('host') 47 self.switcher.simple_reboot() 48 self.switcher.bypass_rec_mode() 49 self.switcher.wait_for_client() 50 51 logging.info("Expected recovery boot and set fwb_tries flag.") 52 self.check_state((self.checkers.crossystem_checker, { 53 'mainfw_type': 'recovery', 54 'recovery_reason': ( 55 vboot.RECOVERY_REASON['RO_INVALID_RW'], 56 vboot.RECOVERY_REASON['RW_VERIFY_KEYBLOCK']), 57 })) 58 self.faft_client.system.set_try_fw_b() 59 60 self.servo.switch_usbkey('host') 61 self.switcher.simple_reboot(sync_before_boot=False) 62 self.switcher.bypass_rec_mode() 63 self.switcher.wait_for_client() 64 65 logging.info("Still expected recovery boot and restore firmware.") 66 self.check_state((self.checkers.crossystem_checker, { 67 'mainfw_type': 'recovery', 68 'recovery_reason': ( 69 vboot.RECOVERY_REASON['RO_INVALID_RW'], 70 vboot.RECOVERY_REASON['RW_VERIFY_KEYBLOCK']), 71 })) 72 self.faft_client.bios.restore_sig(('a', 'b'),) 73 self.switcher.mode_aware_reboot() 74 75 logging.info("Expected normal boot, done.") 76 self.check_state((self.checkers.crossystem_checker, { 77 'mainfw_type': 'developer' if dev_mode else 'normal', 78 })) 79