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 6""" The autotest performing FW update, both EC and AP.""" 7 8from __future__ import print_function 9 10import logging 11import sys 12 13import six 14 15from autotest_lib.client.common_lib import error 16from autotest_lib.server import test 17 18 19class provision_FirmwareUpdate(test.test): 20 """A test that can provision a machine to the correct firmware version.""" 21 22 version = 1 23 24 def stage_image_to_usb(self, host): 25 """Stage the current ChromeOS image on the USB stick connected to the 26 servo. 27 28 @param host: a CrosHost object of the machine to update. 29 """ 30 info = host.host_info_store.get() 31 if not info.build: 32 logging.warning('Failed to get build label from the DUT, skip ' 33 'staging ChromeOS image on the servo USB stick.') 34 else: 35 _, update_url = host.stage_image_for_servo(info.build) 36 host.servo.image_to_servo_usb(update_url) 37 logging.debug('ChromeOS image %s is staged on the USB stick.', 38 info.build) 39 40 def run_once(self, host, value, rw_only=False, stage_image_to_usb=False, 41 fw_path=None): 42 """The method called by the control file to start the test. 43 44 @param host: a CrosHost object of the machine to update. 45 @param value: the provisioning value, which is the build version 46 to which we want to provision the machine, 47 e.g. 'link-firmware/R22-2695.1.144'. 48 @param rw_only: True to only update the RW firmware. 49 @param stage_image_to_usb: True to stage the current ChromeOS image on 50 the USB stick connected to the servo. Default is False. 51 @param fw_path: Path to local firmware image for installing without 52 devserver. 53 54 @raise TestFail: if the firmware version remains unchanged. 55 """ 56 57 try: 58 host.repair_servo() 59 60 # Stage the current CrOS image to servo USB stick. 61 if stage_image_to_usb: 62 self.stage_image_to_usb(host) 63 64 host.firmware_install(build=value, 65 rw_only=rw_only, 66 dest=self.resultsdir, 67 local_tarball=fw_path, 68 verify_version=True, 69 try_scp=True) 70 except Exception as e: 71 logging.error(e) 72 six.reraise(error.TestFail, str(e), sys.exc_info()[2]) 73