USB Pendrive - Read, Write operations development problem!!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
rahnzo
Posts: 4
Joined: Tue Nov 05, 2013 9:34 am

USB Pendrive - Read, Write operations development problem!!

Post 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!
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: USB Pendrive - Read, Write operations development probl

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
rahnzo
Posts: 4
Joined: Tue Nov 05, 2013 9:34 am

Re: USB Pendrive - Read, Write operations development probl

Post 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!
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: USB Pendrive - Read, Write operations development probl

Post 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
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
TomT
Member
Member
Posts: 42
Joined: Sat Mar 15, 2008 7:20 am
Location: Wisconsin, USA
Contact:

Re: USB Pendrive - Read, Write operations development probl

Post by TomT »

You may find some code here that will help you.
TomT

http://code.google.com/p/tatos/downloads/list
rahnzo
Posts: 4
Joined: Tue Nov 05, 2013 9:34 am

Re: USB Pendrive - Read, Write operations development probl

Post 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?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: USB Pendrive - Read, Write operations development probl

Post 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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
rahnzo
Posts: 4
Joined: Tue Nov 05, 2013 9:34 am

Re: USB Pendrive - Read, Write operations development probl

Post 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!
Post Reply