def cmd_verify(self, ui, args): """verify memory against file""" x = util.file_mem_args(ui, args, self.cpu.device) if x is None: return (name, adr, size) = x # check the file filesize = util.file_arg(ui, name) if filesize is None: return # round up the filesize - the io object will return 0xff for any bytes beyond EOF filesize = util.roundup(filesize, 32) if size is None: # no length on the command line - verify the filesize size = filesize if size > filesize: # region is larger than file - just verify the filesize size = filesize # adjust the address and length adr = util.align(adr, 32) n = util.nbytes_to_nwords(size, 32) # read memory, verify against file object mf = iobuf.verify_file(ui, 'verify %s (%d bytes):' % (name, n * 4), name, n * 4) self.cpu.rdmem32(adr, n, mf) mf.close()
def cmd_write(self, ui,args): """write to flash""" x = util.file_mem_args(ui, args, self.device) if x is None: return (name, adr, n) = x # check the file filesize = util.file_arg(ui, name) if filesize is None: return # round up the filesize - the io object will return 0xff for any bytes beyond EOF filesize = util.roundup(filesize, 32) if n is None: # no length on the command line - program the filesize n = filesize if n >= filesize: # region is bigger than the file - program the filesize n = filesize else: # region is smaller than the file - truncate the file ui.put('%s is larger than target memory: %d > %d bytes (truncating)\n' % (name, filesize, n)) # make sure the target region in flash is suitable mr = mem.region(None, adr, n) msg = self.driver.check_region(mr) if msg is not None: ui.put('%s\n' % msg) return # read from file, write to memory mf = iobuf.read_file(ui, 'writing %s (%d bytes):' % (name, n), name, n) self.driver.write(mr, mf) mf.close(rate = True)
def cmd_program(self, ui, args): """program firmware file to flash""" if util.wrong_argc(ui, args, (1,)): return None x = util.file_arg(ui, args[0]) if x is None: return # erase all self.cmd_erase(ui, ('*',)) # write to flash region_name = self.driver.firmware_region() self.cmd_write(ui, (args[0], region_name)) # verify against the file self.mem.cmd_verify(ui, (args[0], region_name))