# Confirm print "This is going to ERASE and REPROGRAM the chip. Are you sure? <y/N>: ", ans = sys.stdin.readline()[0:-1] if (ans != "y") and (ans != "Y"): print "Aborted" sys.exit(2) # Get BLE info page print "\nFlashing:" # Check for PStore pssize = dbg.getBLEPStoreSize() if pssize > 0: print " - Backing-up PS Store (%i Bytes)..." % pssize pstoreData = dbg.readCODE( 0x18000, pssize ) hexFile.set( 0x18000, pstoreData ) # Send chip erase print " - Chip erase..." try: dbg.chipErase() except Exception as e: print "ERROR: %s" % str(e) sys.exit(3) # Flash memory dbg.pauseDMA(False) print " - Flashing %i memory blocks..." % len(hexFile.memBlocks) for mb in hexFile.memBlocks:
print " Flash size : %i Kb" % dbg.chipInfo['flash'] print " SRAM size : %i Kb" % dbg.chipInfo['sram'] if dbg.chipInfo['usb']: print " USB : Yes" else: print " USB : No" # Get serial number print "\nReading %i KBytes to %s..." % (dbg.chipInfo['flash'], sys.argv[1]) hexFile = CCHEXFile(sys.argv[1]) # Read in chunks of 4Kb (for UI-update purposes) for i in range(0, int(dbg.chipInfo['flash'] / 4)): # Read CODE chunk = dbg.readCODE( i * 0x1000, 0x1000 ) # Write chunk to file hexFile.stack(chunk) # Log status print "%.0f%%..." % ( ( (i+1)*4 * 100) / dbg.chipInfo['flash'] ), sys.stdout.flush() # Save file hexFile.save() # Done print "\n\nCompleted" print ""