Clone of official tools
dev/intel_hex_utils.py@0:66f3b5499f7f, 2016-05-19 (annotated)
- Committer:
- screamer
- Date:
- Thu May 19 19:44:41 2016 +0100
- Revision:
- 0:66f3b5499f7f
Initial revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:66f3b5499f7f | 1 | from intelhex import IntelHex |
screamer | 0:66f3b5499f7f | 2 | from cStringIO import StringIO |
screamer | 0:66f3b5499f7f | 3 | |
screamer | 0:66f3b5499f7f | 4 | |
screamer | 0:66f3b5499f7f | 5 | def sections(h): |
screamer | 0:66f3b5499f7f | 6 | start, last_address = None, None |
screamer | 0:66f3b5499f7f | 7 | for a in h.addresses(): |
screamer | 0:66f3b5499f7f | 8 | if last_address is None: |
screamer | 0:66f3b5499f7f | 9 | start, last_address = a, a |
screamer | 0:66f3b5499f7f | 10 | continue |
screamer | 0:66f3b5499f7f | 11 | |
screamer | 0:66f3b5499f7f | 12 | if a > last_address + 1: |
screamer | 0:66f3b5499f7f | 13 | yield (start, last_address) |
screamer | 0:66f3b5499f7f | 14 | start = a |
screamer | 0:66f3b5499f7f | 15 | |
screamer | 0:66f3b5499f7f | 16 | last_address = a |
screamer | 0:66f3b5499f7f | 17 | |
screamer | 0:66f3b5499f7f | 18 | if start: |
screamer | 0:66f3b5499f7f | 19 | yield (start, last_address) |
screamer | 0:66f3b5499f7f | 20 | |
screamer | 0:66f3b5499f7f | 21 | |
screamer | 0:66f3b5499f7f | 22 | def print_sections(h): |
screamer | 0:66f3b5499f7f | 23 | for s in sections(h): |
screamer | 0:66f3b5499f7f | 24 | print "[0x%08X - 0x%08X]" % s |
screamer | 0:66f3b5499f7f | 25 | |
screamer | 0:66f3b5499f7f | 26 | |
screamer | 0:66f3b5499f7f | 27 | def decode(record): |
screamer | 0:66f3b5499f7f | 28 | h = IntelHex() |
screamer | 0:66f3b5499f7f | 29 | f = StringIO(record) |
screamer | 0:66f3b5499f7f | 30 | h.loadhex(f) |
screamer | 0:66f3b5499f7f | 31 | h.dump() |