Merge lp:~w-uroda/python-msp430-tools/titextBlocks into lp:python-msp430-tools

Proposed by Wayne Uroda
Status: Needs review
Proposed branch: lp:~w-uroda/python-msp430-tools/titextBlocks
Merge into: lp:python-msp430-tools
Diff against target: 88 lines (+33/-9)
3 files modified
msp430/memory/__init__.py (+22/-3)
msp430/memory/convert.py (+1/-1)
msp430/memory/titext.py (+10/-5)
To merge this branch: bzr merge lp:~w-uroda/python-msp430-tools/titextBlocks
Reviewer Review Type Date Requested Status
zsquareplusc Pending
Review via email: mp+231988@code.launchpad.net

Description of the change

Added the ability to save titext with maximum block length

To post a comment you must log in.

Unmerged revisions

488. By Wayne Uroda

Added support for saving titext files with a maximum block size.
Eg. output format "titext256" will generate a titext file where there are no more than 256 bytes in each section (sections starting with @address).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'msp430/memory/__init__.py'
2--- msp430/memory/__init__.py 2012-12-07 13:56:26 +0000
3+++ msp430/memory/__init__.py 2014-08-23 13:23:52 +0000
4@@ -298,10 +298,13 @@
5 def save(memory, fileobj, format='titext'):
6 if format == 'titext':
7 return titext.save(memory, fileobj)
8+ elif format.startswith('titext') and format[6:].isdigit():
9+ maxBlockLen = int(format[6:])
10+ return titext.save(memory, fileobj, maxBlockLen)
11 elif format == 'ihex':
12 return intelhex.save(memory, fileobj)
13- elif format == 'elf':
14- return elf.save(memory, fileobj)
15+# elif format == 'elf':
16+# return elf.save(memory, fileobj)
17 elif format == 'bin':
18 return bin.save(memory, fileobj)
19 elif format == 'hex':
20@@ -309,5 +312,21 @@
21 raise ValueError('unsupported file format %s' % (format,))
22
23
24+class SaveFormats:
25+ formatList = ['titext', 'ihex', 'bin', 'hex']
26+ def __iter__(self):
27+ return iter(SaveFormats.formatList)
28+
29+ def __contains__(self,item):
30+ if item in SaveFormats.formatList:
31+ return True
32+
33+ if item.startswith('titext'):
34+ blockSize = item[6:]
35+ if blockSize.isdigit() and int(blockSize) > 0:
36+ return True
37+ return False
38+
39 load_formats = ['titext', 'ihex', 'bin', 'hex', 'elf']
40-save_formats = ['titext', 'ihex', 'bin', 'hex']
41+save_formats = SaveFormats()
42+
43
44=== modified file 'msp430/memory/convert.py'
45--- msp430/memory/convert.py 2011-02-19 19:51:27 +0000
46+++ msp430/memory/convert.py 2014-08-23 13:23:52 +0000
47@@ -45,7 +45,7 @@
48
49 parser.add_option("-f", "--output-format",
50 dest="output_format",
51- help="output format name (%s)" % (', '.join(memory.save_formats),),
52+ help="output format name (%s) or titextN where N is a positive integer" % (', '.join(memory.save_formats),),
53 default="titext",
54 metavar="TYPE")
55
56
57=== modified file 'msp430/memory/titext.py'
58--- msp430/memory/titext.py 2012-07-04 22:44:58 +0000
59+++ msp430/memory/titext.py 2014-08-23 13:23:52 +0000
60@@ -11,6 +11,7 @@
61
62 import msp430.memory
63 import msp430.memory.error
64+import sys
65
66 def load(filelike):
67 """load data from a (opened) file in TI-Text format"""
68@@ -41,11 +42,15 @@
69 memory.segments.append(msp430.memory.Segment(startAddr, segmentdata))
70 return memory
71
72-def save(memory, filelike):
73+def save(memory, filelike, maxBlocklen = sys.maxint):
74 """output TI-Text to given file object"""
75 for segment in sorted(memory.segments):
76- filelike.write("@%04x\n" % segment.startaddress)
77- data = bytearray(segment.data)
78- for i in range(0, len(data), 16):
79- filelike.write("%s\n" % " ".join(["%02x" % x for x in data[i:i+16]]))
80+ rawData = bytearray(segment.data)
81+ rawLength = len(rawData)
82+ for startAddr in range(0, rawLength, maxBlocklen):
83+ filelike.write("@%04x\n" % (segment.startaddress + startAddr))
84+ blockLen = min(maxBlocklen, rawLength - startAddr)
85+ data = rawData[startAddr : (startAddr + blockLen)]
86+ for i in range(0, len(data), 16):
87+ filelike.write("%s\n" % " ".join(["%02x" % x for x in data[i:i+16]]))
88 filelike.write("q\n")

Subscribers

People subscribed via source and target branches