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 import os 7 8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 9 10 11 class firmware_ShellBall(FirmwareTest): 12 """ 13 chromeos-firmwareupdate functional tests. 14 15 Checks the mode condition and enables or disables developement mode 16 accordingly and runs all shellball functioanl tests. 17 """ 18 version = 1 19 20 _shellball_name = None 21 22 def update_firmware(self, mode): 23 self.faft_client.system.run_shell_command('%s --mode %s' % 24 (self._shellball_name, mode)) 25 # Enalbe dev mode if the mode is todev. 26 if mode == 'todev': 27 self.servo.enable_development_mode() 28 # Disable dev mode if the mode is tonormal. 29 elif mode == 'tonormal': 30 self.servo.disable_development_mode() 31 32 def install_original_firmware(self): 33 self.faft_client.system.run_shell_command( 34 'sudo chromeos-firmwareupdate --mode=factory_install') 35 self.invalidate_firmware_setup() 36 37 def initialize(self, host, cmdline_args, shellball_path=None, 38 shellball_name=None): 39 super(firmware_ShellBall, self).initialize(host, cmdline_args) 40 self._shellball_name = "/home/chronos/%s" % self._shellball_name 41 host.send_file("%s/%s" % (shellball_path, shellball_name), 42 self._shellball_name) 43 self.faft_client.system.run_shell_command('chmod +x %s' % 44 self._shellball_name) 45 self.switcher.setup_mode('normal') 46 # Get crossystem fwid. 47 [self._current_fwid] = ( 48 self.faft_client.system.run_shell_command_get_output( 49 'crossystem fwid')) 50 # Get BIOS version from shellball. 51 [self._shellball_fwid] = self.faft_client. \ 52 system.run_shell_command_get_output( 53 '%s -V | grep "BIOS version"' 54 ' | sed "s/BIOS version: ' 55 '\(.*\)/\\1/" ' 56 % self._shellball_name) 57 58 def cleanup(self): 59 try: 60 if os.path.exists(self._shellball_name): 61 os.remove(self._shellball_name) 62 except Exception as e: 63 logging.error("Caught exception: %s", str(e)) 64 super(firmware_ShellBall, self).cleanup() 65 66 def run_once(self): 67 logging.info("Change to devmode.") 68 self.check_state((self.checkers.crossystem_checker, 69 {'dev_boot_usb': '0'})) 70 self.update_firmware('todev') 71 self.switcher.mode_aware_reboot() 72 73 logging.info("Check mainfw_type and run autoupdate.") 74 self.check_state((self.checkers.crossystem_checker, 75 {'mainfw_type': 'developer'})) 76 self.update_firmware('autoupdate') 77 self.switcher.mode_aware_reboot() 78 79 logging.info("Verify fwid and install system firmware.") 80 self.check_state((self.checkers.crossystem_checker, 81 {'fwid': self._shellball_fwid})) 82 self.install_original_firmware() 83 self.switcher.mode_aware_reboot() 84 85 logging.info("Verify the old firmware id and test factory_install.") 86 self.check_state((self.checkers.crossystem_checker, 87 {'fwid': self._current_fwid})) 88 self.update_firmware('factory_install') 89 self.switcher.mode_aware_reboot() 90 91 logging.info("Verify fwid and install original firmware.") 92 self.check_state((self.checkers.crossystem_checker, 93 {'fwid': self._shellball_fwid})) 94 self.install_original_firmware() 95 self.switcher.mode_aware_reboot() 96 97 logging.info("Verify old fwid.") 98 self.check_state((self.checkers.crossystem_checker, 99 {'fwid': self._current_fwid})) 100