Binary to update ESP8266 firmware to Espressif firmware. Requires user to press buttons.

Dependencies:   BufferedSerial mbed

Fork of ESPQuickFlash by Christopher Haster

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers esptoc.py Source File

esptoc.py

00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import time
00005 
00006 
00007 FILE_TEMPLATE = """
00008 /*** Auto generated on %s ***/
00009 
00010 struct flash_page {
00011     uint32_t address;
00012     uint32_t size;
00013     const char *data;
00014 };
00015 
00016 #define FLASH_COUNT %d
00017 struct flash_page FLASH_PAGES[FLASH_COUNT] = {
00018 %s
00019 };
00020 """
00021 
00022 PAGE_TEMPLATE = """    { 0x%05x, 0x%05x, (const char []){
00023         %s
00024     }}"""
00025     
00026 
00027 def main(*args):
00028     if len(args) < 2:
00029         print 'Usage: %s <address> <file> <address> <file>...' % sys.argv[0]
00030         sys.exit(-1)
00031         
00032     pages = []
00033 
00034     for addr, filename in zip(*[iter(args)]*2):
00035         with open(filename, 'rb') as file:
00036             addr = int(addr, 0)
00037             data = file.read()
00038             size = len(data)
00039             
00040             lines = zip(*[('0x%02x' % ord(x) for x in data)]*16)
00041             array = ',\n        '.join(','.join(line) for line in lines)
00042             
00043             pages.append(PAGE_TEMPLATE % (addr, size, array))
00044             
00045     sys.stdout.write(FILE_TEMPLATE % (
00046         time.strftime("%d/%m/%Y"),
00047         len(pages),
00048         ',\n'.join(pages)
00049         ))            
00050     
00051 if __name__=="__main__":
00052     main(*sys.argv[1:])