GP2X Usb Gadget Serial Drivers For Gp2x


gfoot

Member
Joined
Nov 15, 2005
Messages
218
This is the USB Gadget Serial module from a 2.6 kernel, backported to work with the 2.4.25 kernel the GP2X uses. Note that I don't really know what I'm doing, I just blundered along until it worked!

http://www.glost.eclipse.co.uk/gfoot/gp2x/...dget_serial.zip

The zip contains a prebuilt module, a test program, instructions, and sources to both.

Currently it works fine with the test program, but I haven't had any success bringing up a shell yet - I tried running getty on /dev/ttygs0, and I can see the banner in minicom, but it doesn't seem to run the login program (or the login program can't read the tty). Shrug, my test program works fine. :) If anyone can get to the bottom of this, it would be very cool.

Windows users won't be able to use this yet, unless you fancy backporting a more recent version of the gadget serial driver. The Windows drivers require something called ACM, and it's not supported by this version. When you've done that, read the instructions in Documentation/usb/gadget_serial.txt in your 2.6 kernel source - it has a .inf file for Windows to recognize the device.

For me, in Linux, a device called /dev/ttyUSB0 gets automatically created, and I just connect minicom to it. Turn off hardware flow control, and delete any modem init/reset commands. I also use 38400 8/N/1, but that was the default anyway.

Enjoy!
 
I've updated the archive with a version that supports ACM, so it works on Windows now.
 
So this maps the first UART serial port to a simulated USB UART.

No more serial cables then.

Also I think you must press some key combo to get a login prompt...
 
With a serial cable you just wait until it's finished booting then press ctrl-c to kill off gp2xmenu to get shell access. Don't know if this works in the same way with your usb set up though (no usb cable here).
 
It doesn't touch the UARTs - it just adds a new tty device running over the USB port (the official one that you use for mass storage access). There's no magic key combination - if you want something to run on the GP2X end of the link, you have to run it just like any other program. Otherwise your PC is just talking to nothing. :)

It's pretty easy to run bash though, and you can then run your program from bash and see its output on your PC. There are some issues (Ctrl-C doesn't work for example) but it's really useful, even so.

I'd like to work on a decent debug monitor, with file uploads, killing the running app, restarting it, etc. Debugging is an interesting case - running the app in gdb is probably a good start, at least. Building gdb for the gp2x might not be fun though.
 
Thanks a lot for doing this port!

Unfortunately I am new to serial devices in linux. Could you provide more information on how to set up the communication on the (USB) host side?

The kernel's documentation says it should all work by loading the usbserial driver (and creating a character device (mknod foo c 188 0)). However doing a cat or echo to this device fails because it says the device does not exist.

This is Kernel 2.6.14 btw.
 
Thanks a lot for doing this port!

Unfortunately I am new to serial devices in linux. Could you provide more information on how to set up the communication on the (USB) host side?

The kernel's documentation says it should all work by loading the usbserial driver (and creating a character device (mknod foo c 188 0)). However doing a cat or echo to this device fails because it says the device does not exist.

This is Kernel 2.6.14 btw.

In 2.6.14 when the usbgadget module on your PC sees the gp2x (Usually right when you've loaded the modules on the gp2x) it will create /dev/ttyUSB0 without you having to do mknod on anything.

From there you can run something against /dev/ttyUSB0 like getty or bash.
 
Last edited by a moderator:
In 2.6.14 when the usbgadget module on your PC sees the gp2x (Usually right when you've loaded the modules on the gp2x) it will create /dev/ttyUSB0 without you having to do mknod on anything.

From there you can run something against /dev/ttyUSB0 like getty or bash.
On my system this did not work automagically. I had to load the usbserial kernel module as such
Code:
modprobe usbserial product=0xa4a7 vendor=0x0525
.

Then dmesg said it was attached to USB0 and I could exchange data.

Great stuff!
 
Last edited by a moderator:
Hmm, it ought to be /dev/ttyACM0, unless you load the module in non-ACM mode. I'm pretty sure I set the default to ACM though...

Anyway, so long as it works, eh? On my laptop everything is autodetected, I guess Debian just rocks.
 
Hmm, it ought to be /dev/ttyACM0, unless you load the module in non-ACM mode. I'm pretty sure I set the default to ACM though...

Anyway, so long as it works, eh? On my laptop everything is autodetected, I guess Debian just rocks.

Ah, I was using the previous version without ACM. Now I'm using the newer one, I can get everything setup. Screen detects the serial connection, logs in dmesg on the host and the client, but I am yet to get any kind of shell, with either getty (TinyLogin) or piping input into and out from bash to the tty.
Is anyone able to do this yet?
 
Last edited by a moderator:
Renamed (.gpu) and changed the bash example as follows:

Code:
bash-2.05a# cat bash.gpu
#!/bin/sh

rm log.txt

sync

function log()
{
        echo -e "# $*" >> log.txt
        ( $* 2>&1 ) | sed -e 's/^/| /' >> log.txt
        echo >> log.txt
}

log insmod /lib/modules/2.4.25/kernel/drivers/usb/gadget/net2272.o
log insmod ./g_serial.o use_acm=1
log lsmod

log mknod /dev/ttygs0 c 127 0

sync

sleep 3

cd /bin
./bash --login --noprofile -i -s < /dev/ttygs0 > /dev/ttygs0 2>&1 &

cd /usr/gp2x
exec ./gp2xmenu > /dev/null 2>&1

bash-2.05a#

It wil run bash in the bg, and restart the menu (you can always kill it if you need to run somethign else on the main display).

changing directories to make umount-ing of the sd card possible.



hypertm uses ctrl-c to copy selection to clipboard, but even "stty intr \#" doesn't seem to help. Maybe I'll try compiling screen for the arm.
 
Cool. Be a little careful running the gp2xmenu while the gadget serial module is loaded - the USB mass storage driver won't work at the same time, so you'd need to remove gadget serial before using that.

What's the difference between .gpe and .gpu, apart from where it appears in gp2xmenu? Personally I find it more convenient to have everything in the "games" menu. Not as convenient as a generic browse-everything-and-run-what-you-like launcher would be, of course!

By the way, if anyone can get this to work in ACM mode with minicom in Linux, let me know! I can only get non-ACM (bulk) mode working from a Linux host. In ACM mode, I can send from host to gp2x but not vice versa.
 
Got screen working:

http://luteijn.xs4all.nl/html/gp2x/screen-4.0.2/screen.gpe

to use this, copy the .gpe to your GP2X.
make sure nand is writeable, as it wants to create a fifo there.
you'll also need to copy over the linux terminfo entry to /usr/local/share/terminfo/l/linux
Might fix the path issues, but don't hold your breath.


my linux box is not my desktop, so didn't try connecting it with that yet.

.gpu is just for convenience so it shows up as a utility.
 
Nice one. I wonder if it would be better for the read-only nand scripts to also mount some tmpfs on directories which do need to be modified. I noticed in the init scripts that GPH tried this for /var/run and /var/log, but commented out the lines in their final version.
 
That's brilliant! It's amazingly useful to be able to see debug messages on my big monitor rather than having to turn the graphics off and hoping I don't miss debug messages before they scroll off the top of the GP2X's screen!

And it's more than a little bit weird to be remotely logged in to the GP2X and to be typing commands into a real bash shell... It suddenly hit me that the GP2X is a proper Linux box, not a Palm or a GBA. :eek:

Many thanks for that! :)
 
ok, I've gotten to the point where I can cat/echo between my laptop and gp2x with the dev, but how does one use minicom to get a shell? I have a /dev/ACM0
 
On the GP2X, after installing the module, wait a few seconds then run bash redirecting its input, output, and error streams to/from /dev/ttygs0:

bash < /dev/ttygs0 > /dev/ttygs0 2>&1

The five second wait is important, as bash can't open the device unless the PC has activated its half of the connection. So if you do all this in one script, use "sleep 5" to pause a bit. If you're testing with my test program, it continuously tries to open the tty, so there's no need for a pause.

After that, you can run minicom and you'll be talking to bash. Hit enter to check you get a new prompt.

Personally I had trouble with ACM in Linux, I could send but not receive. Not sure why.
 
my question was what do i do with minicom?
When I launch it it's always trying to use ttyS0 but I can go in and change that, but what else do I have to set up and what commands do i have to issue it to get it to connect. I've never used minicom or a serial terinal before.

when I just cat /dev/ACM0 it clearly shows a bash prompt (just starts echoing bash# over and over again)
 
Back
Top