Author Topic: MSD: READ_CAPACITY(10) command fails  (Read 10492 times)

erdmann

  • Member
  • ***
  • Posts: 43
MSD: READ_CAPACITY(10) command fails
« on: December 05, 2016, 07:15:25 am »
This is driving me nuts:
I am having trouble with some SanDisk Cruzer Memory stick. I send it the READ_CAPACITY(10) command and it fails the data transfer Phase (8 Bytes of result info: LSB of last sector, sector size) with Input pipe stall which requires me to reset the IN endpoint (according to MSD spec). I then do the "read CSW" to properly finish the BBB Transmission protocol which works ok (but of course I did not get data in the first place). I then do a REQUEST_SENSE command which tells me that everything is fine (ha ha ha ...).

For any other USB stick or USB hard disk (well I tried about 10 different devices, "any other" is a relative term ...), the READ_CAPACITY(10) command works just fine and returns expected results (for example, it should return 512 for sector size or maybe 4096 for future devices). And if not, I would expect that a REQUEST_SENSE should tell me that SOMETHING went wrong.

What in the world makes this stick so different ? Are there either any unspoken timing issues or unknown command sequence mysteries to follow ?
I am beginning to believe that I have to precede the READ_CAPACITY(10) command with some other command for getting it to work (on this device). Maybe TEST_UNIT_READY command ? Does anyone know of any undocumented expectations of what commands can follow what other commands ?

USB MSD devices are a pain in the rear. They all behave a bit differently.


Lars

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: MSD: READ_CAPACITY(10) command fails
« Reply #1 on: December 05, 2016, 12:44:00 pm »
If you are developing a host, the safest path is to observe the sequence of commands and events that Windows uses and emulate that.

Also see "Debugging" here:

http://janaxelson.com/mass_storage.htm

I agree that mass storage devices are difficult - they often don't comply fully with the specs.

erdmann

  • Member
  • ***
  • Posts: 43
Re: MSD: READ_CAPACITY(10) command fails
« Reply #2 on: December 05, 2016, 02:09:47 pm »
Forgot to mention:
The READ_CAPACITY command is directly preceded by an INQUIRY command that sucessfully terminates for all but one device that I have trace info for.

I am now beginning to believe that some devices require to COMPLETELY get all the data from them that they can deliver. After I attempted to read 128 bytes of inquiry data almost all devices are happy to return more than the 0x24 = 36 bytes that are the minimum. Additionally almost all devices do not return the correct value for "residuum" in the CSW block (almost all of them get it wrong). Some return 0 bytes even though I asked for more than they could deliver, others return a residuum > 0 but still return as much data as I asked for (I guess with garbage appended ...).
Funny enough, asking for more than 0xFF bytes (if allocation length field becomes 2 bytes) will lead to errors for some devices and they won't return any inquiry data even though they claim that everything was ok ...

Am I right in saying that this is all trial and error  and you cannot rely on anything but your gut feeling ?

Lars

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: MSD: READ_CAPACITY(10) command fails
« Reply #3 on: December 05, 2016, 03:25:51 pm »
The best advice I know of is to imitate Windows since virtually all devices are tested under Windows. Also see the documented Linux workarounds:

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/storage/unusual_devs.h?id=f9b4192923fa6e38331e88214b1fe5fc21583fcc



erdmann

  • Member
  • ***
  • Posts: 43
Re: MSD: READ_CAPACITY(10) command fails
« Reply #4 on: December 06, 2016, 03:26:03 am »
Ok, thanks for the link. Seems that I am not alone with this problem ...