From d470dc6daa46f26fc995ec86929e8209c581ea2d Mon Sep 17 00:00:00 2001 From: Michael Hope Date: Wed, 29 Sep 2010 20:21:52 +1300 Subject: Do basic validation on the boot version and chip IDs. --- support/stm32loader.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'support') diff --git a/support/stm32loader.py b/support/stm32loader.py index 7509871..b7fb96c 100755 --- a/support/stm32loader.py +++ b/support/stm32loader.py @@ -426,8 +426,18 @@ if __name__ == "__main__": print "Can't init. Ensure that BOOT0 is enabled and reset device" bootversion = cmd.cmdGet() + mdebug(0, "Bootloader version %X" % bootversion) - mdebug(0, "Chip id `%s'" % str(map(lambda c: hex(ord(c)), cmd.cmdGetID()))) + + if bootversion < 20 or bootversion >= 100: + raise Exception('Unreasonable bootloader version %d' % bootversion) + + id = [ord(x) for x in cmd.cmdGetID()] + mdebug(0, "Chip id '%s'" % ' '.join('0x%x' % x for x in id)) + + if len(id) < 2 or id[0] != 0x04: + raise Exception('Unrecognised chip ID') + # cmd.cmdGetVersion() # cmd.cmdGetID() # cmd.cmdReadoutUnprotect() -- cgit v1.2.3