def wrap_stub(elf_file): """ Wrap an ELF file into a stub 'dict' """ print('Wrapping ELF file %s...' % elf_file) e = esptool.ELFFile(elf_file) text_section = e.get_section('.text') try: data_section = e.get_section('.data') except ValueError: data_section = None stub = { 'text': text_section.data, 'text_start': text_section.addr, 'entry': e.entrypoint, } if data_section is not None: stub['data'] = data_section.data stub['data_start'] = data_section.addr # Pad text with NOPs to mod 4. if len(stub['text']) % 4 != 0: stub['text'] += (4 - (len(stub['text']) % 4)) * '\0' print('Stub text: %d @ 0x%08x, data: %d @ 0x%08x, entry @ 0x%x' % ( len(stub['text']), stub['text_start'], len(stub.get('data', '')), stub.get('data_start', 0), stub['entry']), file=sys.stderr) return stub
# 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, write to the Free Software Foundation, Inc., 51 Franklin # Street, Fifth Floor, Boston, MA 02110-1301 USA. import json import os import sys sys.path.append('..') import esptool if __name__ == '__main__': e = esptool.ELFFile(sys.argv[1]) entry = 'stub_main' stub = { 'params_start': e.get_symbol_addr('_params_start'), 'code': e.load_section('.code'), 'code_start': e.get_symbol_addr('_code_start'), 'entry': e.get_symbol_addr(entry), } data = e.load_section('.data') if len(data) > 0: stub['data'] = data stub['data_start'] = e.get_symbol_addr('_data_start') params_len = e.get_symbol_addr('_params_end') - stub['params_start'] if params_len % 4 != 0: raise FatalError('Params must be dwords')