def read(hex_filename): return IHex.read_file(hex_filename).areas[0]
def _doOperations(self): """Go trought all operations and try to execute them.""" if self._args.operation is None: return iop = iter(self._args.operation) self._buffer = IHex() try: while True: try: op = next(iop) time.sleep(1) except StopIteration: return 0 if op == 'BLANKCHECK': self._operations.opBlankCheck(0) elif op == 'ECHO': print(next(iop)) elif op == 'ERASE': op = next(iop) if op != 'F': raise PgmError("Expected 'F' not %s" % op) self._operations.opErase() elif op == 'LOADBUFFER': filename = next(iop) self._buffer = IHex.read_file(filename) elif op == 'PROGRAM': for start, data in self._buffer.areas.items(): self._operations.opProgram(data, start) elif op == 'MEMORY': self._operations.opMemory(next(iop)) self._addr_start = 0 self._addr_end = None elif op == 'READ': if self._addr_end is None: size = None #size = 1024 # debug only, set to None!!! else: size = self._addr_end - self._addr_start data = self._operations.opRead(self._addr_start, size) self._buffer.insert_data(self._addr_start, data) elif op == 'SAVEBUFFER': filename = next(iop) if next(iop) != '386HEX': raise PgmError("Invalid output format") self._buffer.write_file(filename) elif op == 'START': reset = next(iop) if reset == 'RESET': reset = True addr = next(iop) elif reset == 'NORESET': reset = False addr = next(iop) else: addr = reset reset = True addr = int(addr, 0) if addr != 0: raise PgmError("Only address 0 supported for START") self._operations.opStartAppl(reset) try: next(iop) except StopIteration: continue raise PgmError("START cannot be folowed by anny instruction!!!") elif op == 'VERIFY': for start, data in self._buffer.areas.items(): data_r = self._operations.opRead(start, len(data)) if data != data_r: while not data_r.startswith(data): data = data[:-1] addr = len(data) addr = addr + start raise PgmError("Verification failed at address: 0x%X" % addr) else: raise PgmError("Unknown or unsupported operation: %s" % op) except StopIteration: raise PgmError("Missing argument for cmd: %s" % cmd)
def writeihex(ser, filename): h = IHex.read_file(filename) for addr in h.areas: data = h.areas[addr] for i in xrange(len(data)/4): writemem(ser, addr + i * 4 + 0x80000000, data[i*4:i*4+4])
def _doOperations(self): """Go trought all operations and try to execute them.""" if self._args.operation is None: return iop = iter(self._args.operation) self._buffer = IHex() try: while True: try: op = next(iop) time.sleep(1) except StopIteration: return 0 if op == 'BLANKCHECK': self._operations.opBlankCheck(0) elif op == 'ECHO': print(next(iop)) elif op == 'ERASE': op = next(iop) if op != 'F': raise PgmError("Expected 'F' not %s" % op) self._operations.opErase() elif op == 'LOADBUFFER': filename = next(iop) self._buffer = IHex.read_file(filename) elif op == 'PROGRAM': for start, data in self._buffer.areas.items(): self._operations.opProgram(data, start) elif op == 'MEMORY': self._operations.opMemory(next(iop)) self._addr_start = 0 self._addr_end = None elif op == 'READ': if self._addr_end is None: size = None #size = 1024 # debug only, set to None!!! else: size = self._addr_end - self._addr_start data = self._operations.opRead(self._addr_start, size) self._buffer.insert_data(self._addr_start, data) elif op == 'SAVEBUFFER': filename = next(iop) if next(iop) != '386HEX': raise PgmError("Invalid output format") self._buffer.write_file(filename) elif op == 'START': reset = next(iop) if reset == 'RESET': reset = True addr = next(iop) elif reset == 'NORESET': reset = False addr = next(iop) else: addr = reset reset = True addr = int(addr, 0) if addr != 0: raise PgmError("Only address 0 supported for START") self._operations.opStartAppl(reset) try: next(iop) except StopIteration: continue raise PgmError( "START cannot be folowed by anny instruction!!!") elif op == 'VERIFY': for start, data in self._buffer.areas.items(): data_r = self._operations.opRead(start, len(data)) if data != data_r: while not data_r.startswith(data): data = data[:-1] addr = len(data) addr = addr + start raise PgmError( "Verification failed at address: 0x%X" % addr) else: raise PgmError("Unknown or unsupported operation: %s" % op) except StopIteration: raise PgmError("Missing argument for cmd: %s" % cmd)