#!/usr/bin/env python # -*- coding: utf-8 -*- import usb.core import usb.util dev = usb.core.find(idVendor=0x0451, idProduct=0x9815) # was it found? if dev is None: raise ValueError('Device not found') # set the active configuration. With no arguments, the first # configuration will be the active one dev.set_configuration() # get an endpoint instance cfg = dev.get_active_configuration() # print cfg intf = cfg[(0,0)] ep = usb.util.find_descriptor( intf, # match the first OUT endpoint custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_OUT) assert ep is not None print ep bootData = file("boot.bin").read() msg = bytearray.fromhex('A1ACED01') msg += bytearray.fromhex('00000100') #entry address msg += bytearray.fromhex('%08x' % len(bootData)) #block length msg += bytearray.fromhex('00000020') #store address msg += bytearray.fromhex('00000000') head = file("head", "w") head.write(msg) head.close() ep.write(file("head").read()) ep.write(bootData)