8000 Output header in verbose mode. Also validate ULP header. · Plaque-fcc/micropython-esp32-ulp@15a631a · GitHub
[go: up one dir, main page]

Skip to content

Commit 15a631a

Browse files
committed
Output header in verbose mode. Also validate ULP header.
If the magic bytes in the header are not 'ulp\0' then the file is not a ULP binary or otherwise corrupt.
1 parent 08bb182 commit 15a631a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tools/disassemble.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ def chunk_into_words(code, bytes_per_word, byteorder):
163163
return words
164164

165165

166+
def print_ulp_header(h):
167+
print('ULP magic : %s (0x%08x)' % (h.magic.to_bytes(4, 'little'), h.magic))
168+
print('.text offset : %s (0x%02x)' % (h.text_offset, h.text_offset))
169+
print('.text size : %s (0x%02x)' % (h.text_size, h.text_size))
170+
print('.data offset : %s (0x%02x)' % (h.text_offset+h.text_size, h.text_offset+h.text_size))
171+
print('.data size : %s (0x%02x)' % (h.data_size, h.data_size))
172+
print('.bss size : %s (0x%02x)' % (h.bss_size, h.bss_size))
173+
print('----------------------------------------')
174+
175+
166176
def print_code_line(byte_offset, i, asm):
167177
lineformat = '{0:04x} {1} {2}'
168178
hex = ubinascii.hexlify(i.to_bytes(4, 'little'))
@@ -210,6 +220,13 @@ def disassemble_file(filename, verbose=False):
210220
)
211221
h = struct(addressof(data), binary_header_struct_def, LITTLE_ENDIAN)
212222

223+
if (h.magic != 0x00706c75):
224+
print('Invalid signature: 0x%08x (should be: 0x%08x)' % (h.magic, 0x00706c75))
225+
return
226+
227+
if verbose:
228+
print_ulp_header(h)
229+
213230
code = data[h.text_offset:]
214231
words = chunk_into_words(code, bytes_per_word=4, byteorder='little')
215232

@@ -223,7 +240,7 @@ def print_help():
223240
print('Options:')
224241
print(' -h Show this help text')
225242
print(' -m <byte_sequence> Sequence of hex bytes (8 per instruction)')
226-
print(' -v Verbose mode. Also show instruction fields')
243+
print(' -v Verbose mode. Show ULP header and fields of each instruction')
227244
print(' <filename> Path to ULP binary')
228245
pass
229246

0 commit comments

Comments
 (0)
0