Howto: Usb Serial Shell With Stock Usb Cable


hcf

Still Fresh
Joined
Nov 15, 2009
Messages
32
Age
50
Location
Milpitas, CA, USA
Note: There is a new version of this package. DO NOT use the old package's "USBSerialDown.gpe" script, it will require reflashing your firmware to recover from. Please see the bottom of this message for the ugprade details.

There is a fine guide on this board that details how to make a USB Serial console cable for the GP2X Wiz by cannibalizing two other cables. It costs money, it takes time, and that makes it a barrier for some people to really get in and start enjoying hacking with their Wiz. It's really quite clever tho because it can expose the host-side controller hidden inside the Wiz, so you can hook up a keyboard or mouse or joystick or even a USB Serial dongle to connect to your PC (so you can hack on the Wiz while your program is running).

But I had to wonder: If the Wiz can pretend to be a block device USB client, why can't it pretend to be a serial converter?

It turns out there is a USB Serial client ("gadget" in linux kernel parlance) in the Linux-2.6.24 source tree. So I compiled it so you don't have to, then mucked about with Wiz'ness to get it to work without having to fuss with Termula.

Step 1: Fetch my USBSerial software minipack:

http://www.mercenary.net/OpenWiz/USBSerial-1.1.0p1.tar.bz2

Step 2: Untar this package onto an SD card.

Code:
  cd /media/disk # (or wherever)
  tar xjf ~/Desktop/USBSerial-1.1.0.tar.bz2 # (or wherever)

Step 3: Unmount the SD card safely and use the Wiz's built-in 'Launcher to run "USBSerial/USBSerialUp.gpe".

Step 4: Connect your Wiz to the host computer (make sure it has a comfy keyboard) with the USB cable that came with your wiz.

IMPORTANT: Do not modify your Wiz USB cable in any way. Put the soldering iron down.

By this time you should see the following in your dmesg on the host system (presuming you are using Linux):

Code:
usb X-Y: new high speed USB device using ehci_hcd and address 49
usb X-Y: configuration #1 chosen from 1 choice
usb X-Y: New USB device found, idVendor=0525, idProduct=a4a6
usb X-Y: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb X-Y: Product: OpenGP2X Wiz Serial Shell Access
usb X-Y: Manufacturer: Linux 2.6.24 with lf1000_udc
usb X-Y: SerialNumber: 0

Step 5: In order to present the USB dongle to your host operating system, you need to load the 'usbserial' module, with flags to identify its (default g_serial.ko) idVendor and idProduct values:

Code:
modprobe usbserial vendor=0x0525 product=0xA4A6

By this time you should see the following in your dmesg:

Code:
usb X-Y: generic converter now attached to ttyUSB0

Step 6: You may now use the ttyUSB0 interface (or whatever was actually assigned) with any serial management application of your liking - minicom, rtty...I like kermit, so I'll use quotes from my shell history as an example:

Code:
# kermit
(...) C-Kermit>set line /dev/ttyUSB0
(...) C-Kermit>connect
Connecting to /dev/ttyUSB0, speed 9600
 Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------




Welcome to the AESOP S3C2440A world !!!(0.1)

You may now login as 'root'.

wiz login: root
/dev #

And now you're done. Or you've just begun?


Baud speeds aren't important (and you may get errors trying to set them). I haven't tested to see how fast it actually runs, been having too much fun poking at things without having to suffer Termula2x hunt and pecking.

When you are done, you only have to restart your Wiz to clean up. Note that while the serial gadget is installed, it seems to interfere with the menu's USB block device mounting...nothing bad happens if you try to let it mount the NAND or SD from the menu system, but it seems to quietly fail to work. I haven't looked closely at this issue, and it hasn't bothered me particularly. Just FYI (but it may be a good argument for continuing work on the g_ether gadget, as g_ether would likely have the same limitation but would allow network rcp/scp/ftp access to the SD/NAND).

UPGRADING from USBSerial-1.1.0:

Under no circumstances should you run the USBSerialDown.gpe script.

First, delete the USBSerial directory on your SD. Install the new USBSerial directory using the sources above. Run the USBSerialUP.gpe script from the launcher and follow the instructions normally.

Once you've got a comfortable serial shell again, use vi to edit /etc/inittab and remove the line(s) starting with "G0", they should be at the bottom of the file. Once you've saved that change to inittab, "kill -HUP 1", this asks init to re-read inittab. Next, rm /usr/bin/loginpass.sh, which is installed by the old software.

That's it. From now on, to uninstall the new serial software simply restart the Wiz.

Edit 1: New version update.

Edit 2: s/SDRAM/SD card/ (correcting finger macro)
 
chickendung said:
I imagine this will help developers quite a bit, but what about the common folk? Can we use this method for connecting gamepads, keyboards, etc. to control the Wiz if we have some other hardware?

Sorry, no; although electrically USB is typically described as a star topology, logically USB works as a single-root tree, one host, many clients.

My package doesn't change that, it turns it on its head; instead of wanting the Wiz to be a host attached to a serial-dongle client, it is a virtual serial-dongle client attached to your host. Serial is easily reversible. Gamepads...not so much...unless you want your Wiz to play your gamepad. :)

To turn the gamepad situation on its head, what you need is something like a bridge or tunnel, like putting your gamepad on a VPN with a virtual host bridge on the Wiz. So far as I'm aware, no one's ever done that before, so there's no existing software and it would probably be a significant amount of work.

Unless that changes you are probably better off with the solder iron. :/
 
Last edited by a moderator:
nice idea and great work so far... if there wouldn't be the problem that my wiz doesn't boot anymore now after i've 'removed' the usb serial module. currently i'm reflashing the firmware, at least it gets that far :)
 
crow_riot said:
nice idea and great work so far... if there wouldn't be the problem that my wiz doesn't boot anymore now after i've 'removed' the usb serial module. currently i'm reflashing the firmware, at least it gets that far :)

I also just noticed that. A little more testing would have done me some good. :( Initially when I was playing with the system, my mknod's in /dev kept disappearing on reboot. So I thought the system got a copy-on-write or a re-image of the root filesystem on every reboot or something. I guess only /dev is rebuilt. It's strange because if it's devfs, it's not appearing in 'mount'.

Anyway, I've gone back to my previous method (a /bin/sh fork to watch getty) and am not mucking with the root filesystem anymore for now. I can't test if it works because I also need to go learn how to reflash my firmware for the first time. :(
 
Last edited by a moderator:
Phew. Reflashing the firmware brings it back.

Also, I think the reason why this serial method causes the SDRAM mount to fail is because the install script's PWD is on the SDRAM...so when the GP2X Menu tries to umount the SD, it fails because the mount is still in use, and then the device is busy when it tries to nail up the block device gadget. This should be easy to work around if someone has the time, I just want to work on something else for awhile. :)

edit: clearer explanation
 
Hey, this is really, really useful. Thanks very much for doing this, its brought the Wiz back up a notch in being able to develop and debug. Hooray for finally having access to my apps stdio! :)

One thing about the gamepad idea: it would be possible to modify the gadget-serial linux module to make the wiz appear to be a common joystick. This is quite feasible and would be a great hack. I imagine if you can compile the gadget-serial driver already, you must have what you need to make a joystick driver.. so if you could post more details about how you built this module for the Wiz, it would be helpful for those who want to have a go at making a nice little Wiz-As-Joystick USB driver.

What do you think?
 
torpor said:
Hey, this is really, really useful. Thanks very much for doing this, its brought the Wiz back up a notch in being able to develop and debug. Hooray for finally having access to my apps stdio! :)

Enh, I did it for myself to use, but you're welcome anyway.

One thing about the gamepad idea: it would be possible to modify the gadget-serial linux module to make the wiz appear to be a common joystick. This is quite feasible and would be a great hack. I imagine if you can compile the gadget-serial driver already, you must have what you need to make a joystick driver.. so if you could post more details about how you built this module for the Wiz, it would be helpful for those who want to have a go at making a nice little Wiz-As-Joystick USB driver.

What do you think?

As a USB client there are a great many possibilities for the Wiz. You could turn the Wiz into a mini drawing pad as well, exposing the touchscreen as a tablet. You could make it into a little USB pictureframe display (anyone remember the bucket game on GameCube? Crystal Chronicles? You could use Wiz's as display/touchpad gamecontrollers for some multiplayer action). So far as I know none of this kind of software has been written already; unlike g_serial where all I did was compile module that comes with 2.6.24, that's why it was so easy.

The linux-2.4.26-pollux tarball in the archives is what I used as sources. This handily has two config files, I think I used the older dated one first and it worked so I never tried the newer dated one (whichever you choose, 'cp' it to .config in the root of the linux-2.6.24-pollux directory). Use the toolchain on the archives (or the newer one in this forum, either works as the kernel doesn't want libraries), but make sure it's in your PATH this time tho so the linux kernel's Makefile can find it. Whenever you type 'make' in the linux kernel directory, use:

Code:
make ARCH=arm CROSS_COMPILE=arm-openwiz-linux-gnu- command

Where 'command' is the make command you're after for the moment. I did oldconfig first, entered through all the queries for stuff not listed in the config, then menuconfig to lazily seek into drivers->usb->gadget and enable the serial gadget as a module. I didn't try building the kernel, just made 'modules', and then copied down g_serial.ko. The block device/mass storage module and ethernet module were already built from these sources and installed on the Wiz, so I ignored them (but you could probably use this same build environment trying to rebuild/fix g_ether). To set the custom text strings on the USB device ("OpenGP2X Wiz Serial"), I just edited drivers/usb/serial.c and searched for the string "Gadget". :)

Not really much to it.
 
Last edited by a moderator:
I just tried it again, no chance to get it work on Windows (yeah, i know ... ;) ) ... I've tried to set the "use_acm" flag, but then the serial module doesn't even load. Does anyone know what it needs to get the serial module in 'acm mode' working?

just looked at dmesg ... get the message:
Code:
gs_bind: cannot run ACM on lf1000 ...

... too bad.
 
This *SO* doesn't work - I launched the latest gpe, modprobed okay, confirmed with dmesg... did ls /dev/ to confirm /dev/ttyUSB0 is there... opened kermit, set line to /dev/ttyUSB0 and connect... *FAIL*... just hangs there. Can you fix this please?.
 
glossywhite said:
This *SO* doesn't work - I launched the latest gpe, modprobed okay, confirmed with dmesg... did ls /dev/ to confirm /dev/ttyUSB0 is there... opened kermit, set line to /dev/ttyUSB0 and connect... *FAIL*... just hangs there. Can you fix this please?.

Try hitting enter a couple times, make sure you're waiting ~10 seconds or so (there is a 5sec sleep in the getty loop to make sure it doesn't spin on CPU, and getty itself only polls for CD every so often).

You mentioned in another thread you downgraded your Wiz to an older firmware and haven't been able to upgrade past it. This module is built to work with Wiz firmware 1.1.0. I have no idea what it will do on an older firmware.

Host-side, I know the serial gadget works with a linux host of at least 2.6.22 or later.
 
Last edited by a moderator:
Excellent, thank you very much, extremely helpful!

Followed the instructions and it works fine.

I tried running a program(sqdef) from kermit and it started the program on the Wiz, but then when I exited the program it didn't go back to the terminal in kermit, it kept displaying status lines and would allow me to ctrl-C to terminate an application but it seemed to have linked up the keyboard with buttons on the Wiz, I think it was 'e' changed to the entertainment screen and 'a' was a b-button press on the Wiz.

Also, is there any way to transfer files while connected through USBserial?

Edit: It seems that whenever you run a program through kermit it runs it in the background or something because it flickers between the program and the menu, and your button presses on the Wiz apply to both (if you press b, it activates the currently selected menu item and also whatever b does in the program you are running through kermit)
 
IAmCorbin said:
Edit: It seems that whenever you run a program through kermit it runs it in the background or something because it flickers between the program and the menu, and your button presses on the Wiz apply to both (if you press b, it activates the currently selected menu item and also whatever b does in the program you are running through kermit)
That's normal. Type "killall gp2xmenu" before running anything.
 
Last edited by a moderator:
tanathos said:
So, no one knows how to do that on windows? :(

check out my thread about that: http://www.gp32x.de/board/index.php?/topic/50579-usb-serial-windows/

it is a solution for windows, though not as convenient as using under unix.
 
Last edited by a moderator:
Hi, iv'e found a way to transfer files:

You must use minicom + rzsz, I've compiled zmodem for Wiz...

Guide:

- Just make sure you have lrzsz installed on your linux

- Install lrz lsz from the file executing install.gpe on wiz (copy lrz/lsz to sbin) Zmodem for wiz

- Run hcf's USBSerial as usual

- Run on pc, as usual too (linux):

Code:
$ sudo modprobe usbserial vendor=0x0525 product=0xA4A6

- Install/configure minicom on pc:

Code:
$ minicom -s

I've only changed serial port:

Code:
    +-----------------------------------------------------------------------+
    | A - Dispositivo Serial            : /dev/ttyUSB0                      |
    | B - Localización del Archivo de Bloqueo : /var/lock                   |
    | C - Programa de Acceso           :                                    |
    | D - Programa de Salida             :                                  |
    | E - Bps/Paridad/Bits             : 115200 8N1                         |
    | F - Control de Flujo por Hardware: Sí                                 |
    | G - Control de Flujo por Software: No                                 |
    |                                                                       |
    |    ¿Qué configuración alterar?                                        |
    +-----------------------------------------------------------------------+

and send options for zmodem:

Code:
+------------------------------------------------------------------------------+
|     Nombre            Programa               Nombre R/T Pantalla completa IO-|
|RA  zmodem     /usr/bin/sz -vv -b -e -N        Y    U    N       Y       Y    |
| B  ymodem     /usr/bin/sb -vv                 Y    U    N       Y       Y    |
| C  xmodem     /usr/bin/sx -vv                 Y    U    N       Y       N    |
| D  zmodem     /usr/bin/rz -vv -b -E           N    D    N       Y       Y    |
| E  ymodem     /usr/bin/rb -vv                 N    D    N       Y       Y    |
| F  xmodem     /usr/bin/rx -vv                 Y    D    N       Y       N    |
| G  kermit     /usr/bin/kermit -i -l %l -s     Y    U    Y       N       N    |
| H  kermit     /usr/bin/kermit -i -l %l -r     N    D    Y       N       N    |
| I  ascii      /usr/bin/ascii-xfr -dsv         Y    U    N       Y       N    |
| J    -                                                                       |
| K    -                                                                       |
| L    -                                                                       |
| M  Auto activación de la cadena de caracteres de recepción Zmodem..... D     |
| N  Utilizar ventana de selección de archivos.. Sí                            |
| O  Indicador para directorio de recepción.. No                               |
|                                                                              |
|   ¿Cambiar qué configuración?: (ESPACIO para borrar)                         |
+------------------------------------------------------------------------------+

Save config.

Run minicom.

On wiz open a new terminal:

Code:
 root@wiz:/dev# /sbin/getty -L ttygserial 115200 vt100
and
call reception prog:

Code:
 root@wiz:/dev# cd /whereToPutTheFileOnTheTarget/
 root@wiz:/whereToPutTheFileOnTheTarget# lrz -vvvvb
 .. waiting to receive.

send files from pc with minicom: Ctrl + A , s

and reverse direction:

Code:
 root@wiz:/dev# cd /whereIsTheFileToSendOnTheTarget/
 root@wiz:/whereIsTheFileToSendOnTheTarget# lsz -b --zmodem FileToSendOnTheTarget

minicom handles the file receiving automatically (put it in your $HOME by default)
 
Back
Top