X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fgoodfet.maxusbmass;h=0bda107ffe596f2c032b985b4a452f71609e9d44;hp=de25c6ef0c08baed2ab67bdb290b1de177a9f520;hb=3ce12eeaf2628956df8b10ebf0e2824a229cdc93;hpb=b41a0644a0777cb50ff080b8f8c3995f6ee19183 diff --git a/client/goodfet.maxusbmass b/client/goodfet.maxusbmass index de25c6e..0bda107 100755 --- a/client/goodfet.maxusbmass +++ b/client/goodfet.maxusbmass @@ -11,6 +11,17 @@ import time; from GoodFETMAXUSB import *; + +# This constant is kinda complicated and very ugly. The idea is that +# if we take too long in any given transaction, the host will abort. +# How many blocks we can send depends upon timeouts on both sides, +# with (at least in Linux) the behavior that aborting early causes the +# disk to reset with only warning and no real errors. Somewhere +# there's a way to provide this constant to the host, in which case +# stalling and waiting for a reset will no longer be necessary. + +MAXBLOCKSPERTRANSFER=128 + def zeros(length): """Returns a list of zeroes of the specified length.""" l=range(0,length); @@ -284,7 +295,7 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice): #print "Responding to CB inquiry."; response=[ 0x00, # 00 for Direct, 1F for "no floppy" - 0x80, # make 0x80 for removable media + 0x80, # make 0x80 for removable media, 0x00 for fixed 0x00, # Version 0x01, # Response Data Format 0x1f, #Additional length. @@ -297,6 +308,8 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice): ord('0'),ord('.'),ord('0'),ord('1')] #print "Sending %i byte reply to %i byte query." % ( # len(response),dtlen); + while len(response)32: + if count>MAXBLOCKSPERTRANSFER: count=0; - status=1; #Fail if we're asked to read more than 32 blocks. + #status=1; #Fail if we're asked to read more than 32 blocks. #Now we need to stall EP3. It's not acceptable to just forget to transmit. self.wreg(rEPSTALLS,0x10); + return; for i in range(0,count): data=self.getSectorData(baselba+i); - for j in range(0,8): - #print "Sending block fragment %i,%i" % (i,j); - #Transmit each 64-byte block fragment, then wait for next. - while not(self.rreg(rEPIRQ)&bmIN3BAVIRQ): pass; - response=data[j*64:j*64+64]; - self.writebytes(rEP3INFIFO, - response); - self.wregAS(rEP3INBC, - 64); + self.fifo_ep3in_tx(data); + + # for j in range(0,8): + # #print "Sending block fragment %i,%i" % (i,j); + # #Transmit each 64-byte block fragment, then wait for next. + # while not(self.rreg(rEPIRQ)&bmIN3BAVIRQ): pass; + # response=data[j*64:j*64+64]; + # self.writebytes(rEP3INFIFO, + # response); + # self.wregAS(rEP3INBC, + # 64); #sys.exit(); elif verb==0x2A: #WRITE SECTOR print "Haven't implemented WRITE SECTOR."; #sys.exit(); + elif verb==0x1B: #EJECT/RETRACT DISK + print "Haven't implemented SCSI Start Stop Unit Command (1B)"; + print "https://en.wikipedia.org/wiki/SCSI_Start_Stop_Unit_Command"; + #sys.exit(); else: print "ERROR: Unknown SCSI command block verb %02x." % verb; - status=1; #Command Failed + status=0x02; #Command Failed if dtlen>0: print "Sending %i bytes of dummy data here." % dtlen; self.fifo_ep3in_tx(zeros(dtlen)); @@ -461,6 +482,7 @@ class GoodFETMAXUSBMassFile(GoodFETMAXUSBMass): self.datafilelen%512); sys.exit(); return self.datafilelen/512-1; + if(len(sys.argv)==1): print "Usage: %s disk.img\n" % sys.argv[0]; sys.exit();