def main(): try: if len(sys.argv) == 3: if sys.argv[1] == 'read': import usb.core dfu = init_dfu() upload_codeplug(dfu, sys.argv[2]) print('Read complete') elif sys.argv[1] == 'readboot': print("This only works from OS X. Use the one in md380-tool with patched firmware for other bootloaders.") import usb.core dfu = init_dfu() upload_bootloader(dfu, sys.argv[2]) elif sys.argv[1] == "upgrade": import usb.core with open(sys.argv[2], 'rb') as f: data = f.read() dfu = init_dfu() download_firmware(dfu, data) elif sys.argv[1] == "new_upgrade": with open(sys.argv[2], 'rb') as f: data = f.read() dfu = init_dfu() download_firmware_md2017(dfu,data) elif sys.argv[1] == 'write': import usb.core f = open(sys.argv[2], 'rb') data = f.read() f.close() print(len(data),data[0:5]) if sys.argv[2][-4:] == '.dfu': suf_len, vendor, product = dfu_suffix.check_suffix(data) dfu = init_dfu() codeplug = data[:-suf_len] elif sys.argv[2][-4:] == '.rdt' and ( len(data) == 262709 or len(data) == 852533 ) and data[0:5] == 'DfuSe': #small is md380 codeplug, large is MD2017 dfu = init_dfu() codeplug = data[549:len(data) - 16] else: dfu = init_dfu() codeplug = data download_codeplug(dfu, codeplug) print('Write complete') elif sys.argv[1] == 'sign': filename = sys.argv[2] f = open(filename, 'rb') firmware = f.read() f.close() data = dfu_suffix.add_suffix(firmware, md380_vendor, md380_product) dfu_file = filename[:-4] + '.dfu' f = open(dfu_file, 'wb') f.write(data) f.close() print("Signed file written: %s" % dfu_file) elif sys.argv[1] == 'settime': import usb.core dfu = init_dfu() dfu.set_time() else: usage() elif len(sys.argv) == 2: if sys.argv[1] == 'detach': import usb.core dfu = init_dfu() dfu.set_address(0x08000000) # Radio Application detach(dfu) elif sys.argv[1] == 'time': import usb.core dfu = init_dfu() print(dfu.get_time()) elif sys.argv[1] == 'settime': import usb.core dfu = init_dfu() dfu.set_time() elif sys.argv[1] == 'reboot': import usb.core dfu = init_dfu() dfu.md380_custom(0x91, 0x01) # Programming Mode dfu.md380_custom(0x91, 0x01) # Programming Mode # dfu.md380_custom(0x91,0x01); #Programming Mode # dfu.drawtext("Rebooting",160,50); dfu.md380_reboot() elif sys.argv[1] == 'abort': import usb.core dfu = init_dfu() dfu.abort() elif sys.argv[1] == "ident": dfu = init_dfu() import binascii rid = dfu.identify_radio() print(binascii.hexlify(rid)) print(rid) else: usage() else: usage() except RuntimeError as e: print(e.args[0]) exit(1) except Exception as e: print(e) # print(dfu.get_status()) exit(1)
def main(): try: if len(sys.argv) == 3: if sys.argv[1] == 'read': dfu = init_dfu() upload_codeplug(dfu, sys.argv[2]) print('Read complete') elif sys.argv[1] == 'readboot': print( "This only works from OS X. Use the one in md380-tool with patched firmware for other bootloaders." ) dfu = init_dfu() upload_bootloader(dfu, sys.argv[2]) elif sys.argv[1] == "upgrade": with open(sys.argv[2], 'rb') as f: data = f.read() errors = auto_upgrade(data) if errors: print( "Encountered following unexpected errors during upgrade:" ) for e in errors: print(e) print( "This means the upgrade (probably) failed. Try again." ) elif sys.argv[1] == 'write': f = open(sys.argv[2], 'rb') data = f.read() f.close() firmware = None if sys.argv[2][-4:] == '.dfu': suf_len, vendor, product = dfu_suffix.check_suffix(data) dfu = init_dfu() firmware = data[:-suf_len] elif sys.argv[2][-4:] == '.rdt': if len(data) == 262709 and data[0:5] == 'DfuSe': dfu = init_dfu() firmware = data[549:len(data) - 16] else: print( '%s not a valid codeplug (wrong size, or wrong magic).' % sys.argv[2]) else: dfu = init_dfu() firmware = data if firmware is not None: download_codeplug(dfu, firmware) print('Write complete') elif sys.argv[1] == 'sign': filename = sys.argv[2] f = open(filename, 'rb') firmware = f.read() f.close() data = dfu_suffix.add_suffix(firmware, md380_vendor, md380_product) dfu_file = filename[:-4] + '.dfu' f = open(dfu_file, 'wb') f.write(data) f.close() print("Signed file written: %s" % dfu_file) elif sys.argv[1] == 'settime': dfu = init_dfu() dfu.set_time() else: usage() elif len(sys.argv) == 2: if sys.argv[1] == 'detach': dfu = init_dfu() dfu.set_address(0x08000000) # Radio Application detach(dfu) elif sys.argv[1] == 'time': dfu = init_dfu() print(dfu.get_time()) elif sys.argv[1] == 'settime': dfu = init_dfu() dfu.set_time() elif sys.argv[1] == 'reboot': dfu = init_dfu() dfu.md380_custom(0x91, 0x01) # Programming Mode dfu.md380_custom(0x91, 0x01) # Programming Mode # dfu.md380_custom(0x91,0x01); #Programming Mode # dfu.drawtext("Rebooting",160,50); dfu.md380_reboot() elif sys.argv[1] == 'abort': dfu = init_dfu() dfu.abort() else: usage() else: usage() except RuntimeError as e: print(e.args[0]) exit(1) except Exception as e: print(e) # print(dfu.get_status()) exit(1)
def main(): try: if len(sys.argv) == 3: if sys.argv[1] == 'read': import usb.core dfu = init_dfu() upload_codeplug(dfu, sys.argv[2]) print('Read complete') elif sys.argv[1] == 'readboot': print "This only wokrs from OS X. Use the one in md380-tool with patched firmware for other bootloaders."; import usb.core dfu = init_dfu() upload_bootloader(dfu, sys.argv[2]) elif sys.argv[1] == "upgrade": import usb.core with open(sys.argv[2], 'rb') as f: data = f.read(); dfu = init_dfu(); download_firmware(dfu, data); elif sys.argv[1] == 'write': import usb.core f = open(sys.argv[2], 'rb') data = f.read() f.close() if sys.argv[2][-4:] == '.dfu': suf_len, vendor, product = dfu_suffix.check_suffix(data) dfu = init_dfu() firmware = data[:-suf_len] elif sys.argv[2][-4:] == '.rdt' and len(data) == 262709 and data[0:5] == 'DfuSe': dfu = init_dfu() firmware = data[549:len(data)-16] else: dfu = init_dfu() firmware = data download_codeplug(dfu, firmware) print('Write complete') elif sys.argv[1] == 'sign': filename = sys.argv[2] f = open(filename, 'rb') firmware = f.read() f.close() data = dfu_suffix.add_suffix(firmware, md380_vendor, md380_product) dfu_file = filename[:-4] + '.dfu' f = open(dfu_file, 'wb') f.write(data) f.close() print("Signed file written: %s" % dfu_file) else: usage() elif len(sys.argv) == 2: if sys.argv[1] == 'detach': import usb.core dfu = init_dfu() dfu.set_address(0x08000000); #Radio Application detach(dfu) elif sys.argv[1] == 'time': import usb.core dfu = init_dfu() print dfu.get_time(); elif sys.argv[1] == 'reboot': import usb.core dfu = init_dfu() dfu.md380_custom(0x91,0x01); #Programming Mode dfu.md380_custom(0x91,0x01); #Programming Mode #dfu.md380_custom(0x91,0x01); #Programming Mode #dfu.drawtext("Rebooting",160,50); dfu.md380_reboot() elif sys.argv[1] == 'abort': import usb.core dfu = init_dfu() dfu.abort(); else: usage() else: usage() except RuntimeError, e: print(e.args[0]) exit(1)
firmware = data[:-suf_len] else: dfu = init_dfu() firmware = data download_codeplug(dfu, firmware) print('Write complete') elif action == 'sign': filename = sys.argv[2] f = open(filename, 'rb') firmware = f.read() f.close() data = dfu_suffix.add_suffix(firmware, md380_vendor, md380_product) elif len(sys.argv) == 2: if sys.argv[1] == 'detach': import usb.core dfu = init_dfu() dfu.set_address(0x08000000); #Radio Application detach(dfu) elif sys.argv[1] == 'time': import usb.core dfu = init_dfu() print dfu.get_time(); elif sys.argv[1] == 'reboot': import usb.core dfu = init_dfu()
def main(): try: if len(sys.argv) == 3: if sys.argv[1] == 'read': import usb.core dfu = init_dfu() upload_codeplug(dfu, sys.argv[2]) print('Read complete') elif sys.argv[1] == 'readboot': print "This only wokrs from OS X. Use the one in md380-tool with patched firmware for other bootloaders." import usb.core dfu = init_dfu() upload_bootloader(dfu, sys.argv[2]) elif sys.argv[1] == "upgrade": import usb.core with open(sys.argv[2], 'rb') as f: data = f.read() dfu = init_dfu() download_firmware(dfu, data) elif sys.argv[1] == 'write': import usb.core f = open(sys.argv[2], 'rb') data = f.read() f.close() if sys.argv[2][-4:] == '.dfu': suf_len, vendor, product = dfu_suffix.check_suffix(data) dfu = init_dfu() firmware = data[:-suf_len] elif sys.argv[2][-4:] == '.rdt' and len( data) == 262709 and data[0:5] == 'DfuSe': dfu = init_dfu() firmware = data[549:len(data) - 16] else: dfu = init_dfu() firmware = data download_codeplug(dfu, firmware) print('Write complete') elif sys.argv[1] == 'sign': filename = sys.argv[2] f = open(filename, 'rb') firmware = f.read() f.close() data = dfu_suffix.add_suffix(firmware, md380_vendor, md380_product) dfu_file = filename[:-4] + '.dfu' f = open(dfu_file, 'wb') f.write(data) f.close() print("Signed file written: %s" % dfu_file) else: usage() elif len(sys.argv) == 2: if sys.argv[1] == 'detach': import usb.core dfu = init_dfu() dfu.set_address(0x08000000) #Radio Application detach(dfu) elif sys.argv[1] == 'time': import usb.core dfu = init_dfu() print dfu.get_time() elif sys.argv[1] == 'reboot': import usb.core dfu = init_dfu() dfu.md380_custom(0x91, 0x01) #Programming Mode dfu.md380_custom(0x91, 0x01) #Programming Mode #dfu.md380_custom(0x91,0x01); #Programming Mode #dfu.drawtext("Rebooting",160,50); dfu.md380_reboot() elif sys.argv[1] == 'abort': import usb.core dfu = init_dfu() dfu.abort() else: usage() else: usage() except RuntimeError, e: print(e.args[0]) exit(1)