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 WAG54GOnce 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:
Example ETAGing of a SMP863x - has a clear suitable pinout picture
- JTAG emulators
- DIY
- Purchase
egnite sell the Turtelizer 2 - has a serial port
Olimex produce the ARM-USB-OCD - has a serial port too
although cheap and looks good, it is apparently completely useless, the Amontec JTAGKEY-Tiny problem is that it is not really compliant with the MIPS EJTAG rising and falling timings
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 0Prepare 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:
CONFIG_CPMAC requires CONFIG_FIXED_PHY to function
if you use anything other than CONFIG_HZ_100, the timing delay loops go crazy; Florian thinks it is a bug in 4KEc stuff
CONFIG_CPMAC conflicts with anything other than CONFIG_PREEMPT_NONE if CONFIG_NO_HZ is set, reseting the box with no visible oops to trace the problem from when it initialises (only occurs when you pass to the kernel 'cpmac.dumb_switch=1', I have to otherwise no traffic flows across the NIC although they are detected)
you might need to apply the second part of the patch to 'drivers/serial/8250.c' from 500-serial_kludge.patch to make the serial console behave; this depends on the revision of your AR7 SoC, if the serial console looks a bit mixed up in places use this to fix it
if your kernel boots but gets stuck at "Calibrating delay loop...", it is because IRQ's are not firing and means MIPS: Deal with larger physical offsets (comes from the MIPS git queue as of 20100307) was never applied
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"