#!/usr/bin/python # # File : gen_appbin.py # This file is part of Espressif's generate bin script. # Copyright (C) 2013 - 2016, Espressif Systems # # This program is free software: you can redistribute it and/or modify # it under the terms of version 3 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . """This file is part of Espressif's generate bin script. argv[1] is elf file name argv[2] is version num""" import string import sys import os import re import binascii import struct import zlib TEXT_ADDRESS = 0x40100000 # app_entry = 0 # data_address = 0x3ffb0000 # data_end = 0x40000000 # text_end = 0x40120000 CHECKSUM_INIT = 0xEF chk_sum = CHECKSUM_INIT blocks = 0 def write_file(file_name,data): if file_name is None: print 'file_name cannot be none\n' sys.exit(0) fp = open(file_name,'ab') if fp: fp.seek(0,os.SEEK_END) fp.write(data) fp.close() else: print '%s write fail\n'%(file_name) def combine_bin(file_name,dest_file_name,start_offset_addr,need_chk): global chk_sum global blocks if dest_file_name is None: print 'dest_file_name cannot be none\n' sys.exit(0) if file_name: fp = open(file_name,'rb') if fp: ########## write text ########## fp.seek(0,os.SEEK_END) data_len = fp.tell() if data_len: if need_chk: tmp_len = (data_len + 3) & (~3) else: tmp_len = (data_len + 15) & (~15) data_bin = struct.pack(' eagle.app.sym' else : cmd = 'xt-nm -g ' + elf_file + ' > eagle.app.sym' os.system(cmd) fp = file('./eagle.app.sym') if fp is None: print "open sym file error\n" sys.exit(0) lines = fp.readlines() fp.close() entry_addr = None p = re.compile('(\w*)(\sT\s)(call_user_start)$') for line in lines: m = p.search(line) if m != None: entry_addr = m.group(1) # print entry_addr if entry_addr is None: print 'no entry point!!' sys.exit(0) data_start_addr = '0' p = re.compile('(\w*)(\sA\s)(_data_start)$') for line in lines: m = p.search(line) if m != None: data_start_addr = m.group(1) # print data_start_addr rodata_start_addr = '0' p = re.compile('(\w*)(\sA\s)(_rodata_start)$') for line in lines: m = p.search(line) if m != None: rodata_start_addr = m.group(1) # print rodata_start_addr # write flash bin header #============================ # SPI FLASH PARAMS #------------------- #flash_mode= # 0: QIO # 1: QOUT # 2: DIO # 3: DOUT #------------------- #flash_clk_div= # 0 : 80m / 2 # 1 : 80m / 3 # 2 : 80m / 4 # 0xf: 80m / 1 #------------------- #flash_size_map= # 0 : 512 KB (256 KB + 256 KB) # 1 : 256 KB # 2 : 1024 KB (512 KB + 512 KB) # 3 : 2048 KB (512 KB + 512 KB) # 4 : 4096 KB (512 KB + 512 KB) # 5 : 2048 KB (1024 KB + 1024 KB) # 6 : 4096 KB (1024 KB + 1024 KB) #------------------- # END OF SPI FLASH PARAMS #============================ byte2=int(flash_mode)&0xff byte3=(((int(flash_size_map)<<4)| int(flash_clk_div))&0xff) app=int(user_bin)&0xff if boot_mode == '2': # write irom bin head #data_bin = struct.pack('> 8)+chr((all_bin_crc & 0x00FF0000) >> 16)+chr((all_bin_crc & 0xFF000000) >> 24)) cmd = 'rm eagle.app.sym' os.system(cmd) if __name__=='__main__': gen_appbin()