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 8 9import logging 10 11from autotest_lib.client.common_lib import error 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 21 def stage_image_to_usb(self, host): 22 """Stage the current ChromeOS image on the USB stick connected to the 23 servo. 24 25 @param host: a CrosHost object of the machine to update. 26 """ 27 info = host.host_info_store.get() 28 if not info.build: 29 logging.warning('Failed to get build label from the DUT, skip ' 30 'staging ChromeOS image on the servo USB stick.') 31 else: 32 host.servo.image_to_servo_usb( 33 host.stage_image_for_servo(info.build)) 34 logging.debug('ChromeOS image %s is staged on the USB stick.', 35 info.build) 36 37 def get_ro_firmware_ver(self, host): 38 """Get the RO firmware version from the host.""" 39 result = host.run('crossystem ro_fwid', ignore_status=True) 40 if result.exit_status == 0: 41 # The firmware ID is something like "Google_Board.1234.56.0". 42 # Remove the prefix "Google_Board". 43 return result.stdout.split('.', 1)[1] 44 else: 45 return None 46 47 def get_rw_firmware_ver(self, host): 48 """Get the RW firmware version from the host.""" 49 result = host.run('crossystem fwid', ignore_status=True) 50 if result.exit_status == 0: 51 # The firmware ID is something like "Google_Board.1234.56.0". 52 # Remove the prefix "Google_Board". 53 return result.stdout.split('.', 1)[1] 54 else: 55 return None 56 57 def run_once(self, host, value, rw_only=False, stage_image_to_usb=False): 58 """The method called by the control file to start the test. 59 60 @param host: a CrosHost object of the machine to update. 61 @param value: the provisioning value, which is the build version 62 to which we want to provision the machine, 63 e.g. 'link-firmware/R22-2695.1.144'. 64 @param rw_only: True to only update the RW firmware. 65 @param stage_image_to_usb: True to stage the current ChromeOS image on 66 the USB stick connected to the servo. Default is False. 67 """ 68 try: 69 host.repair_servo() 70 71 # Stage the current CrOS image to servo USB stick. 72 if stage_image_to_usb: 73 self.stage_image_to_usb(host) 74 75 host.firmware_install(build=value, rw_only=rw_only) 76 except Exception as e: 77 logging.error(e) 78 raise error.TestFail(str(e)) 79 80 # Only care about the version number. 81 firmware_ver = value.rsplit('-', 1)[1] 82 if not rw_only: 83 current_ro_ver = self.get_ro_firmware_ver(host) 84 if current_ro_ver != firmware_ver: 85 raise error.TestFail('Failed to update RO, still version %s' % 86 current_ro_ver) 87 current_rw_ver = self.get_rw_firmware_ver(host) 88 if current_rw_ver != firmware_ver: 89 raise error.TestFail('Failed to update RW, still version %s' % 90 current_rw_ver) 91