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_CorruptBothFwBodyAB(FirmwareTest): 12 """ 13 Servo based both firmware body A and B corruption test. 14 15 The expected behavior is different if the firmware preamble USE_RO_NORMAL 16 flag is enabled. In the case USE_RO_NORMAL ON, the firmware corruption 17 doesn't hurt the boot results since it boots the RO path directly and does 18 not load and verify the RW firmware body. In the case USE_RO_NORMAL OFF, 19 the firmware verification fails on loading RW firmware and enters recovery 20 mode. In this case, it requires a USB disk plugged-in, which contains a 21 Chrome OS test image (built by "build_image --test"). 22 """ 23 version = 1 24 25 use_ro = False 26 27 def initialize(self, host, cmdline_args, dev_mode=False): 28 super(firmware_CorruptBothFwBodyAB, self).initialize(host, cmdline_args) 29 self.backup_firmware() 30 if (self.faft_client.bios.get_preamble_flags('a') & 31 vboot.PREAMBLE_USE_RO_NORMAL): 32 self.use_ro = True 33 self.switcher.setup_mode('dev' if dev_mode else 'normal') 34 else: 35 self.switcher.setup_mode('dev' if dev_mode else 'normal') 36 self.setup_usbkey(usbkey=True, host=False) 37 38 def cleanup(self): 39 try: 40 self.restore_firmware() 41 except Exception as e: 42 logging.error("Caught exception: %s", str(e)) 43 super(firmware_CorruptBothFwBodyAB, self).cleanup() 44 45 def run_once(self, dev_mode=False): 46 if self.use_ro: 47 # USE_RO_NORMAL flag is ON. Firmware body corruption doesn't 48 # hurt the booting results. 49 logging.info('The firmware USE_RO_NORMAL flag is enabled.') 50 logging.info("Corrupt both firmware body A and B.") 51 self.check_state((self.checkers.crossystem_checker, { 52 'mainfw_type': 'developer' if dev_mode else 'normal', 53 })) 54 self.faft_client.bios.corrupt_body(('a', 'b')) 55 self.switcher.mode_aware_reboot() 56 57 logging.info("Still expected normal/developer boot and restore.") 58 self.check_state((self.checkers.crossystem_checker, { 59 'mainfw_type': 'developer' if dev_mode else 'normal', 60 })) 61 self.faft_client.bios.restore_body(('a', 'b')) 62 else: 63 logging.info("Corrupt both firmware body A and B.") 64 self.check_state((self.checkers.crossystem_checker, { 65 'mainfw_type': 'developer' if dev_mode else 'normal', 66 })) 67 self.faft_client.bios.corrupt_body(('a', 'b')) 68 69 # Older devices (without BROKEN screen) didn't wait for removal in 70 # dev mode. Make sure the USB key is not plugged in so they won't 71 # start booting immediately and get interrupted by unplug/replug. 72 self.servo.switch_usbkey('host') 73 self.switcher.simple_reboot() 74 self.switcher.bypass_rec_mode() 75 self.switcher.wait_for_client() 76 77 logging.info("Expected recovery boot and restore firmware.") 78 self.check_state((self.checkers.crossystem_checker, { 79 'mainfw_type': 'recovery', 80 'recovery_reason': 81 (vboot.RECOVERY_REASON['RO_INVALID_RW'], 82 vboot.RECOVERY_REASON['RW_VERIFY_BODY']), 83 })) 84 self.faft_client.bios.restore_body(('a', 'b')) 85 self.switcher.mode_aware_reboot() 86 87 logging.info("Expected normal boot, done.") 88 self.check_state((self.checkers.crossystem_checker, { 89 'mainfw_type': 'developer' if dev_mode else 'normal', 90 })) 91