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 5import logging 6 7from autotest_lib.server.cros import vboot_constants as vboot 8from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 9 10 11class firmware_RollbackFirmware(FirmwareTest): 12 """ 13 Servo based firmware rollback 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 rollbacks 17 firmware A and results firmware B boot. It then rollbacks firmware B and 18 results recovery boot. 19 """ 20 version = 1 21 22 def initialize(self, host, cmdline_args, dev_mode=False): 23 super(firmware_RollbackFirmware, self).initialize(host, cmdline_args) 24 self.backup_firmware() 25 self.switcher.setup_mode('dev' if dev_mode else 'normal') 26 self.setup_usbkey(usbkey=True, host=False) 27 28 def cleanup(self): 29 self.restore_firmware() 30 super(firmware_RollbackFirmware, self).cleanup() 31 32 def run_once(self, dev_mode=False): 33 logging.info("Rollback firmware A.") 34 self.check_state((self.checkers.fw_tries_checker, 'A')) 35 self.faft_client.bios.move_version_backward('a') 36 self.switcher.mode_aware_reboot() 37 38 logging.info("Expected firmware B boot and rollback firmware B.") 39 self.check_state((self.checkers.fw_tries_checker, ('B', False))) 40 self.faft_client.bios.move_version_backward('b') 41 self.switcher.simple_reboot() 42 if not dev_mode: 43 self.switcher.bypass_rec_mode() 44 self.switcher.wait_for_client() 45 46 logging.info("Expected recovery boot and restores firmware A and B.") 47 self.check_state((self.checkers.crossystem_checker, { 48 'mainfw_type': 'recovery', 49 'recovery_reason': ( 50 vboot.RECOVERY_REASON['RO_INVALID_RW'], 51 vboot.RECOVERY_REASON['RW_FW_ROLLBACK']), 52 })) 53 self.faft_client.bios.move_version_forward(('a', 'b')) 54 self.switcher.mode_aware_reboot() 55 56 expected_slot = 'B' if self.fw_vboot2 else 'A' 57 logging.info("Expected firmware " + expected_slot + " boot, done.") 58 self.check_state((self.checkers.fw_tries_checker, expected_slot)) 59