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