From f69b7ef1f8b03609ad09453e484760ef7cc48b9e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 7 Jul 2013 23:23:03 +0000 Subject: basic commands work now git-svn-id: https://svn.spreadspace.org/pic/trunk@55 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- downloader/downloader.py | 81 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) (limited to 'downloader') diff --git a/downloader/downloader.py b/downloader/downloader.py index 48e6836..a07e15d 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -50,6 +50,23 @@ def load_hex(file): return codedata +def write_hex(file, codedata): + from intelhex import IntelHex + + fin = file + if fin == '-': + fin = sys.stdout + + hexdata = {} + for a in codedata: + hexdata[2*a] = codedata[a] & 0xFF + hexdata[2*a+1] = codedata[a] >> 8 + + ih = IntelHex() + ih.fromdict(hexdata) + ih.write_hex_file(fin) + + def get_lowest_flash_addr(codedata, fss): lowest_code_addr = sorted(codedata.keys())[0] return lowest_code_addr - (lowest_code_addr%fss) @@ -74,7 +91,7 @@ def create_flash_segments(codedata, fs, fss): img = create_flash_image(codedata, fss, sa, ea) for i in xrange(0, ea, fss): - slice = img[1][i:i+fss] + slice = tuple(img[1][i:i+fss]) if not all( (elem == 0xFFFF) for elem in slice): yield (i, slice) @@ -160,7 +177,7 @@ def exec_command(dev, cmd, param, answer): return struct.unpack_from(answer, astr, 3) -### Commands +### low level commands def identify(dev, name): data = exec_command(dev, 1, '', ' 1: raise getopt.GetoptError('Too many arguments') + if not cmd: + raise getopt.GetoptError('You have to supply a command (read,write,verify)') + except getopt.GetoptError, msg: print "ERROR: %s" % msg print usage sys.exit(2) dev = open_serial(device, baudrate) - codedata = load_hex(args[0]) - id = identify(dev, name) - for segment in create_flash_segments(codedata, id['fs'], id['fss']): - print "%05X: %s" % (segment[0], ''.join('%04X'%i for i in segment[1])) + try: + commands[cmd](dev, id, args[0]) + except KeyError: + print "ERROR: unkown command '%s'" % cmd -- cgit v1.2.3