Skip to content

Commit 08bb182

Browse files
committed
use text_offset from ULP header instead of hardcoded offset
1 parent 40ea7e9 commit 08bb182

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tools/disassemble.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from uctypes import struct, addressof, LITTLE_ENDIAN, UINT16, UINT32
12
from esp32_ulp.opcodes import RD_REG_PERIPH_RTC_CNTL, RD_REG_PERIPH_RTC_IO, RD_REG_PERIPH_RTC_I2C, \
23
RD_REG_PERIPH_SENS, DR_REG_MAX_DIRECT
34
import esp32_ulp.opcodes as opcodes
@@ -200,7 +201,16 @@ def disassemble_file(filename, verbose=False):
200201
with open(filename, 'rb') as f:
201202
data = f.read()
202203

203-
code = data[12:] # text_offset (where code starts) is always 12 for ULP binaries
204+
binary_header_struct_def = dict(
205+
magic = 0 | UINT32,
206+
text_offset = 4 | UINT16,
207+
text_size = 6 | UINT16,
208+
data_size = 8 | UINT16,
209+
bss_size = 10 | UINT16,
210+
)
211+
h = struct(addressof(data), binary_header_struct_def, LITTLE_ENDIAN)
212+
213+
code = data[h.text_offset:]
204214
words = chunk_into_words(code, bytes_per_word=4, byteorder='little')
205215

206216
for idx, i in enumerate(words):

0 commit comments

Comments
 (0)