Page 1 of 1

USB Pendrive - Read, Write operations development problem!!

Posted: Tue Nov 05, 2013 11:21 am
by rahnzo
Hi all,

I am working on an own operating system, developing a driver to interact with a device of type Pen Drive. Currently I try to read or write to the device.
The device used to make tests is a brand Pen Drive Kingston, and the model is the "DataTraveller DT 101". My research suggests me that I need to make transactions is the BOT protocol(Bulk Only Transport)
I am lost here and do not know where to start. I can't find generic examples of how to create the CBW and make communication with the device (for starters). Someone would have some example or any idea how to begin implementing a read or write operations to a device pendrive? The operating system that I work, only works with UHCI.

Thanks a lot!

Re: USB Pendrive - Read, Write operations development probl

Posted: Tue Nov 05, 2013 8:09 pm
by thepowersgang
Sadly, this is a lot harder than you'd expect.

"Pen drives" are usually USB disks. This means you need a USB stack (including *HCI driver and the USB layer atop it), a MSC driver, and SCSI atop that, before you can read/write the drive.

(This isn't actually too much code, but it's conceptually quite a bit to take in and design)

I'd suggest reading up on UHCI and OHCI, then the enumeration section of the USB 1.1 spec, and finally the MSC spec.

Re: USB Pendrive - Read, Write operations development probl

Posted: Tue Nov 05, 2013 9:52 pm
by rahnzo
Yes, the USB driver is currently running. I've gotten the device is recognized and stored in a specific structure representing the usb device all the information of the same, including the endpoints needed for communication. The fact is that after this, I am lost on how to send the data to the device. I need to use SCSI technology to perform a read or write? I need to perform reading or writing in the simplest way possible. Besides, no one has the piece of code where exactly is done sending data to the device? (assuming that I have developed throughout the rest of the driver)

Thanks!

Re: USB Pendrive - Read, Write operations development probl

Posted: Wed Nov 06, 2013 4:15 am
by thepowersgang
It's pretty simple actually, only about 300 lines (and most of that chaff)

You create a MSC "CBW" with the SCSI command, send it and wait for the data and status.

https://github.com/thepowersgang/acess2 ... es/USB/MSC

Re: USB Pendrive - Read, Write operations development probl

Posted: Wed Nov 06, 2013 11:35 am
by TomT
You may find some code here that will help you.
TomT

http://code.google.com/p/tatos/downloads/list

Re: USB Pendrive - Read, Write operations development probl

Posted: Wed Nov 06, 2013 2:48 pm
by rahnzo
Thank you very much! I thought to send SCSI commands needed to have connected the flash drive to a SCSI device, instead of the usual connection to the hub. Then I can send SCSI commands to a flash drive that is connected directly to any motherboard, right?

Re: USB Pendrive - Read, Write operations development probl

Posted: Wed Nov 06, 2013 10:42 pm
by thepowersgang
"connected directly to any motherboard" - What do you mean by that?

The SCSI command set does not have to go via a SCSI bus. There's a protocol for sending SCSI commands over TCP/IP (iSCSI iirc) and it's also used for most USB mass storage devices)

Re: USB Pendrive - Read, Write operations development probl

Posted: Thu Nov 07, 2013 12:05 pm
by rahnzo
Sorry for my English! I meant that if I could read or write SCSI commands without using the flash drive connected to a SCSI interface. I thought SCSI commands read / write could be used only if you have installed on the motherboard SCSI card.

But thanks to you, I understood that I can use SCSI commands to transfer without any special hardware device.

According to my research, for writing / reading to cbw should be sent. CBW structure must contain within the CBD (command descriptor block). There are different types of CBD? I just found it that the CBD is a SCSI command.

Thanks a lot thepowersgang!