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

mipsel-linux-gnu-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

./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

Prepare the kernel source:

$ git clone git://git.linux-mips.org/pub/scm/linux
$ wget "http://marc.info/?l=linux-mips&m=126254986304947&q=raw" -O ar7-gpio.patch
$ wget "http://marc.info/?l=linux-mips&m=126457988003439&q=raw" -O ar7-clk.patch
$ #wget "http://marc.info/?l=linux-mips&m=126254994505045&q=raw" -O ar7-part.patch
$ cd linux
$ git checkout origin/linux-2.6.33-stable
$ git checkout -b ar7

$ git fetch git://git.linux-mips.org/pub/scm/linux-queue.git +
$ git merge FETCH_HEAD

$ # the following two are in linux-queue (20100307) so skip this whole section
$ patch -p1 < ../ar7-gpio.patch
$ patch -p1 < ../ar7-clk.patch
$ # ar7part is broken, instead add "mtdparts=physmap-flash.0:....." to your kernel parameter
$ # patch -p1 < ../ar7-part.patch
$ git commit -s -a -m "bits and bobs for WAG54Gv2 kickoff"

Cook your kernel:

$ alias mmake="ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- 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

Now build the root filesystem, do not get buildroot to build your JFFS2 image:

$ git clone git://git.buildroot.net/buildroot
$ cd buildroot
$ make menuconfig
$ # make busybox-menuconfig

After doing this you might want to go back into your Linux kernel tree (if you are using modules) and type:

$ 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:

# ar7part is broken, use the second line
#CONFIG_CMDLINE="rootfstype=jffs2 root=/dev/mtdblock3 rw cpmac.dumb_switch=1"
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) cpmac.dumb_switch=1"

www: wag54g (last edited 2010-03-08 11:32:18 by alex)