feat: Detect Guru Meditation errors

This commit is contained in:
radim.karnis
2022-10-03 15:43:00 +02:00
parent f4ed949557
commit 6fac2611d1

View File

@@ -1428,6 +1428,38 @@ def slip_reader(port, trace_function):
Designed to avoid too many calls to serial.read(1), which can bog Designed to avoid too many calls to serial.read(1), which can bog
down on slow systems. down on slow systems.
""" """
def detect_panic_handler(input):
"""
Checks the input bytes for panic handler messages.
Raises a FatalError if Guru Meditation or Fatal Exception is found, as both
of these are used between different ROM versions.
Tries to also parse the error cause (e.g. IllegalInstruction).
"""
guru_meditation = (
rb"G?uru Meditation Error: (?:Core \d panic'ed \(([a-zA-Z]*)\))?"
)
fatal_exception = rb"F?atal exception \(\d+\): (?:([a-zA-Z]*)?.*epc)?"
# Search either for Guru Meditation or Fatal Exception
data = re.search(
rb"".join([rb"(?:", guru_meditation, rb"|", fatal_exception, rb")"]),
input,
re.DOTALL,
)
if data is not None:
msg = "Guru Meditation Error detected {}".format(
" ".join(
[
"({})".format(i.decode("utf-8"))
for i in [data.group(1), data.group(2)]
if i is not None
]
)
)
raise FatalError(msg)
partial_packet = None partial_packet = None
in_escape = False in_escape = False
successful_slip = False successful_slip = False
@@ -1455,10 +1487,12 @@ def slip_reader(port, trace_function):
partial_packet = b"" partial_packet = b""
else: else:
trace_function("Read invalid data: %s", HexFormatter(read_bytes)) trace_function("Read invalid data: %s", HexFormatter(read_bytes))
remaining_data = port.read(port.inWaiting())
trace_function( trace_function(
"Remaining data in serial buffer: %s", "Remaining data in serial buffer: %s",
HexFormatter(port.read(port.inWaiting())), HexFormatter(remaining_data),
) )
detect_panic_handler(read_bytes + remaining_data)
raise FatalError( raise FatalError(
"Invalid head of packet (0x%s): " "Invalid head of packet (0x%s): "
"Possible serial noise or corruption." % hexify(b) "Possible serial noise or corruption." % hexify(b)
@@ -1471,10 +1505,12 @@ def slip_reader(port, trace_function):
partial_packet += b"\xdb" partial_packet += b"\xdb"
else: else:
trace_function("Read invalid data: %s", HexFormatter(read_bytes)) trace_function("Read invalid data: %s", HexFormatter(read_bytes))
remaining_data = port.read(port.inWaiting())
trace_function( trace_function(
"Remaining data in serial buffer: %s", "Remaining data in serial buffer: %s",
HexFormatter(port.read(port.inWaiting())), HexFormatter(remaining_data),
) )
detect_panic_handler(read_bytes + remaining_data)
raise FatalError("Invalid SLIP escape (0xdb, 0x%s)" % (hexify(b))) raise FatalError("Invalid SLIP escape (0xdb, 0x%s)" % (hexify(b)))
elif b == b"\xdb": # start of escape sequence elif b == b"\xdb": # start of escape sequence
in_escape = True in_escape = True