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
1=== modified file 'scripts/msp430-bsl-legacy.py'
2--- scripts/msp430-bsl-legacy.py 2011-01-07 01:46:50 +0000
3+++ scripts/msp430-bsl-legacy.py 2012-02-09 06:15:22 +0000
4@@ -126,6 +126,11 @@
5 erased before programming.
6 """ % (sys.argv[0], VERSION))
7
8+def legacy_memory(memory):
9+ # msp430.legacy.bsl doesn't expect seg.data to be type bytearray
10+ for segment in memory:
11+ segment.data = bytes(segment.data)
12+ return memory
13
14 # Main:
15 def main():
16@@ -180,7 +185,7 @@
17 comPort = a # take the string and let serial driver decide
18 elif o in ("-P", "--password"):
19 # extract password from file
20- bslobj.passwd = memory.Memory(a).getMemrange(0xffe0, 0xffff)
21+ bslobj.passwd = legacy_memory(memory.load(a)).getMemrange(0xffe0, 0xffff)
22 elif o in ("-w", "--wait"):
23 wait = 1
24 elif o in ("-f", "--framesize"):
25@@ -302,8 +307,7 @@
26 elif o in ("-N", "--notimeout"):
27 notimeout = 1
28 elif o in ("-B", "--bsl"):
29- bslrepl = memory.Memory() # File to program
30- bslrepl.loadFile(a)
31+ bslrepl = legacy_memory(memory.load(a)) # File to program
32 elif o in ("-V", "--bslversion"):
33 todo.append(bslobj.actionReadBSLVersion) # load replacement BSL as first item
34 elif o in ("-S", "--speed"):
35@@ -389,7 +393,6 @@
36 sys.stderr.flush()
37
38 #prepare data to download
39- bslobj.data = memory.Memory() # prepare downloaded data
40 if filetype is not None: # if the filetype is given...
41 if filename is None:
42 raise ValueError("No filename but filetype specified")
43@@ -398,16 +401,16 @@
44 else:
45 file = open(filename, "rb") # or from a file
46 if filetype == 0: # select load function
47- bslobj.data.loadIHex(file) # intel hex
48+ bslobj.data = legacy_memory(memory.load(filename, file, 'ihex')) # intel hex
49 elif filetype == 1:
50- bslobj.data.loadTIText(file) # TI's format
51+ bslobj.data = legacy_memory(memory.load(filename, file, 'titext')) # TI's format
52 else:
53 raise ValueError("Illegal filetype specified")
54 else: # no filetype given...
55 if filename == '-': # for stdin:
56- bslobj.data.loadIHex(sys.stdin) # assume intel hex
57+ bslobj.data = legacy_memory(memory.load(filename, sys.stdin, 'ihex')) # assume intel hex
58 elif filename:
59- bslobj.data.loadFile(filename) # autodetect otherwise
60+ bslobj.data = legacy_memory(memory.load(filename)) # autodetect otherwise
61
62 if DEBUG > 3: sys.stderr.write("File: %r" % filename)
63

Subscribers

People subscribed via source and target branches