OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Nov 19, 2019 4:59 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: USB2.0 mass storage device
PostPosted: Sat Apr 24, 2010 6:23 am 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Mon Apr 26, 2010 11:44 am 
Offline
Member
Member

Joined: Sat Mar 15, 2008 7:20 am
Posts: 42
Location: Wisconsin, USA
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)


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Sun May 02, 2010 1:39 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
@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?
Code:
   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


@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)

_________________
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Fri May 07, 2010 4:21 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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. :D

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


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Fri May 14, 2010 6:39 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2204
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.


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Fri May 14, 2010 8:07 am 
Offline
Member
Member

Joined: Fri Aug 01, 2008 7:52 am
Posts: 248
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.


Wikipedia is your friend: http://en.wikipedia.org/wiki/SCSI_command . Have fun :D .


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Fri May 14, 2010 12:00 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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. :wink:

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! :D


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


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Fri May 14, 2010 2:07 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2204
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.


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Sat May 15, 2010 1:21 am 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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?

_________________
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS


Last edited by ehenkes on Mon May 24, 2010 9:11 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Sun May 16, 2010 2:11 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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

_________________
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS


Top
 Profile  
 
 Post subject: Re: USB2.0 mass storage device
PostPosted: Tue Jun 01, 2010 4:22 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
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 :D

_________________
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group