GP2X More Usb Hacking


gfoot

Member
Joined
Nov 15, 2005
Messages
218
I was kind of worried about the data rates I've been seeing over the mass storage driver, and the fact that g_serial seemed to be collapsing under heavy load rather often. But less so now.

I've been playing with gadgetfs a bit, which is really quite neat. Essentially it provides user-space access to the USB port, allowing you to mess about with endpoints etc and use the USB protocols at a fairly low level. Since it's a 2.4 kernel, I expected a really old, experimental, and broken version to be in use, but it is actually a proper filesystem, which implies it's a more recent version. It's a surprise a day with GP2X Linux.

Like I said, gadgetfs really is a filesystem. Insert net2272 followed by gadgetfs, then mount it somewhere:

Code:
mount -t gadgetfs something_ignored /dev/gadget

/dev/gadget seems traditional (mkdir it first), but it works just as well on an SD card. Make sure you unmount the filesystem before removing the card though, or the kernel won't be able to unmount the SD's filesystem and you'll have to reboot or live without SD.

After mounting it, you get a "net2272" device node, which you can poke in various ways to gain access to its endpoints via separate files. You can make up your own VID/PID, supply a device descriptor, configurations, etc... all the complicated USB stuff that I don't really understand (props to http://www.beyondlogic.org/usbnutshell/usb1.htm though).

Anyway, enough of gadgetfs. I've also been playing with libusb-win32, which is very cool as well. It's a similar kind of thing for the host side of the link. It can create .inf files for arbitrary devices, and supplies a pretty raw hardware driver, allowing you to prod and poke from userspace. So far I've installed a driver for the non-ACM g_serial, testing against my test program on the gp2x (mary had a little lamb...), and the API is really simple - I've got it receiving fine, and sending too.

On the topic of sending, without performing any fancy configuration I'm seeing about 7Mbytes per second transfer rate from host to device, which seems really respectable. The max for USB full speed is 1.5 Mbytes per second, so it's beating that - implying it's actually running at high speed, which should have a theoretical maximum of 60 Mbytes per second. Still, 7's not bad IMHO.

I haven't actually checked the data integrity on reception, though as these were bulk transfers and no errors were flagged on the host, they should have got through ok. It's also possilbe that the receiving program itself is slowing the link down, as it's doing a silly amount of graphics every time it receives a character.

Promising stuff, anyway, and very easy to set up if anyone else wants to play with it.
 
You're doing some excellent work, gfoot. I don't understand some of it (USB is voodoo to me sometimes and I have no idea what ACM is), but I do see the potential in what you are doing.
 
Well done gfoot :) Now all we need to do is butcher up the source that shows a shell on the 2x's screen, redirect it to the pc, and allow loads of useful stuff in the background like file transfers, process view, gdb, etc...
 
Back
Top