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
def wrap_stub ( elf_file ) : 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 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
Wrap an ELF file into a stub 'dict'