Simple USB Storage Read/Write?
Simple USB Storage Read/Write?
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.
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.
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
-
- Member
- Posts: 199
- Joined: Sat Jun 28, 2008 6:44 pm
Re: Simple USB Storage Read/Write?
kernel.org?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.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Simple USB Storage Read/Write?
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
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?
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.
The second simplest is to do what Troy Martin advised and write drivers.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Simple USB Storage Read/Write?
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.geppyfx wrote:The second simplest is to do what Troy Martin advised and write drivers.
Am I missing something?
Re: Simple USB Storage Read/Write?
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.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.
@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?
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
Re: Simple USB Storage Read/Write?
To access a USB mass storage device, the USB Mass Storage Class Specifications will probably help you more than the ATA/ATAPI specs...Troy Martin wrote:Of course, once the USB hub drivers and stuff has been implemented, I assume it's basically like using ATA controller.
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.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.
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.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
Re: Simple USB Storage Read/Write?
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
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?
I don't plan to implement IDE. Just USB for now and later SATA.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
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
Re: Simple USB Storage Read/Write?
Obviously it will need to read/write to this drive, so I'm wondering what's the simplist approach to this?
I think, you first usb bus driver, and then could control IDE controller.I don't plan to implement IDE. Just USB for now and later SATA.
USB is only communication protocol.
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
Re: Simple USB Storage Read/Write?
As far as I know, any USB to IDE interface abstracts to a USB Mass Storage interface.kop99 wrote:Obviously it will need to read/write to this drive, so I'm wondering what's the simplist approach to this?I think, you first usb bus driver, and then could control IDE controller.I don't plan to implement IDE. Just USB for now and later SATA.
USB is only communication protocol.
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.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Simple USB Storage Read/Write?
No. That's wrong, do some research before posting nonsense.kop99 wrote:I think, you first usb bus driver, and then could control IDE controller.
USB is only communication protocol.
Re: Simple USB Storage Read/Write?
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.
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?
No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
Re: Simple USB Storage Read/Write?
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..xvedejas wrote:No source code anyone? The Linux kernel isn't exactly the simplest piece of software ever written...