Author Topic: Design of a Host Driver which would detect all Pendrives  (Read 13404 times)

SAJEEV

  • Member
  • ***
  • Posts: 3
Design of a Host Driver which would detect all Pendrives
« on: November 22, 2010, 06:28:20 am »
Hi Jan,

We have developed USB Host(On the Go) Driver with Cypress Microcontroller. It is finely working with most of the Pendrives available in the market.
But some of the Pendrives are not getting detected by the Driver.

When we check it would be seen that, Read Master Boot command getting failed.
Then we checked the same Pendrive with Windows OS. It is getting detected. We examined the USB Trace of it. For Windows OS also, at first Read Master Boot command is getting failed.
Then following a sequence of commands,  Read Master Boot command is retried 8 times. 7 times it got failed in the same way. Only in the 8th times it is getting passed.
When I do the same procedure in our drive it is also working.
So now our Driver also is able to detect that Pendrive. But why Read Master Boot command is getting failed 7 times and passed in 8th attempt?
How this can be explained?
This is just an example. Some other Pendrives are having some other kinds of response.
By comparing with Windows OS, we are continuously updating our host driver. 
 
Is there any guide or book which is describing the sequence in which the SCSI commands to be given to a USB slave device?
Or For designing a USB Host driver which would detect all the Pendrives in the market, what is the sequence of commands, I need to follow?
All the Pendrives are getting detected by Windows OS. Is there any document available which is mentioning the command sequence followed by the Windows OS in detecting the Pendrives.

Expecting your valuable reply,
Thanks in advance,
Sajeev   

   

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Design of a Host Driver which would detect all Pendrives
« Reply #1 on: November 22, 2010, 08:59:00 am »
Yes, apparently many drives are designed so they will work under Windows without much concern about complying with all of the requirements of the mass-storage spec.

My links under Debugging here might help:

http://www.lvr.com/mass_storage.htm

Jan

SAJEEV

  • Member
  • ***
  • Posts: 3
Re: Design of a Host Driver which would detect all Pendrives
« Reply #2 on: November 24, 2010, 04:33:40 am »
Hi Jan,

Thank you for the reply.

The links provided you helped me a lot.
It is a valuable information, that there are so many Pendrives in the market which is not compliance with USB specifications.

But the Pendrive under consideration in our case is one of the Transcend 4GB Pendrives.

Usually the sequence in which SCSI commands are given by our USB Host(On the Go) Driver to a Pendrive is as shown below.

Inquiry,Read Format Capacity,Read Capacity,Mode Sense(1c),Mode Sense(3f),Read Master Boot,Read Partition Boot and then SCSI Write commands to write data into Pendrive. Definitely Stall,Unsupported commands, No Data, Less Data etc. are considered.

Now let me give the sequence of SCSI commands for the above mentioned Sandisk 4GB Pendrive to work.
Inquiry,Read Format Capacity,Read Capacity,Mode Sense(1c),Mode Sense(3f),Read Master Boot(1st time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Mode Sense(1c),Mode Sense(3f), Read Capacity,Read Capacity, Read Master Boot(2nd time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Read Master Boot(3rd time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Read Capacity,Read Capacity,Read Master Boot(4th time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Get Descriptor from Device(Control Transfer),Test Unit Ready(Failed),Request Sense,Read Capacity,Read Capacity,Read Capacity,Read Capacity,Read Master Boot(5th time,Passed),Read Partiotion Boot,
then SCSI Write commands to write data into Pendrive

Here for the first 4 times, Read Master Boot Data stage would be stalled by the device( less data case), But CSW stage would be passed. But with 1 as the CSW status byte.  In USBTRACE this would be appeared as  SYNC RESET PIPE &CLEAR.

Why it is happening so?

Initially it is failed, after following the above sequence it is getting passed.  Is it because of the Test Unit Ready command, it is passed? What might be happening in Pendrive in this case?

Basically what should be the sequence of SCSI commands from Host to Device?
When a Test Unit Ready command need to be given?
Why a Read Capcity command is repeated so many times?(observed in Windows OS driver)
If One device is failed with One command, how many times to be retried, before declaring "Non supported Pemdrive".   

Expect your valuable reply,

regards,
Sajeevan.K






   



 
 

 


SAJEEV

  • Member
  • ***
  • Posts: 3
Re: Design of a Host Driver which would detect all Pendrives
« Reply #3 on: November 24, 2010, 04:38:41 am »
Hi Jan,

Thank you for the reply.

The links provided by you helped me a lot.
It is a valuable information, that there are so many Pendrives in the market which is not compliance with USB specifications.

But the Pendrive under consideration in our case is one of the Transcend 4GB Pendrives.

Usually the sequence in which SCSI commands are given by our USB Host(On the Go) Driver to a Pendrive is as shown below.

Inquiry,Read Format Capacity,Read Capacity,Mode Sense(1c),Mode Sense(3f),Read Master Boot,Read Partition Boot and then SCSI Write commands to write data into Pendrive. Definitely Stall,Unsupported commands, No Data, Less Data etc. are considered.

Now let me give the sequence of SCSI commands for the above mentioned Sandisk 4GB Pendrive to work.
Inquiry,Read Format Capacity,Read Capacity,Mode Sense(1c),Mode Sense(3f),Read Master Boot(1st time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Mode Sense(1c),Mode Sense(3f), Read Capacity,Read Capacity, Read Master Boot(2nd time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Read Master Boot(3rd time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Read Capacity,Read Capacity,Read Master Boot(4th time,Failed,Showing SYNC RESET PIPE &CLEAR),Request Sense,Get Descriptor from Device(Control Transfer),Test Unit Ready(Failed),Request Sense,Read Capacity,Read Capacity,Read Capacity,Read Capacity,Read Master Boot(5th time,Passed),Read Partiotion Boot,
then SCSI Write commands to write data into Pendrive

Here for the first 4 times, Read Master Boot Data stage would be stalled by the device( less data case), But CSW stage would be passed. But with 1 as the CSW status byte.  In USBTRACE this would be appeared as  SYNC RESET PIPE &CLEAR.

Why it is happening so?

Initially it is failed, after following the above sequence it is getting passed.  Is it because of the Test Unit Ready command, it is passed? What might be happening in Pendrive in this case?

Basically what should be the sequence of SCSI commands from Host to Device?
When a Test Unit Ready command need to be given?
Why a Read Capcity command is repeated so many times?(observed in Windows OS driver)
If One device is failed with One command, how many times to be retried, before declaring "Non supported Pemdrive".   

Expect your valuable reply,

regards,
Sajeevan.K






   



 
 

 


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Design of a Host Driver which would detect all Pendrives
« Reply #4 on: January 05, 2011, 09:44:26 pm »
I have no simple answer. Some drives are temperamental. The host driver can either try to accommodate these drives or refuse to communicate if they don't comply with the standard.

Jan

nvd

  • Member
  • ***
  • Posts: 42
Re: Design of a Host Driver which would detect all Pendrives
« Reply #5 on: April 26, 2013, 06:22:11 am »
Hi,
 I was searching for information on Transcend 4Gb drive issues with Embedded host and stumbled upon this thread hence asking this question.

 I am finding that READ_CAPACITY(10) command is always stalled by this drive when I try it from my Embedded host.
 Same command passes with Windows though.
 
 This seems so strange....any inputs on this?
 I can communicate with other devices without a problem.

Regards,
Nitin

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Design of a Host Driver which would detect all Pendrives
« Reply #6 on: April 26, 2013, 01:17:45 pm »
What does your host do differently from the way Windows does it?

As noted a lot of devices like this seem to be programmed to respond to exactly the sequence that Windows sends them, and not respond to anything else. This is where you need a hardware bus analyser to see what's actually going on.

nvd

  • Member
  • ***
  • Posts: 42
Re: Design of a Host Driver which would detect all Pendrives
« Reply #7 on: April 28, 2013, 11:53:17 pm »
Hi,
 Found that some of the devices report UNIT ATTENTION condition on detection. (Not sure of the exact reason)
 When UNIT ATTENTION condition exists, any command other than INQUIRY and Test_Unit_Ready is stalled.
 
 If Test_Unit_Ready command is issued, some devices report FAIL status and clear the UNIT ATTENTION condition.
 After this any other command will work as normal.

 However, some devices do not clear UNIT ATTENTION condition after Test_Unit_Ready. They clear it after REQUEST_SENSE command.
 
 so to be able to access different devices the sequence of commands which works for me is.....INQUIRY -- TUR -- if this fails....REQUEST_SENSE (Take action according to sense data or ignore it).....again TUR....this should PASS....then READ_CAPACITY and other commands as required.

  Seems like windows does what actually is expected to be done :)

NVD
« Last Edit: April 29, 2013, 05:51:25 am by nvd »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Design of a Host Driver which would detect all Pendrives
« Reply #8 on: April 29, 2013, 10:43:09 am »
Good to hear you got it working. Thanks for reporting what you found.