📄 tos-bsl.in
字号:
-p, --program Program file -v, --verify Verify by fileThe order of the above options matters! The table is ordered by normalexecution order. For the options "Epv" a file must be specified.Program flow specifiers default to "pvr" if a file is given.Don't forget to specify "e" or "eE" when programming flash!Data retreiving: -u, --upload=addr Upload a datablock (see also: -s). -s, --size=num Size of the data block do upload. (Default is 2) -x, --hex Show a hexadecimal display of the uploaded data. (Default) -b, --bin Get binary uploaded data. This can be used to redirect the output into a file.Do before exit: -g, --go=address Start programm execution at specified address. This implies option --wait. -r, --reset Reset connected MSP430. Starts application. This is a normal device reset and will start the programm that is specified in the reset vector. (see also -g) -w, --wait Wait for <ENTER> before closing serial port.If it says "NAK received" it's probably because you specified no or awrong password.""" % (sys.argv[0], VERSION))#add some arguments to a function, but don't call it yet, instead return#a wrapper object for later invocationclass curry: """create a callable with some arguments specified in advance""" def __init__(self, fun, *args, **kwargs): self.fun = fun self.pending = args[:] self.kwargs = kwargs.copy() def __call__(self, *args, **kwargs): if kwargs and self.kwargs: kw = self.kwargs.copy() kw.update(kwargs) else: kw = kwargs or self.kwargs return apply(self.fun, self.pending + args, kw) def __repr__(self): #first try if it a function try: return "curry(%s, %r, %r)" % (self.fun.func_name, self.pending, self.kwargs) except AttributeError: #fallback for callable classes return "curry(%s, %r, %r)" % (self.fun, self.pending, self.kwargs)def hexify(line, bytes, width=16): return '%04x %s%s %s' % ( line, ('%02x '*len(bytes)) % tuple(bytes), ' '* (width-len(bytes)), ('%c'*len(bytes)) % tuple(map(lambda x: (x>=32 and x<127) and x or ord('.'), bytes)) )#Main:def main(): global DEBUG import getopt filetype = None filename = None comPort = 0 #Default setting. speed = None unpatched = 0 reset = 0 wait = 0 #wait at the end goaddr = None bsl = BootStrapLoader() toinit = [] todo = [] startaddr = None size = 2 hexoutput = 1 notimeout = 0 bslrepl = None mayuseBSL = 1 forceBSL = 0 sys.stderr.write("MSP430 Bootstrap Loader Version: %s\n" % VERSION) try: opts, args = getopt.getopt(sys.argv[1:], "hc:P:wf:m:eEpvrg:UDudsxbITNB:S:V14", ["help", "comport=", "password=", "wait", "framesize=", "erasecycles=", "masserase", "erasecheck", "program", "verify", "reset", "go=", "unpatched", "debug", "upload=", "download=", "size=", "hex", "bin", "intelhex", "titext", "notimeout", "bsl=", "speed=", "bslversion", "f1x", "f4x", "invert-reset", "invert-test", "swap-reset-test", "telos-latch", "telos-i2c", "telos", "telosb", "tmote","no-BSL-download", "force-BSL-download", "slow"] ) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() elif o in ("-c", "--comport"): try: comPort = int(a) #try to convert decimal except ValueError: comPort = a #take the string and let serial driver decide elif o in ("-P", "--password"): #extract password from file bsl.passwd = Memory(a).getMemrange(0xffe0, 0xffff) elif o in ("-w", "--wait"): wait = 1 elif o in ("-f", "--framesize"): try: maxData = int(a) #try to convert decimal except ValueError: sys.stderr.write("framesize must be a valid number\n") sys.exit(2) #Make sure that conditions for maxData are met: #( >= 16 and == n*16 and <= MAX_DATA_BYTES!) if maxData > BootStrapLoader.MAX_DATA_BYTES: maxData = BootStrapLoader.MAX_DATA_BYTES elif maxData < 16: maxData = 16 bsl.maxData = maxData - (maxData % 16) sys.stderr.write( "Max. number of data bytes within one frame set to %i.\n" % maxData) elif o in ("-m", "--erasecycles"): try: meraseCycles = int(a) #try to convert decimal except ValueError: sys.stderr.write("erasecycles must be a valid number\n") sys.exit(2) #sanity check of value if meraseCycles < 1: sys.stderr.write("erasecycles must be a positive number\n") sys.exit(2) if meraseCycles > 20: sys.stderr.write("warning: erasecycles set to a large number (>20): %d\n" % meraseCycles) sys.stderr.write( "Number of mass erase cycles set to %i.\n" % meraseCycles) bsl.meraseCycles = meraseCycles elif o in ("-e", "--masserase"): toinit.append(bsl.actionMassErase) #Erase Flash elif o in ("-E", "--erasecheck"): toinit.append(bsl.actionEraseCheck) #Erase Check (by file) elif o in ("-p", "--programm"): todo.append(bsl.actionProgram) #Program file elif o in ("-v", "--verify"): todo.append(bsl.actionVerify) #Verify file elif o in ("-r", "--reset"): reset = 1 elif o in ("-g", "--go"): try: goaddr = int(a) #try to convert decimal except ValueError: try: goaddr = int(a[2:],16) #try to convert hex except ValueError: sys.stderr.write("go address must be a valid number\n") sys.exit(2) wait = 1 elif o in ("-U", "--unpatched"): unpatched = 1 elif o in ("-D", "--debug"): DEBUG = DEBUG + 1 elif o in ("-u", "--upload"): try: startaddr = int(a) #try to convert decimal except ValueError: try: startaddr = int(a,16) #try to convert hex except ValueError: sys.stderr.write("upload address must be a valid number\n") sys.exit(2) elif o in ("-s", "--size"): try: size = int(a) except ValueError: try: size = int(a,16) except ValueError: sys.stderr.write("size must be a valid number\n") sys.exit(2) elif o in ("-x", "--hex"): hexoutput = 1 elif o in ("-b", "--bin"): hexoutput = 0 elif o in ("-I", "--intelhex"): filetype = 0 elif o in ("-T", "--titext"): filetype = 1 elif o in ("-N", "--notimeout"): notimeout = 1 elif o in ("-B", "--bsl"): bslrepl = Memory() #File to program bslrepl.loadFile(a) elif o in ("-V", "--bslversion"): todo.append(bsl.actionReadBSLVersion) #load replacement BSL as first item elif o in ("-S", "--speed"): try: speed = int(a) #try to convert decimal except ValueError: sys.stderr.write("speed must be decimal number\n") sys.exit(2) elif o in ("-1", "--f1x"): bsl.cpu = F1x elif o in ("-4", "--f4x"): bsl.cpu = F4x elif o in ("--invert-reset", ): bsl.invertRST = 1 elif o in ("--invert-test", ): bsl.invertTEST = 1 elif o in ("--swap-reset-test", ): bsl.swapRSTTEST = 1 elif o in ("--telos-latch", ): bsl.telosLatch = 1 elif o in ("--telos-i2c", ): bsl.telosI2C = 1 elif o in ("--telos", ): bsl.invertRST = 1 bsl.invertTEST = 1 bsl.swapRSTTEST = 1 bsl.telosLatch = 1 elif o in ("--telosb", ): bsl.swapRSTTEST = 1 bsl.telosI2C = 1 mayuseBSL = 0 speed = 38400 elif o in ("--tmote", ): bsl.swapRSTTEST = 1 bsl.telosI2C = 1 mayuseBSL = 0 speed = 38400 elif o in ("--no-BSL-download", ): mayuseBSL = 0 elif o in ("--force-BSL-download", ): forceBSL = 1 elif o in ("--slow", ): bsl.slowmode = 1 if len(args) == 0: sys.stderr.write("Use -h for help\n") elif len(args) == 1: #a filename is given if not todo: #if there are no actions yet todo.extend([ #add some useful actions... bsl.actionProgram, bsl.actionVerify, ]) filename = args[0] else: #number of args is wrong usage() sys.exit(2) if DEBUG: #debug infos sys.stderr.write("Debug level set to %d\n" % DEBUG) sys.stderr.write("Python version: %s\n" % sys.version) #sanity check of options if notimeout and goaddr is not None and startaddr is not None: sys.stderr.write("Option --notimeout can not be used together with both --upload and --go\n") sys.exit(1) if notimeout: sys.stderr.write("Warning: option --notimeout can cause improper function in some cases!\n") bsl.timeout = 0 if goaddr and reset: sys.stderr.write("Warning: option --reset ignored as --go is specified!\n") reset = 0 if startaddr and reset: sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n") reset = 0 sys.stderr.flush() #prepare data to download bsl.data = Memory() #prepare downloaded data if filetype is not None: #if the filetype is given... if filename is None: raise ValueError("no filename but filetype specified") if filename == '-': #get data from stdin file = sys.stdin else: file = open(filename, "rb") #or from a file if filetype == 0: #select load function bsl.data.loadIHex(file) #intel hex elif filetype == 1: bsl.data.loadTIText(file) #TI's format else: raise ValueError("illegal filetype specified") else: #no filetype given... if filename == '-': #for stdin: bsl.data.loadIHex(sys.stdin) #assume intel hex elif filename: bsl.data.loadFile(filename) #autodetect otherwise if DEBUG > 3: sys.stderr.write("File: %r" % filename) bsl.comInit(comPort) #init port #initialization list if toinit: #erase and erase check if DEBUG: sys.stderr.write("Preparing device ...\n") #bsl.actionStartBSL(usepat
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -