Page 1 of 2
Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 3:41 pm
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.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 3:57 pm
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?
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 4:01 pm
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
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 4:06 pm
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.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 4:13 pm
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?
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 4:59 pm
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?
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 5:26 pm
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...
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.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 7:08 pm
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
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 7:14 pm
by xvedejas
I don't plan to implement IDE. Just USB for now and later SATA.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 7:19 pm
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.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 7:34 pm
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.
Re: Simple USB Storage Read/Write?
Posted: Fri Jun 12, 2009 7:36 pm
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.
Re: Simple USB Storage Read/Write?
Posted: Sat Jun 13, 2009 5:36 am
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.
Re: Simple USB Storage Read/Write?
Posted: Mon Jun 15, 2009 9:25 pm
by xvedejas
No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...
Re: Simple USB Storage Read/Write?
Posted: Mon Jun 15, 2009 10:20 pm
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..