#!/usr/bin/env python3 import argparse import struct import os, sys from lib.dump import DUMP_MAGIC, DUMP_OFFSET, DUMP_SIZE def error(msg): print(msg, file=sys.stderr) def main(): # parse the arguments ap = argparse.ArgumentParser(description=""" Extract a crash dump from an external flash image and output the same format produced by the D21 g-code. """) ap.add_argument('image') args = ap.parse_args() # read the image off = DUMP_OFFSET with open(args.image, 'rb') as fd: fd.seek(off) data = fd.read(DUMP_SIZE) if len(data) != DUMP_SIZE: error('incorrect image size') return os.EX_DATAERR # check for magic header magic, = struct.unpack('