summaryrefslogtreecommitdiff
path: root/bootloader/downloader.py
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-10 01:29:55 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-10 01:29:55 +0000
commit2beeddebe44c8d5997b1999c651f28a36155cf07 (patch)
tree6196c7469bcdbe96ae7c639e7316c6930753b708 /bootloader/downloader.py
parentfinally remove downloader dir (diff)
drop requirment for intelhex library
added minimal hex file handling class git-svn-id: https://svn.spreadspace.org/pic/trunk@65 a09c6847-51d9-44de-8ef2-e725cf50f3c7
Diffstat (limited to 'bootloader/downloader.py')
-rwxr-xr-xbootloader/downloader.py88
1 files changed, 36 insertions, 52 deletions
diff --git a/bootloader/downloader.py b/bootloader/downloader.py
index 459e0d2..260ff7e 100755
--- a/bootloader/downloader.py
+++ b/bootloader/downloader.py
@@ -29,7 +29,7 @@ VERSION_MIN = 1
### HEX File Magic
def load_hex(file):
- from intelhex import IntelHex
+ from ihexpic import IHexPic
fin = file
if fin == '-':
@@ -38,58 +38,41 @@ def load_hex(file):
print >> sys.stderr, "ERROR: File not found: %s" % fin
sys.exit(1)
- codedata = {}
- ih = IntelHex(fin)
- for a in ih.addresses():
- if a/2 not in codedata.keys():
- codedata[a/2] = 0
- if a%2 == 0:
- codedata[a/2] += ih[a]
- else:
- codedata[a/2] += (ih[a] << 8)
+ hexdata = IHexPic()
+ hexdata.load_from_file(fin)
+ return hexdata
- return codedata
+# TODO: re-add this as soon as write_hex_file works
+# def write_hex(file, hexdata):
+# fout = file
+# if fout == '-':
+# fout = sys.stdout
-def write_hex(file, codedata):
- from intelhex import IntelHex
+# hexdata.write_hex_file(fout)
- 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]
+def get_lowest_flash_addr(hexdata, fss):
+ lowest_code_addr = hexdata.get_lowest_addr()
return lowest_code_addr - (lowest_code_addr%fss)
-def get_highest_flash_addr(codedata, fss):
- highest_code_addr = sorted(codedata.keys())[-1]
+def get_highest_flash_addr(hexdata, fss):
+ highest_code_addr = hexdata.get_highest_addr()
return highest_code_addr + (fss - highest_code_addr%fss)
-def create_flash_image(codedata, fss, sa, ea):
+def create_flash_image(hexdata, fss, sa, ea):
img = ( sa, [0xFFFF]*(ea-sa) )
- for a,d in codedata.items():
+ for a,d in hexdata.items():
if a < ea:
img[1][a-sa] = d
return img
-def create_flash_segments(codedata, fs, fss):
- sa = get_lowest_flash_addr(codedata, fss)
- ea = get_highest_flash_addr(codedata, fss)
+def create_flash_segments(hexdata, fs, fss):
+ sa = get_lowest_flash_addr(hexdata, fss)
+ ea = get_highest_flash_addr(hexdata, fss)
if ea >= fs:
print >> sys.stderr, "WARNING: the hex file contains data after end of flash, these words will be ignored"
ea = fs
- img = create_flash_image(codedata, fss, sa, ea)
+ img = create_flash_image(hexdata, fss, sa, ea)
for i in xrange(0, ea, fss):
slice = tuple(img[1][i:i+fss])
if not all( (elem == 0xFFFF) for elem in slice):
@@ -234,27 +217,28 @@ def boot(dev, id, file):
cmd_boot(dev)
def write_flash(dev, id, file):
- codedata = load_hex(file)
- for segment in create_flash_segments(codedata, id['fs'], id['fss']):
+ hexdata = load_hex(file)
+ for segment in create_flash_segments(hexdata, id['fs'], id['fss']):
# print >> sys.stderr, "%05X: %s" % (segment[0], ''.join('%04X '%i for i in segment[1]))
cmd_write_flash_segment(dev, id, segment[0], segment[1])
-def read_flash(dev, id, file):
- codedata = {}
- for addr in xrange(0, id['fs'], id['fss']):
- data = cmd_read_flash_segment(dev, id, addr)
-# print >> sys.stderr, "%05X: %s" % (addr, ''.join('%04X '%i for i in data))
- a = addr
- for d in data:
- codedata[a] = d
- a += 1
+# TODO: re-add this as soon as write_hex_file works
+# def read_flash(dev, id, file):
+# codedata = {}
+# for addr in xrange(0, id['fs'], id['fss']):
+# data = cmd_read_flash_segment(dev, id, addr)
+# # print >> sys.stderr, "%05X: %s" % (addr, ''.join('%04X '%i for i in data))
+# a = addr
+# for d in data:
+# codedata[a] = d
+# a += 1
- write_hex(file, codedata)
+# write_hex(file, codedata)
def verify_flash(dev, id, file):
- codedata = load_hex(file)
+ hexdata = load_hex(file)
err = 0
- for segment in create_flash_segments(codedata, id['fs'], id['fss']):
+ for segment in create_flash_segments(hexdata, id['fs'], id['fss']):
flashdata = cmd_read_flash_segment(dev, id, segment[0])
for file,flash in zip(segment[1] , flashdata):
if flash == 0x3FFF:
@@ -276,7 +260,7 @@ def verify_flash(dev, id, file):
commands = {
'boot': boot,
'write': write_flash,
- 'read': read_flash,
+# 'read': read_flash, # TODO: re-add this as soon as write_hex_file works
'verify': verify_flash
}