def reset_state(self, image_type): """Update to the image and erase the board id. We can't erase the board id unless we are running a debug image. Update to the debug image so we can erase the board id and then rollback to the right image. Args: image_type: the name of the image we want to be running at the end of reset_state: 'universal' or 'board_id_locked'. This image name needs to correspond with some test attribute ${image_type}_path Raises: TestFail if the board id was not erased """ _, rw_ver, bid = self.image_versions[image_type] chip_bid = cr50_utils.GetChipBoardId(self.host) if self.is_running_version(rw_ver, bid) and (chip_bid == cr50_utils.ERASED_CHIP_BID): logging.info('Skipping reset. Already running %s image with erased ' 'chip board id', image_type) return logging.info('Updating to %s image and erasing chip bid', image_type) self.cr50_update(self.dev_path) # Rolling back will take care of erasing the board id self.cr50_update(getattr(self, image_type + '_path'), rollback=True) # Verify the board id was erased if cr50_utils.GetChipBoardId(self.host) != cr50_utils.ERASED_CHIP_BID: raise error.TestFail('Could not erase bid')
def initialize(self, host, cmdline_args, full_args): """Initialize servo and download images""" super(firmware_Cr50RejectUpdate, self).initialize(host, cmdline_args, full_args, restore_cr50_state=True) if not hasattr(self, 'cr50'): raise error.TestNAError('Test can only be run on devices with ' 'access to the Cr50 console') if 'DBG' in self.cr50.get_version(): raise error.TestNAError('Update rules are wonky on DBG images') if cr50_utils.GetChipBoardId(host) == cr50_utils.ERASED_CHIP_BID: raise error.TestNAError('Set Cr50 board id to run test') self.bid_path = self.download_cr50_debug_image(self.IMAGE_DEVID, self.BID)[0] self.old_path = self.download_cr50_release_image(self.OLD_IMAGE_VER)[0] self.original_path = self.get_saved_cr50_original_path() self.host = host # Wait until cr50 can accept an update, so cr50 update rate limiting # won't interfere with the test. self.cr50.wait_until_update_is_allowed()
def get_cr50_device_state(self): """Get a dict with the current device cr50 information. The state dict will include the platform brand, rlz code, chip board id, the running cr50 image version, the running cr50 image board id, and the device cr50 image version. """ state = {} state['mosys platform brand'] = self.host.run( 'mosys platform brand', ignore_status=True).stdout.strip() state['device_prod_ver'] = cr50_utils.GetBinVersion( self.host, cr50_utils.CR50_PROD) state['has_prepvt'] = cr50_utils.HasPrepvtImage(self.host) if state['has_prepvt']: state['device_prepvt_ver'] = cr50_utils.GetBinVersion( self.host, cr50_utils.CR50_PREPVT) else: state['device_prepvt_ver'] = None state['rlz'] = cr50_utils.GetRLZ(self.host) state['chip_bid'] = cr50_utils.GetChipBoardId(self.host) state['chip_bid_str'] = '%08x:%08x:%08x' % state['chip_bid'] state['running_ver'] = cr50_utils.GetRunningVersion(self.host) state['cr50_image_bid'] = self.cr50.get_active_board_id_str() logging.debug('Current Cr50 state:\n%s', pprint.pformat(state)) return state
def initialize(self, host, cmdline_args, release_path="", release_ver="", old_release_path="", old_release_ver="", dev_path="", test=""): """Initialize servo and process the given images""" super(firmware_Cr50Update, self).initialize(host, cmdline_args, restore_cr50_state=True, cr50_dev_path=dev_path) if not release_ver and not os.path.isfile(release_path): raise error.TestError('Need to specify a release version or path') self.devid = self.servo.get('cr50_devid') # Make sure ccd is disabled so it won't interfere with the update self.cr50.ccd_disable() self.rootfs_verification_disable() self.host = host self.erase_nvmem = test.lower() == self.ERASE_NVMEM # A dict used to store relevant information for each image self.images = {} # Process the given images in order of oldest to newest. Get the version # info and add them to the update order self.update_order = [] if not self.erase_nvmem and (old_release_path or old_release_ver): self.add_image_to_update_order(self.OLD_RELEASE_NAME, old_release_path, old_release_ver) self.add_image_to_update_order(self.RELEASE_NAME, release_path, release_ver) self.add_image_to_update_order(self.DEV_NAME, dev_path) self.verify_update_order() logging.info("Update %s", self.update_order) self.chip_bid = None self.chip_flags = None chip_bid_info = cr50_utils.GetChipBoardId(self.host) if chip_bid_info != cr50_utils.ERASED_CHIP_BID: self.chip_bid, _, self.chip_flags = chip_bid_info logging.info('chip board id will be erased during rollback. %x:%x ' 'will be restored after rollback.', self.chip_bid, self.chip_flags) else: logging.info('No chip board id is set. This test will not attempt ' 'to restore anything during rollback.') self.device_update_path = cr50_utils.GetActiveCr50ImagePath(self.host) # Update to the dev image self.run_update(self.DEV_NAME)
def get_new_chip_bid(self): """Get the new chip board id and flags. Returns: a tuple chip bid info, a bool True if the chip board id needs to change. """ chip_bid_info = self.chip_bid_str.split(':') running_bid_info = cr50_utils.GetChipBoardId(self.host) # If no board id was specified, restore the original board id if len(chip_bid_info) != 2 or not chip_bid_info[0]: logging.info('No board id given. Using the current chip settings ' '%s', running_bid_info) return running_bid_info, False chip_bid = cr50_utils.GetIntBoardId(chip_bid_info[0]) chip_flags = int(chip_bid_info[1], 16) chip_bid_info = (chip_bid, 0xffffffff ^ chip_bid, chip_flags) set_bid = chip_bid_info != running_bid_info return chip_bid_info, set_bid
def updater_set_bid(self, bid, flags, exit_code): """Set the flags using usb_updater and verify the result Args: board_id: board id string flags: An int with the flag value exit_code: the expected error code. 0 if it should succeed Raises: TestFail if usb_updater had an unexpected exit status or setting the board id failed """ original_bid, _, original_flags = cr50_utils.GetChipBoardId(self.host) if exit_code: exit_code = 'Error %d while setting board id' % exit_code try: cr50_utils.SetChipBoardId(self.host, bid, flags) result = self.SUCCESS except error.AutoservRunError, e: result = e.result_obj.stderr.strip()