Files
STM32F4-Base/MDK-ARM/check_crecipe_content.py
T

56 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Verify whether the C-recipe runs actually received correct CONTENT (fill part),
# i.e. whether "fill part 0/1460" from probe_classify mode C is real corruption
# or a classifier artifact. ASCII output only.
import sys, re
def pattern(base, n):
return bytes(((base + i) & 0xFF) for i in range(n))
def hex_blocks(path):
blocks = []
cur = []
for line in open(path, encoding="utf-8-sig", errors="replace"):
m = re.match(r"HEX2?\s+(\d+)\s+([0-9a-fA-F]+)", line.strip())
if m:
off = int(m.group(1))
if off == 0 and cur:
blocks.append(cur)
cur = []
cur.append((off, bytes.fromhex(m.group(2))))
if cur:
blocks.append(cur)
out = []
for b in blocks:
data = b"".join(x[1] for x in b)
out.append(data)
return out
def check(path):
blocks = hex_blocks(path)
print("=" * 60)
print("LOG:", path, "blocks:", [len(b) for b in blocks])
exp_fill = pattern(640, 1460)
exp_tail = pattern(2100, 1460) + b"".join(pattern(2100 + 1460 + i * 64, 64) for i in range(10))
if blocks:
got = blocks[0]
n = min(len(got), len(exp_fill))
m = 0
while m < n and got[m] == exp_fill[m]:
m += 1
print(" fill: got=%d exp=%d match_prefix=%d %s" %
(len(got), len(exp_fill), m, "MATCH" if m == len(exp_fill) else "MISMATCH"))
if m < n:
print(" first mismatch at %d: got=%02x exp=%02x" % (m, got[m], exp_fill[m]))
if len(blocks) > 1:
got2 = blocks[1]
n2 = min(len(got2), len(exp_tail))
m2 = 0
while m2 < n2 and got2[m2] == exp_tail[m2]:
m2 += 1
print(" tail: got=%d exp=%d match_prefix=%d %s" %
(len(got2), len(exp_tail), m2, "MATCH" if m2 == len(exp_tail) else "MISMATCH"))
for p in sys.argv[1:]:
check(p)