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 self.restore_firmware() 31 super(firmware_CorruptBothFwSigAB, self).cleanup() 32 33 def run_once(self, dev_mode=False): 34 logging.info("Corrupt both firmware signature A and B.") 35 self.check_state((self.checkers.crossystem_checker, { 36 'mainfw_type': 'developer' if dev_mode else 'normal', 37 })) 38 self.faft_client.bios.corrupt_sig(('a', 'b'),) 39 self.switcher.simple_reboot() 40 if not dev_mode: 41 self.switcher.bypass_rec_mode() 42 self.switcher.wait_for_client() 43 44 logging.info("Expected recovery boot and set fwb_tries flag.") 45 self.check_state((self.checkers.crossystem_checker, { 46 'mainfw_type': 'recovery', 47 'recovery_reason': ( 48 vboot.RECOVERY_REASON['RO_INVALID_RW'], 49 vboot.RECOVERY_REASON['RW_VERIFY_KEYBLOCK']), 50 })) 51 self.faft_client.system.set_try_fw_b() 52 self.switcher.simple_reboot() 53 if not dev_mode: 54 self.switcher.bypass_rec_mode() 55 self.switcher.wait_for_client() 56 57 logging.info("Still expected recovery boot and restore firmware.") 58 self.check_state((self.checkers.crossystem_checker, { 59 'mainfw_type': 'recovery', 60 'recovery_reason': ( 61 vboot.RECOVERY_REASON['RO_INVALID_RW'], 62 vboot.RECOVERY_REASON['RW_VERIFY_KEYBLOCK']), 63 })) 64 self.faft_client.bios.restore_sig(('a', 'b'),) 65 self.switcher.mode_aware_reboot() 66 67 logging.info("Expected normal boot, done.") 68 self.check_state((self.checkers.crossystem_checker, { 69 'mainfw_type': 'developer' if dev_mode else 'normal', 70 })) 71