def set_firmware_region_pointer(self, chip_id, region_name): ''' USBC001001 TPS6598x chip reboot with firmware in region0 or region1. Args: chip_id: string, ["XA", "XB"]. region_name: string, ['region0', 'region1'], in TI's definition, TPS6598x firmware have two regions and save in different flash memory. Returns: None. Raise: Usbc001001Exception, register write fail. Examples: usbc001001.set_firmware_region_pointer('XA', region1')\r\n ''' assert chip_id in USBC001001Def.USBC_ID assert region_name in [ USBC001001Def.REGION0_NAME, USBC001001Def.REGION1_NAME ] if region_name == USBC001001Def.REGION0_NAME: new_pointer = REGION0.APP_START_ADDR else: new_pointer = REGION1.APP_START_ADDR header_addr = REGION0.HEADER_ADDR # change write start address if 'Success' != hi_functions.FLem(self.tps6598x[chip_id], header_addr, 1): raise Usbc001001Exception("change write start address fail") # write new pointer twice if 'Success' != hi_functions.FLad(self.tps6598x[chip_id], header_addr): raise Usbc001001Exception("FLad function write new pointer fail") if 'Success' != hi_functions.FLwd(self.tps6598x[chip_id], self._int_2_byte_array(new_pointer)): raise Usbc001001Exception("FLwd function write new pointer fail") if 'Success' != hi_functions.FLad(self.tps6598x[chip_id], header_addr): raise Usbc001001Exception("FLad function write new pointer fail") if 'Success' != hi_functions.FLwd(self.tps6598x[chip_id], self._int_2_byte_array(new_pointer)): raise Usbc001001Exception("FLwd function write new pointer fail") # set app offset with 0, in address=hearder_addr + 0x1000 - 4 if 'Success' != hi_functions.FLad( self.tps6598x[chip_id], header_addr + USBC001001Def.HEADER_OFFSET): raise Usbc001001Exception("FLad function set app offset fail") if 'Success' != hi_functions.FLwd( self.tps6598x[chip_id], USBC001001Def.FLWD_OFFSET_CONFIG_ARRAY): raise Usbc001001Exception("FLwd function set app offset fail") # reset self._GAID(chip_id)
def _flash_write(self, chip_id, region, file_name): with open(file_name, 'rb') as fd: file_size = os.path.getsize(file_name) file_data = fd.read(USBC001001Def.FLASH_WRITE_PAGE_SIZE) write_addr = region.APP_START_ADDR while file_data: if 'Success' != hi_functions.FLad(self.tps6598x[chip_id], write_addr): raise Usbc001001Exception( "FLad function gets wrong when doing flash writing") if 'Success' != hi_functions.FLwd(self.tps6598x[chip_id], array('B', file_data)): raise Usbc001001Exception( "FLwd function gets wrong when doing flash writing") write_addr += len(file_data) file_data = fd.read(USBC001001Def.FLASH_WRITE_PAGE_SIZE) # Progress information printing if 0 == ((write_addr - region.APP_START_ADDR) % USBC001001Def.FIRMWARE_DIV_SIZE): print('Flash written: %d %%' % (USBC001001Def.FLOAT_TO_PERCENT * (write_addr - region.APP_START_ADDR) / file_size)) # updata header if 'Success' != hi_functions.FLem(self.tps6598x[chip_id], region.HEADER_ADDR, 1): raise Usbc001001Exception("FLem function checks header wrong") if 'Success' != hi_functions.FLad(self.tps6598x[chip_id], region.HEADER_ADDR): raise Usbc001001Exception("FLad function checks header wrong") if 'Success' != hi_functions.FLwd( self.tps6598x[chip_id], self._int_2_byte_array(region.APP_START_ADDR)): raise Usbc001001Exception("FLwd function checks header wrong") # write again for insurance if 'Success' != hi_functions.FLad(self.tps6598x[chip_id], region.HEADER_ADDR): raise Usbc001001Exception("FLad function checks header wrong") if 'Success' != hi_functions.FLwd( self.tps6598x[chip_id], self._int_2_byte_array(region.APP_START_ADDR)): raise Usbc001001Exception("FLwd function checks header wrong") # set app offset with 0, in address=hearder_addr + 0x1000 - 4 if 'Success' != hi_functions.FLad( self.tps6598x[chip_id], region.HEADER_ADDR + USBC001001Def.HEADER_OFFSET): raise Usbc001001Exception("FLad sets offset fail") if 'Success' != hi_functions.FLwd( self.tps6598x[chip_id], USBC001001Def.FLWD_OFFSET_CONFIG_ARRAY): raise Usbc001001Exception("FLwd sets offset fail")
def set_firmware_region_pointer(self, region_name): ''' VDM001002 board TPS6598x chip reboot with firmware in region0 or region1. Args: region_name: string, ['region0', 'region1'], in TI's definition, TPS6598x firmware have two regions and save in different flash memory. Returns: None. Raise: VDM001002Exception, register write fail. Examples: vdm.set_firmware_region_pointer('region1')\r\n ''' assert region_name in [ VDM001002Def.REGION0_NAME, VDM001002Def.REGION1_NAME ] if region_name == VDM001002Def.REGION0_NAME: new_pointer = REGION0.APP_START_ADDR else: new_pointer = REGION1.APP_START_ADDR header_addr = REGION0.HEADER_ADDR # change write start address if 'Success' != hi_functions.FLem(self.tps6598x, header_addr, 1): raise VDM001002Exception("change write start address fail") # write new pointer twice if 'Success' != hi_functions.FLad(self.tps6598x, header_addr): raise VDM001002Exception("FLad function write new pointer fail") if 'Success' != hi_functions.FLwd(self.tps6598x, self._int_2_byte_array(new_pointer)): raise VDM001002Exception("FLwd function write new pointer fail") if 'Success' != hi_functions.FLad(self.tps6598x, header_addr): raise VDM001002Exception("FLad function write new pointer fail") if 'Success' != hi_functions.FLwd(self.tps6598x, self._int_2_byte_array(new_pointer)): raise VDM001002Exception("FLwd function write new pointer fail") # set app offset with 0, in address=hearder_addr + 0x1000 - 4 if 'Success' != hi_functions.FLad( self.tps6598x, header_addr + VDM001002Def.HEADER_OFFSET): raise VDM001002Exception("FLad function set app offset fail") if 'Success' != hi_functions.FLwd( self.tps6598x, VDM001002Def.FLWD_OFFSET_CONFIG_ARRAY): raise VDM001002Exception("FLwd function set app offset fail") # reset self._GAID()
def _flash_erase(self, region): if 'Success' != hi_functions.FLem(self.tps6598x, region.APP_START_ADDR, VDM001002Def.APP_SECTOR_SIZE): raise VDM001002Exception("flash erase fail.") print("Falsh erase")
def _flash_erase(self, chip_id, region): if 'Success' != hi_functions.FLem(self.tps6598x[chip_id], region.APP_START_ADDR, USBC001001Def.APP_SECTOR_SIZE): raise Usbc001001Exception("flash erase fail.") print("Falsh erase")