Home | History | Annotate | Download | only in firmware_UpdateFirmwareVersion
      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 
      5 import logging
      6 from autotest_lib.server import utils
      7 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      8 from autotest_lib.client.common_lib import error
      9 
     10 
     11 class firmware_UpdateFirmwareVersion(FirmwareTest):
     12     """
     13     Servo based firmware update test which checks the firmware version.
     14 
     15     This test requires a USB test image plugged in. The firmware id of
     16     the current running firmware must matches the system shellball's, or user
     17     can provide a shellball to do this test. In this way, the client will be
     18     update with the given shellball first. On runtime, this test modifies the
     19     firmware version of the shellball and runs autoupdate. Check firmware
     20     version after boot with firmware B, and then recover firmware A and B to
     21     original shellball.
     22     """
     23     version = 1
     24 
     25     def check_firmware_version(self, expected_ver):
     26         actual_ver = self.faft_client.bios.get_version(
     27                 'b' if self.fw_vboot2 else 'a')
     28         actual_tpm_fwver = self.faft_client.tpm.get_firmware_version()
     29         if actual_ver != expected_ver or actual_tpm_fwver != expected_ver:
     30             raise error.TestFail(
     31                 'Firmware version should be %s,'
     32                 'but got (fwver, tpm_fwver) = (%s, %s).' %
     33                 (expected_ver, actual_ver, actual_tpm_fwver))
     34         else:
     35             logging.info(
     36                 'Update success, now version is %s',
     37                 actual_ver)
     38 
     39     def initialize(self, host, cmdline_args):
     40         dict_args = utils.args_to_dict(cmdline_args)
     41         shellball_path = dict_args.get('shellball', None)
     42         super(firmware_UpdateFirmwareVersion, self).initialize(
     43             host, cmdline_args)
     44         self.switcher.setup_mode('normal')
     45         self.backup_firmware()
     46         self.setup_firmwareupdate_shellball(shellball_path)
     47 
     48         # Update firmware if needed
     49         if shellball_path:
     50             self.set_hardware_write_protect(enable=False)
     51             self.faft_client.updater.run_factory_install()
     52             self.switcher.mode_aware_reboot()
     53 
     54         self.setup_usbkey(usbkey=True)
     55 
     56         self._fwid = self.faft_client.updater.get_fwid()
     57 
     58         actual_ver = self.faft_client.bios.get_version('a')
     59         logging.info('Origin version is %s', actual_ver)
     60         self._update_version = actual_ver + 1
     61         logging.info('Firmware version will update to version %s',
     62                      self._update_version)
     63 
     64         self.faft_client.updater.resign_firmware(self._update_version)
     65         self.faft_client.updater.repack_shellball('test')
     66 
     67     def cleanup(self):
     68         try:
     69             self.faft_client.updater.cleanup()
     70             self.restore_firmware()
     71             self.invalidate_firmware_setup()
     72         except Exception as e:
     73             logging.error("Caught exception: %s", str(e))
     74         super(firmware_UpdateFirmwareVersion, self).cleanup()
     75 
     76     def run_once(self):
     77         logging.info("Update firmware with new version.")
     78         self.check_state((self.checkers.crossystem_checker, {
     79                           'fwid': self._fwid
     80                           }))
     81         self.check_state((self.checkers.fw_tries_checker, 'A'))
     82         self.faft_client.updater.run_autoupdate('test')
     83         self.switcher.mode_aware_reboot()
     84 
     85         logging.info("Copy firmware form B to A.")
     86         self.faft_client.updater.run_bootok('test')
     87         self.check_state((self.checkers.fw_tries_checker, 'B'))
     88         self.switcher.mode_aware_reboot()
     89 
     90         logging.info("Check firmware and TPM version, then recovery.")
     91         self.check_state((self.checkers.fw_tries_checker,
     92                           'B' if self.fw_vboot2 else 'A'))
     93         self.check_firmware_version(self._update_version)
     94         self.faft_client.updater.run_recovery()
     95         self.reboot_and_reset_tpm()
     96 
     97         logging.info("Check Rollback version.")
     98         self.check_state((self.checkers.crossystem_checker, {
     99                           'fwid': self._fwid
    100                           }))
    101         self.check_state((self.checkers.fw_tries_checker,
    102                           'B' if self.fw_vboot2 else 'A'))
    103         self.check_firmware_version(self._update_version - 1)
    104