Merge lp:~cdwilson/python-msp430-tools/fix-legacy-input-file-processing into lp:python-msp430-tools

Proposed by Christopher Wilson
Status: Merged
Merged at revision: 449
Proposed branch: lp:~cdwilson/python-msp430-tools/fix-legacy-input-file-processing
Merge into: lp:python-msp430-tools
Diff against target: 62 lines (+11/-8)
1 file modified
scripts/msp430-bsl-legacy.py (+11/-8)
To merge this branch: bzr merge lp:~cdwilson/python-msp430-tools/fix-legacy-input-file-processing
Reviewer Review Type Date Requested Status
zsquareplusc Approve
Review via email: mp+92147@code.launchpad.net

Description of the change

Fix for https://bugs.launchpad.net/python-msp430-tools/+bug/929137

Please merge if the fix looks good to you.

To post a comment you must log in.
450. By Christopher Wilson

Refactor legacy BSL input file processing

Revision history for this message
zsquareplusc (zsquareplusc) wrote :

OK, merged.

That legacy_memory modifies the Segment instances is not nice, but I don't feel like rewriting the code where it accesses the data as this is the old BSL implementation anyway. This at least gets the tool working again :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scripts/msp430-bsl-legacy.py'
--- scripts/msp430-bsl-legacy.py 2011-01-07 01:46:50 +0000
+++ scripts/msp430-bsl-legacy.py 2012-02-09 06:15:22 +0000
@@ -126,6 +126,11 @@
126erased before programming.126erased before programming.
127""" % (sys.argv[0], VERSION))127""" % (sys.argv[0], VERSION))
128128
129def legacy_memory(memory):
130 # msp430.legacy.bsl doesn't expect seg.data to be type bytearray
131 for segment in memory:
132 segment.data = bytes(segment.data)
133 return memory
129134
130# Main:135# Main:
131def main():136def main():
@@ -180,7 +185,7 @@
180 comPort = a # take the string and let serial driver decide185 comPort = a # take the string and let serial driver decide
181 elif o in ("-P", "--password"):186 elif o in ("-P", "--password"):
182 # extract password from file187 # extract password from file
183 bslobj.passwd = memory.Memory(a).getMemrange(0xffe0, 0xffff)188 bslobj.passwd = legacy_memory(memory.load(a)).getMemrange(0xffe0, 0xffff)
184 elif o in ("-w", "--wait"):189 elif o in ("-w", "--wait"):
185 wait = 1190 wait = 1
186 elif o in ("-f", "--framesize"):191 elif o in ("-f", "--framesize"):
@@ -302,8 +307,7 @@
302 elif o in ("-N", "--notimeout"):307 elif o in ("-N", "--notimeout"):
303 notimeout = 1308 notimeout = 1
304 elif o in ("-B", "--bsl"):309 elif o in ("-B", "--bsl"):
305 bslrepl = memory.Memory() # File to program310 bslrepl = legacy_memory(memory.load(a)) # File to program
306 bslrepl.loadFile(a)
307 elif o in ("-V", "--bslversion"):311 elif o in ("-V", "--bslversion"):
308 todo.append(bslobj.actionReadBSLVersion) # load replacement BSL as first item312 todo.append(bslobj.actionReadBSLVersion) # load replacement BSL as first item
309 elif o in ("-S", "--speed"):313 elif o in ("-S", "--speed"):
@@ -389,7 +393,6 @@
389 sys.stderr.flush()393 sys.stderr.flush()
390394
391 #prepare data to download395 #prepare data to download
392 bslobj.data = memory.Memory() # prepare downloaded data
393 if filetype is not None: # if the filetype is given...396 if filetype is not None: # if the filetype is given...
394 if filename is None:397 if filename is None:
395 raise ValueError("No filename but filetype specified")398 raise ValueError("No filename but filetype specified")
@@ -398,16 +401,16 @@
398 else:401 else:
399 file = open(filename, "rb") # or from a file402 file = open(filename, "rb") # or from a file
400 if filetype == 0: # select load function403 if filetype == 0: # select load function
401 bslobj.data.loadIHex(file) # intel hex404 bslobj.data = legacy_memory(memory.load(filename, file, 'ihex')) # intel hex
402 elif filetype == 1:405 elif filetype == 1:
403 bslobj.data.loadTIText(file) # TI's format406 bslobj.data = legacy_memory(memory.load(filename, file, 'titext')) # TI's format
404 else:407 else:
405 raise ValueError("Illegal filetype specified")408 raise ValueError("Illegal filetype specified")
406 else: # no filetype given...409 else: # no filetype given...
407 if filename == '-': # for stdin:410 if filename == '-': # for stdin:
408 bslobj.data.loadIHex(sys.stdin) # assume intel hex411 bslobj.data = legacy_memory(memory.load(filename, sys.stdin, 'ihex')) # assume intel hex
409 elif filename:412 elif filename:
410 bslobj.data.loadFile(filename) # autodetect otherwise413 bslobj.data = legacy_memory(memory.load(filename)) # autodetect otherwise
411414
412 if DEBUG > 3: sys.stderr.write("File: %r" % filename)415 if DEBUG > 3: sys.stderr.write("File: %r" % filename)
413416

Subscribers

People subscribed via source and target branches