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