Simple USB Storage Read/Write?

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.
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Simple USB Storage Read/Write?

Post by xvedejas »

My kernel so far only has drivers for VGA and the keyboard. My kernel, however, will reside on a USB drive formatted with ext2. Obviously it will need to read/write to this drive, so I'm wondering what's the simplist approach to this? I don't need to implement any other types of USB hardware, so can this be simplified?

Mostly I'm asking for personal opinions about how I ought to approach this problem or links to help tackle it myself, since I haven't seen much on USB storage device drivers. If you could point me to the source of an existing kernel that does what I describe, that would also be helpful.

xv.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Simple USB Storage Read/Write?

Post by whowhatwhere »

xvedejas wrote:Mostly I'm asking for personal opinions about how I ought to approach this problem or links to help tackle it myself, since I haven't seen much on USB storage device drivers. If you could point me to the source of an existing kernel that does what I describe, that would also be helpful.
kernel.org? :mrgreen:
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Simple USB Storage Read/Write?

Post by Troy Martin »

Well, one of our newly-fleshed out articles will definitely help: USB :)

Of course, once the USB hub drivers and stuff has been implemented, I assume it's basically like using ATA controller. I have yet to implement this, but I hope these pointers (0x15DF6A52, 0x0017CAB5, haha) will help to find out how to do this.

Oh, and quite a few members have USB support, so they can most definitely give you advice.

Have fun,
--Troy
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
geppyfx
Member
Member
Posts: 87
Joined: Tue Apr 28, 2009 4:58 pm

Re: Simple USB Storage Read/Write?

Post by geppyfx »

If you are able to boot from USB then most likely it means USB is emulated by bios as FDD,HDD,ZIP or CD. Simplest way is to use BIOS int 13h. It means you have to switch back and forth between protected mode & 'unreal' mode.
The second simplest is to do what Troy Martin advised and write drivers.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Simple USB Storage Read/Write?

Post by Troy Martin »

geppyfx wrote:The second simplest is to do what Troy Martin advised and write drivers.
There's something that's less easy (I don't want to use the word "difficult" here, as I don't want to be bashed because I say writing drivers is hard :) ) than writing drivers? I always assumed that writing custom drivers was the hardest route, albeit most effective.

Am I missing something?
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Simple USB Storage Read/Write?

Post by xvedejas »

geppyfx wrote:If you are able to boot from USB then most likely it means USB is emulated by bios as FDD,HDD,ZIP or CD. Simplest way is to use BIOS int 13h. It means you have to switch back and forth between protected mode & 'unreal' mode.
The second simplest is to do what Troy Martin advised and write drivers.
I'd prefer to write my own driver and stay in protected mode. Also, I'm using grub to boot, if that makes any difference at all.

@Troy Martin:

Thanks, I'll definitely take a look at that. If anyone here *has* implemented what I describe as a simple driver, I'd love to see how they accomplished that.

@Syntropy:

Something a bit simpler, maybe? :wink:
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Re: Simple USB Storage Read/Write?

Post by madeofstaples »

Troy Martin wrote:Of course, once the USB hub drivers and stuff has been implemented, I assume it's basically like using ATA controller.
To access a USB mass storage device, the USB Mass Storage Class Specifications will probably help you more than the ATA/ATAPI specs... :wink:
xvedejas wrote:I'd prefer to write my own driver and stay in protected mode. Also, I'm using grub to boot, if that makes any difference at all.
The bootloader won't make a difference. I don't know if GRUB passes information to make it easier for the kernel to locate the USB device from which it was loaded, but that could be something helpful to look into. Otherwise, you'll need to write a simple PCI driver before you get into USB stuff.

I'm hoping to finish covering USB specifications in the wiki this weekend, and then making the entires for the different host controllers, but I can't make any promises on timeliness right now.
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.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Simple USB Storage Read/Write?

Post by kop99 »

If you're gonna implement IDE also, then you need to read following Wiki.
For PIO mode.
http://wiki.osdev.org/ATA_PIO_Mode
For DMA mode.
http://wiki.osdev.org/ATA/ATAPI_using_DMA
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Simple USB Storage Read/Write?

Post by xvedejas »

kop99 wrote:If you're gonna implement IDE also, then you need to read following Wiki.
For PIO mode.
http://wiki.osdev.org/ATA_PIO_Mode
For DMA mode.
http://wiki.osdev.org/ATA/ATAPI_using_DMA
I don't plan to implement IDE. Just USB for now and later SATA.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Simple USB Storage Read/Write?

Post by kop99 »

Obviously it will need to read/write to this drive, so I'm wondering what's the simplist approach to this?
I don't plan to implement IDE. Just USB for now and later SATA.
I think, you first usb bus driver, and then could control IDE controller.
USB is only communication protocol.
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Re: Simple USB Storage Read/Write?

Post by madeofstaples »

kop99 wrote:
Obviously it will need to read/write to this drive, so I'm wondering what's the simplist approach to this?
I don't plan to implement IDE. Just USB for now and later SATA.
I think, you first usb bus driver, and then could control IDE controller.
USB is only communication protocol.
As far as I know, any USB to IDE interface abstracts to a USB Mass Storage interface.
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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Simple USB Storage Read/Write?

Post by Brynet-Inc »

kop99 wrote:I think, you first usb bus driver, and then could control IDE controller.
USB is only communication protocol.
No. That's wrong, do some research before posting nonsense.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
octavio
Member
Member
Posts: 94
Joined: Wed Oct 25, 2006 5:12 am
Location: Barcelona España
Contact:

Re: Simple USB Storage Read/Write?

Post by octavio »

The usb drivers are by far the most dificult drivers i have written ,is about 20x dificult than a HD udma driver.
You can start by reading usb2.0 ,ehci and usb mass storage specifications,and also take a look at the sources of other Oses like
linux or Octaos.There are 3 usb controllers (uhci,ohci,ehci) but now most computers have ehci,so start with ehci.
Basically you have to create some data structures filled with scsi commands and pointers to the buffers.
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Simple USB Storage Read/Write?

Post by xvedejas »

No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Simple USB Storage Read/Write?

Post by earlz »

xvedejas wrote:No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...
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..
Post Reply