summaryrefslogtreecommitdiff
path: root/downloader/downloader.py
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-02 22:59:18 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-02 22:59:18 +0000
commitbe691f3e7478d5e8a95a228f5fc0b4fb41c0bc68 (patch)
tree289682e994aff7a2c8c25ca47abb0decb3e13292 /downloader/downloader.py
parentsanity checks for commands (diff)
functions to generate flash segments
git-svn-id: https://svn.spreadspace.org/pic/trunk@23 a09c6847-51d9-44de-8ef2-e725cf50f3c7
Diffstat (limited to 'downloader/downloader.py')
-rwxr-xr-xdownloader/downloader.py48
1 files changed, 34 insertions, 14 deletions
diff --git a/downloader/downloader.py b/downloader/downloader.py
index 5380b4d..c6cb3ed 100755
--- a/downloader/downloader.py
+++ b/downloader/downloader.py
@@ -71,17 +71,41 @@ def load_hex(file):
print "ERROR: File not found: %s" % fin
sys.exit(1)
- data = {}
+ codedata = {}
ih = IntelHex(fin)
for a in ih.addresses():
- if a/2 not in data.keys():
- data[a/2] = 0
+ if a/2 not in codedata.keys():
+ codedata[a/2] = 0
if a%2 == 0:
- data[a/2] += ih[a]
+ codedata[a/2] += ih[a]
else:
- data[a/2] += (ih[a] << 8)
+ codedata[a/2] += (ih[a] << 8)
+
+ return codedata
+
+def get_lowest_flash_addr(codedata, fss):
+ lowest_code_addr = sorted(codedata.keys())[0]
+ return lowest_code_addr - (lowest_code_addr%fss)
+
+def get_highest_flash_addr(codedata, fss):
+ highest_code_addr = sorted(codedata.keys())[-1]
+ return highest_code_addr + (fss - highest_code_addr%fss)
+
+def create_flash_image(codedata, fss, sa, ea):
+ img = ( sa, [0xFFFF]*(ea-sa) )
+ for a,d in codedata.items():
+ img[1][a-sa] = d
+ return img
+
+def create_flash_segments(codedata, fss):
+ sa = get_lowest_flash_addr(codedata, fss)
+ ea = get_highest_flash_addr(codedata, fss)
+ img = create_flash_image(codedata, fss, sa, ea)
+ for i in xrange(0, ea, fss):
+ slice = img[1][i:i+fss]
+ if not all( (elem == 0xFFFF) for elem in slice):
+ yield (i, slice)
- return data
def calc_csum(str):
cs = 0
@@ -89,7 +113,6 @@ def calc_csum(str):
cs ^= ord(c)
return chr(cs)
-
def exec_command(dev, cmd, answer):
import struct
@@ -196,11 +219,8 @@ Options:
sys.exit(2)
dev = open_serial(device, baudrate)
- data = load_hex(args[0])
-
- addrs = data.keys()
- addrs.sort()
- for a in addrs:
- print "%05d: %04X" % (a, data[a])
-
+ codedata = load_hex(args[0])
id = identify(dev)
+
+ for segment in create_flash_segments(codedata, id['fss']):
+ print "%05X: %s" % (segment[0], ''.join('%04X'%i for i in segment[1]))