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