USB2.0 mass storage device
USB2.0 mass storage device
EHCI and USB 2.0 works. Based on control transfers, the OS can fetch descriptors and parse them. As next step I want to read sectors out of an attached USB stick. As far as I have seen, the usb stick belongs to the interface subclass "SCSI". Can you give me some advice how to implement the necessary SCSI support. How is this done as good practice?
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
Here is my CBW CommandBlockWrapper for the SCSI Inquiry request.
take a look at tatOS/usb/inquiry.s and also other files in that directory.
See the /docs directory for a list of resources. I found these documents useful:
[6] "Working Draft American National Standard SCSI Block Commands (SBC-2)"
Nov 2004 and the "SCSI Primary Commands (SPC-2)"
Good luck,
TomT
http://code.google.com/p/tatos/
;Command Block Wrapper for SCSI Inquiry (31 bytes)
InquiryRequest:
dd 0x43425355 ;dCBWSignature
dd 0xaabbccdd ;dCBWTag (device will copy this into CSW)
dd 0x24 ;dCBWDataTransferLength (for tdData)
db 0x80 ;bmCBWFlags 0x80=Device2Host, 00=Host2Device
db 0 ;bCBWLun
db 6 ;bCBWCBLength (of CBWCB)
;CBWCB (16 bytes) see SCSI Inquiry Command
db 0x12 ;SCSI operation code
db 0 ;SCSI reserved
db 0 ;SCSI page or operation code
db 0 ;SCSI reserved
db 0x24 ;SCSI allocation length
db 0 ;SCSI control
times 15 db 0 ;USBmass CBWCB must be 16 bytes long (we add alittle extra 0)
take a look at tatOS/usb/inquiry.s and also other files in that directory.
See the /docs directory for a list of resources. I found these documents useful:
[6] "Working Draft American National Standard SCSI Block Commands (SBC-2)"
Nov 2004 and the "SCSI Primary Commands (SPC-2)"
Good luck,
TomT
http://code.google.com/p/tatos/
;Command Block Wrapper for SCSI Inquiry (31 bytes)
InquiryRequest:
dd 0x43425355 ;dCBWSignature
dd 0xaabbccdd ;dCBWTag (device will copy this into CSW)
dd 0x24 ;dCBWDataTransferLength (for tdData)
db 0x80 ;bmCBWFlags 0x80=Device2Host, 00=Host2Device
db 0 ;bCBWLun
db 6 ;bCBWCBLength (of CBWCB)
;CBWCB (16 bytes) see SCSI Inquiry Command
db 0x12 ;SCSI operation code
db 0 ;SCSI reserved
db 0 ;SCSI page or operation code
db 0 ;SCSI reserved
db 0x24 ;SCSI allocation length
db 0 ;SCSI control
times 15 db 0 ;USBmass CBWCB must be 16 bytes long (we add alittle extra 0)
Re: USB2.0 mass storage device
@TomT:
thank you very much for this link to tatOS, great work! what ist the reason for this order of the commands in your OS? Where can I find the original spec for this procedure?
@all:
Is there no Hobby-OS with USB2/SCSI for Mass Storage Devices (MSD) written in C? We have some code working, but with some errors, which we do not understand regarding the root causes. If somebody is interested in this area I invite him/her to help us. Control Transfers work great, it is the area of bulk transfers causing some trouble and instability.
Source Code: http://prettyos.svn.sourceforge.net/vie ... z?view=tar (comments English) please look at ehci.c and usb2.c
chat: irc.euirc.net #PrettyOS (we speak English)
forum: http://www.c-plusplus.de/forum/viewforu ... is-62.html (German)
thank you very much for this link to tatOS, great work! what ist the reason for this order of the commands in your OS? Where can I find the original spec for this procedure?
Code: Select all
STDCALL mpdstr16,putmessage
call SetAddress
STDCALL mpdstr17,putmessage
call SetConfiguration
;now we start on the SCSI commands
;the order of the commands and redundancy is important
;we init the flash toggles here and then let prepareTDchain touch them only
mov dword [bulktogglein] ,0
mov dword [bulktoggleout],0
STDCALL mpdstr18,putmessage
call Inquiry
STDCALL mpdstr19,putmessage
call TestUnitReady
STDCALL mpdstr20,putmessage
call RequestSense
STDCALL mpdstr19,putmessage
call TestUnitReady
STDCALL mpdstr20,putmessage
call RequestSense
STDCALL mpdstr21,putmessage
call ReadCapacity
;done-ready for read10/write10
STDCALL mpdstr22,putmessage
mov dword [FLASHDRIVEREADY],1
Is there no Hobby-OS with USB2/SCSI for Mass Storage Devices (MSD) written in C? We have some code working, but with some errors, which we do not understand regarding the root causes. If somebody is interested in this area I invite him/her to help us. Control Transfers work great, it is the area of bulk transfers causing some trouble and instability.
Source Code: http://prettyos.svn.sourceforge.net/vie ... z?view=tar (comments English) please look at ehci.c and usb2.c
chat: irc.euirc.net #PrettyOS (we speak English)
forum: http://www.c-plusplus.de/forum/viewforu ... is-62.html (German)
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
Currently, the biggest problem is that we can carry out one SCSI command perfectly at a real PC (VMWare already works great) , but as soon as a second SCSI command follows, the asynchronous scheduler does not carry out the qH and qTD connected to the IN endpoint. As said, control transfers and the first SCSI command work great.
http://prettyos.svn.sourceforge.net/vie ... z?view=tar
Does anybody have a clear sequence how to manage the async scheduler?
Problem solved.
But I would appreciate to communicate to other people working on this complex area.
EDIT: currently, our EHCI / USB 2.0 / MSD/SCSI driver works well. Mainly handshake and toggle problems during bulk transfer.
http://prettyos.svn.sourceforge.net/vie ... z?view=tar
Does anybody have a clear sequence how to manage the async scheduler?
Problem solved.
But I would appreciate to communicate to other people working on this complex area.
EDIT: currently, our EHCI / USB 2.0 / MSD/SCSI driver works well. Mainly handshake and toggle problems during bulk transfer.
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
I have plans to implement this in the "near future". I have working USB-stacks for UHCI and OHCI, and experimental for EHCI, but I found the mass-storage class to lack in documentation (the SCSI part). I also have the FAT-file systems implemented and relatively bug-free under ATA/IDE.
Links to "easy-to-follow" code for how the SCSI part works would be appreciated. The rest seems to be well described in mass storage class in the USB documentation.
Links to "easy-to-follow" code for how the SCSI part works would be appreciated. The rest seems to be well described in mass storage class in the USB documentation.
Re: USB2.0 mass storage device
Wikipedia is your friend: http://en.wikipedia.org/wiki/SCSI_command . Have fun .rdos wrote:I have plans to implement this in the "near future". I have working USB-stacks for UHCI and OHCI, and experimental for EHCI, but I found the mass-storage class to lack in documentation (the SCSI part). I also have the FAT-file systems implemented and relatively bug-free under ATA/IDE.
Links to "easy-to-follow" code for how the SCSI part works would be appreciated. The rest seems to be well described in mass storage class in the USB documentation.
Re: USB2.0 mass storage device
The most important thing is that inside the SCSI command MSB comes first!
Try the sequence: inquiry - test unit ready - request sense - test unit ready - request sense - read capacity - read ...
No handshakes (HC does the ACK alone), switch data toggle per endpoint after each packet transfer or use setconfig(1) before each transfer, if you want to start with toggle 0.
There is a spec for usb MSD: "Universal Serial Bus Mass Storage Class Bulk-Only Transport" Rev. 1.0, September 31, 1999
http://www.usb.org/developers/devclass_ ... ulk_10.pdf
Have fun!
Links to "easy-to-follow" code for how the SCSI part works would be appreciated <--- http://prettyos.svn.sourceforge.net/vie ... usb2_msd.c
I would appreciate a co-worker or at least an experience exchange on this complex topic.
Try the sequence: inquiry - test unit ready - request sense - test unit ready - request sense - read capacity - read ...
No handshakes (HC does the ACK alone), switch data toggle per endpoint after each packet transfer or use setconfig(1) before each transfer, if you want to start with toggle 0.
There is a spec for usb MSD: "Universal Serial Bus Mass Storage Class Bulk-Only Transport" Rev. 1.0, September 31, 1999
http://www.usb.org/developers/devclass_ ... ulk_10.pdf
Have fun!
Links to "easy-to-follow" code for how the SCSI part works would be appreciated <--- http://prettyos.svn.sourceforge.net/vie ... usb2_msd.c
I would appreciate a co-worker or at least an experience exchange on this complex topic.
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
OK, thanks for the info. I will get back to this at some point, but it might take a few months. I'll code it in assembly, so it will probably not be easy-to-read code. Currently, I have USB-code for various serial to USB adapters, as this is what I currently need for our professional payment terminal.
Re: USB2.0 mass storage device
Some people think that "test unit ready" is not necessary. The device has to be "ready".
What does that mean, if "Request Sense" shows "Sense data are not SCSI compliant" in the "Valid" information?
What does that mean, if "Request Sense" shows "Sense data are not SCSI compliant" in the "Valid" information?
Last edited by ehenkes on Mon May 24, 2010 9:11 am, edited 1 time in total.
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
In openSolaris an interesting "quick guide" can be found in http://cvs.opensolaris.org/source/xref/ ... bulkonly.c
cf.: http://www.c-plusplus.de/forum/viewtopi ... is-76.html
cf.: http://www.c-plusplus.de/forum/viewtopi ... is-76.html
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: USB2.0 mass storage device
I can recommend Jan Axelson's book "usb mass storage". Above all, here you can meet the author and other developers in this new forum:
http://www.lvr.com/forum/index.php?topic=14.0
http://www.lvr.com/forum/index.php?topic=14.0
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS