• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.mode_aware_reboot()
42
43        logging.info("Expected recovery boot and restores firmware A and B.")
44        self.check_state((self.checkers.crossystem_checker, {
45                           'mainfw_type': 'recovery',
46                           'recovery_reason': (
47                                vboot.RECOVERY_REASON['RO_INVALID_RW'],
48                                vboot.RECOVERY_REASON['RW_FW_ROLLBACK']),
49                           }))
50        self.faft_client.bios.move_version_forward(('a', 'b'))
51        self.switcher.mode_aware_reboot()
52
53        expected_slot = 'B' if self.fw_vboot2 else 'A'
54        logging.info("Expected firmware " + expected_slot + " boot, done.")
55        self.check_state((self.checkers.fw_tries_checker, expected_slot))
56