OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 8:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Simple USB Storage Read/Write?
PostPosted: Mon Jun 15, 2009 10:57 pm 
Offline
Member
Member

Joined: Tue Apr 28, 2009 4:58 pm
Posts: 87
earlz wrote:
There so should be some community made, BSD or PD licensed USB drivers that are easily adaptable and capable of making the equivalent of a ugen device(generic usb stream device) with only a few lines of code and a plugin PCI driver..

that means copying old bugs and maybe poor desing

Mr/Ms xvedejas there are no handouts once you are past bootloader and entering protected mode. If there are any - the handouts will have their own bugs.

use BIOS(with its own bugs) if you need it done simple way
maybe you should do sata first, a lot less reading


Top
 Profile  
 
 Post subject: Re: Simple USB Storage Read/Write?
PostPosted: Tue Jun 16, 2009 1:49 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
And don't try to expect "simple" code when dealing with a device that isn't simple at all...

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Simple USB Storage Read/Write?
PostPosted: Tue Jun 16, 2009 8:57 am 
Offline
Member
Member

Joined: Thu Apr 12, 2007 8:15 am
Posts: 204
Location: Michigan
xvedejas wrote:
No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...


I don't think you understand what you're asking. If you consider the bare minimum required to "simply" read/write a USB mass storage class device, the list might look like this:

  • PCI enumeration, or, if applicable, the bootloader could ask the bios for the bus, device, and function numbers of the host controller (assuming the BIOS booted from a USB drive). Either way, basic PCI configuration space access is necessary to determine the type of host controller, possibly modify the command register, and to find the BAR.
  • Reset the host controller
  • Initialize the host controller.
  • For each port that detects a device connected:
    • Assert a reset signal, wait, then deassert the reset signal.
    • Assign a unique address to the device via it's default control pipe (requires implementing control transfers).
    • Retrieve a device descriptor. This may indicate if the device is a mass storage class device, OR it may indicate that you need to:
      • Retrieve a configuration descriptor for each possible configuration
      • Examine all interface descriptors associated with any configuration to determine if any of them are mass storage class interfaces
    • Any device that is a mass storage class device should be flagged or somehow recorded for later use.
  • At this point you have a list of directly-connected USB drives.
  • For each such device, then, you must:
    • Set the configuration to whichever configuration implements the mass storage class interface
    • The protocol specified by the device/interface descriptor determines how to communicate with the device, you can probably assume, for simplicity, that this will indicate a SCSI protocol.
    • Then, using the appropriate endpoint numbers (indicated in the interface descriptor), you must execute bulk transfers which wrap around the appropriate protocol in order to communicate with the device. The protocol defines how to go about read/write operations.

And that's not including the possibility of accessing a USB drive connected to a USB hub...

If you're patient, I will cover many of these things in greater detail in the wiki.

_________________
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.


Top
 Profile  
 
 Post subject: Re: Simple USB Storage Read/Write?
PostPosted: Tue Jun 16, 2009 12:06 pm 
Offline
Member
Member

Joined: Sat Mar 15, 2008 7:20 am
Posts: 42
Location: Wisconsin, USA
My OS has a protected mode driver for UHCI. This is the usb controller used on older computers with 2 usb ports on the back. Feel free to hack away. The folder /uhci contains about 20 files totaling 68,000 bytes of assembly code. Ive not attempted a driver for hard drives so not sure how much work that would be. There are other open source OS's with usb drivers. You just have to look.


I suggest downloading and studying the following:


For USB UHCI Universal Host Controller Driver Development:
*************************************************************************
[1] "Universal Serial Bus Mass Storage Class Bulk Only Transport", rev 1.0 Sept 1999 Usb Implementors Forum

[2] "Universal Serial Bus Specification", rev 1.1 1998 and rev 2.0, ch9 is most important

[3] Intel "82371AB PCI-ISA Xcelerator (PIIX4)" Controller Manual and "Universal Host Controller Interface (UHCI) Design Guide" rev 1.1, these are your hardware manuals

[4] "Working Draft American National Standard SCSI Block Commands (SBC-2)" Nov 2004 and the "SCSI Primary Commands (SPC-2)"

[5] "PCI Bios Spec" rev2.1

"Usb Simply Buffered Device Enumeration" and "Usb Simply Buffered Mass Storage Class - Bulk Only Transport" 2007 Shakthi Kannan, actual bytes from usb transactions

"USB Made Simple", web site with 7 part series.
"SnoopyPro" software for windows to view some usb transaction data.
LinuxBios usb_scsi_low.h
Beyond Logic "Usb in a Nutshell" excellent website
waste.org "PCI bus info and code from a programmers perspective"



TomT
http://code.google.com/p/tatos/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], KN9296 and 202 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group