scripts/hex_free_size.py
2022-05-02 16:34:13 +02:00

40 lines
1.1 KiB
Python

#-------------------------------------------------------------------------------
# hex_free_space
# 02/05/2022
# tool script used to estimate the free space left in a µP based on the number
# of 0xFF bytes in the hex file. This methode only works for filled hex files.
#
# usage ex: python hex_free_size somehexfile.hex somemorehexfile.hex
#-------------------------------------------------------------------------------
import fileinput
import re
free_space = 0
free_threshold = 16
p = re.compile(r':[0-9A-F]{8,8}([0-9A-F]{32,32})')
for line in fileinput.input():
val = re.search(p, line)
if val:
data = val.group(0)
count = 0
for char in data:
if char == 'F':
count += 1
if count <= free_threshold:
continue
for char in data:
if char == 'F':
if first:
first = False
else:
first = True
free_space += 1
else:
first = True
print("estimated free space: " + str(free_space))