Linux on a Linksys WAG54G (Version 2)

N.B. this section is far from being complete and contains generally inaccurate information. It's just here for my note taking until I have worked things out properly

The idea of this page is to try and document my slow and irregular work to get Linux working on the Linksys WAG54Gv2 without using the OpenWRT distribution.

Flashing the Firmware

Seems that all the instructions relating to the WAG54Gv2 are different on the internet to the version of the ADAM2 bootloader that I have (version 0.22.12). I do not get the exciting option of FTP however I do get TFTP, which is available when the bootloader kicks in (you can give yourself a larger window of opportunity if you interrupt it by pressing any key over the serial port) with:

$ tftp -v -m binary 192.168.1.1 -c put openwrt-WA21-jffs2-64k-code.bin

The above command then flashes what is 'mtd4' in the partition table below.

Misbehaving Ethernet Ports

Another gotcha is a broken capacitor (33uF 16V) can lead to all sorts of trouble. I had this issue with all three WAG54Gv2's I have bought off fleabay and found that with one of them I was able to get a temporary workaround by using a direct connection from my laptop by typing:

# ethtool -s eth0 autoneg off speed 10 duplex half

Partition Table

The onboard 4MB (64kB erase size) NAND is partition as follows.

partition

start

end

size

notes

mtd0

0x900e0000

0x903f0000

3136kB

rootfs

mtd1

0x90020000

0x900e0000

768kB

kernel

mtd2

0x90000000

0x90020000

128kB

adam2 bootloader

mtd3

0x903f0000

0x90400000

64kB

adam2 cfg

mtd4

0x90020000

0x903f0000

3904kB

kernel + rootfs

Under Linux the ar7part.c driver is meant to spit out a suitable partition table for both bootloaders (PSPBoot and ADAM2) that are available on the AR7 platform however it does not and should not be used; for me the 'rootfs' partition overlaps the 'linux' partition.

Serial Cable

The best serial port mod I have seen for the Linksys routers is done by placing a standard stereo 3.5mm headphone jack onto the front leg of the box. This makes for a very tidy setup, however what to plug into the headphone jack and how do you wire it up? Well FTDI make very nice serial cables that work great under Linux, including the TTL-232R-3V3-AJ which means you do not need to mess with a MAX-232 chip or soldering.

Wiring it up could not be any easier, the pinout of the TTL-232R-3V3-AJ is available from their website and the pinout is shown below (shamelessly stolen from the old OpenWRT wiki); remember that when wiring you attach the TX pin of one end to the RX pin of the other and of course GND to GND.

|
|    __
|   |  |        <- Pin 1, GND
|    --
|   |  |        <- Pin 2, Not Connected
|    --
|   |  |        <- Pin 3, Router's Serial RX
|    --
|   |  |        <- Pin 4, Router's Serial TX
|    --
|   |  |        <- Pin 5, VCC
|    --
|
|
 \__led__led__led__led____________________
                Front of WAG54G

Once all hooked up, you should see some action when you load minicom and configure the serial port to run at 38400 8N1 with no hardware or software flow control.

Resurrecting a Brick

Never did get the JTAG working, but here are some useful links:

You will also probably need the ADAM2 0.22.12 bootloader blob.

Creating Firmwares

$ svn co svn://svn.openwrt.org/openwrt/trunk openwrt
$ gcc -o srec2bin openwrt/tools/firmware-utils/src/srec2bin.c
$ gcc -o addpattern openwrt/tools/firmware-utils/src/addpattern.c

The 'cook-firmware' script is as follows:

#!/bin/sh -e

#objcopy -S -O srec --srec-forceS3 --remove-section=.reginfo --remove-section=.mdebug --remove-section=.comment --remove-section=.note --remove-section=.pdr --remove-section=.options --remove-section=.MIPS.options linux/vmlinuz vmlinuz.srec
objcopy -S -O srec --srec-forceS3 linux/vmlinuz vmlinuz.srec

./srec2bin vmlinuz.srec vmlinuz.bin

if [ $(wc -c vmlinuz.bin | cut -d' ' -f1) -gt 786432 ]; then
        echo kernel too big
        exit 1
fi

/usr/sbin/mkfs.jffs2 -X lzo -e 65536 -n -p -t -l -d buildroot/output/target/ --squash -o fs.img
if [ $(wc -c fs.img | cut -d' ' -f1) -gt 3211264 ]; then
        echo filesystem too big
        exit 1
fi

( dd if=/dev/zero bs=16 count=1; dd if=vmlinuz.bin bs=786432 conv=sync; cat fs.img ) | ./addpattern -o firmware-code.bin -p WA21

tftp -v -m binary 192.168.1.1 -c put firmware-code.bin

exit 0

Time to build yourself a toolchain and the root filesystem:

$ git clone git://git.buildroot.net/buildroot
$ cd buildroot
$ make menuconfig
$ # UCLIBC_CONFIG_FILE=../buildroot.uclibc.config make uclibc-menuconfig
$ # BUSYBOX_CONFIG_FILE=../buildroot.busybox.config make busybox-menuconfig
$ make
# mknod output/target/dev/console c 5 1
# mknod output/target/dev/null c 1 3
# mknod output/target/dev/ttyS0 c 4 64

Prepare the kernel source:

$ git clone git://git.linux-mips.org/pub/scm/linux
$ cd linux
$ git fetch
$ git checkout --track -b ar7 origin/linux-2.6.34-stable

$ # AR7 enhancements
$ git cherry-pick a39ed2c98830bdb2575c18ad2c4b1bdb72fd5b3f
$ git cherry-pick 9c1b013a3951671e219c32ca056fc07381a9e113
$ git cherry-pick 142a2ceea793b4d134757c226daeb4101d649df0
$ # git cherry-pick 1a1c92c4e415840dc39cd6766e92e0bc4c8d9d73
$ # git cherry-pick 9c753fb8b8a018335d758bac8acfb211cb69e404
$ git cherry-pick 076f6e4e84428dd3d2f0abcb5d08595e3d20cb56

Time to cook your kernel:

$ alias mmake="ARCH=mips CROSS_COMPILE=/usr/src/wag54g/buildroot/output/staging/usr/bin/mipsel-linux- make"
$ mmake ar7_defconfig
$ # try to get as much as you can in the main kernel, as modules take up filesystem space
$ mmake menuconfig
$ mmake
$ INSTALL_MOD_PATH=/usr/src/wag54g/buildroot/output/target mmake modules_install

Now run the 'cook-firmware' script and you should end up with a suitable image.

Kernel Cooking Notes

Issues I have found with the kernel:

Might be interesting for you, I use the following cmdline:

CONFIG_CMDLINE="rootfstype=jffs2 root=/dev/mtdblock0 rw mtdparts=physmap-flash.0:3136k@896k(rootfs),768k@128k(kernel),128k@0k(adam2)ro,64k@4032k(adam2-cfg)ro,3904k@128k(kernel+rootfs)"

TI ATM

If you cannot deal with the OpenWRT sangam-atm setup, you can download a tarball of my git tree that I have for it:

ADSL2+

TODO: http://www.andybotting.com/wordpress/openwrt-on-the-d-link-dsl-502t-gen-1, 'setenv modulation MMODE'

www: wag54g (last edited 2010-07-30 22:14:29 by alex)