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
esptoc.py
- Committer:
- geky
- Date:
- 2016-04-18
- Revision:
- 0:d84cdaf22096
File content as of revision 0:d84cdaf22096:
#!/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:])