Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial mbed
Diff: esptoc.py
- Revision:
- 0:d84cdaf22096
diff -r 000000000000 -r d84cdaf22096 esptoc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/esptoc.py Mon Apr 18 20:36:49 2016 +0000 @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import sys +import time + + +FILE_TEMPLATE = """ +/*** Auto generated on %s ***/ + +struct flash_page { + uint32_t address; + uint32_t size; + const char *data; +}; + +#define FLASH_COUNT %d +struct flash_page FLASH_PAGES[FLASH_COUNT] = { +%s +}; +""" + +PAGE_TEMPLATE = """ { 0x%05x, 0x%05x, (const char []){ + %s + }}""" + + +def main(*args): + if len(args) < 2: + print 'Usage: %s <address> <file> <address> <file>...' % sys.argv[0] + sys.exit(-1) + + pages = [] + + for addr, filename in zip(*[iter(args)]*2): + with open(filename, 'rb') as file: + addr = int(addr, 0) + data = file.read() + size = len(data) + + lines = zip(*[('0x%02x' % ord(x) for x in data)]*16) + array = ',\n '.join(','.join(line) for line in lines) + + pages.append(PAGE_TEMPLATE % (addr, size, array)) + + sys.stdout.write(FILE_TEMPLATE % ( + time.strftime("%d/%m/%Y"), + len(pages), + ',\n'.join(pages) + )) + +if __name__=="__main__": + main(*sys.argv[1:])