Monday, June 2, 2008

Customizing Asus AM200g - II. Preparing the environment

I know I promised you a jabber server, but in the end it was not so easy and the entry would be perhaps too long, so let's start with simple stuff :-)

Note I am not a programmer, have no C skills, so there can be a glitch here and there, but in the end all steps below led me to something that worked. If you find something really nasty, please let me know.

I took most of the inspiration at Daniel Fišer's page on Asus WL-600g hacking and just tweaked it to suit my setup.

1. On a fresh Mandriva 2008.1 installation some of the necessary tools are missing. Install them as root:

# urpmi make gcc autoconf automake

2. Since Asus still did not release the sources for AM200g, I used the GPL setup provided for AM604g, which uses the same chipset and seems to be almost identical (it even comes in the same box, except for missing USB port and second antenna). Follow these steps to install it:

$ wget
$ unzip
$ cd GPL_AM604G_ForRussia
$ tar xvf GENERIC_6348_WLAN_A34_3-06-02-01_GPL.tar.gz
$ su
# ./consumer_install

3. Not surprisingly, the AM604g source is just as broken as the AM600g one, so the same steps as described by Daniel need to be done:

# cd /opt/toolchains/uclibc-crosstools/bin
# for A in mips-linux-uclibc-* ; do
> ln -s ${A} mipsel-uclibc-${A#mips-linux-uclibc-}
> done
# cd /home/hajma/Documents/GPL_AM604G_ForRussia/GENERIC_6348_WLAN_A34_3-06-02-01
# wget
# patch -p0 <cur_menu.patch

4. Now you can try to build the firmware, just for fun:


The firmware is created in the images directory. Since I have no replacement for the router, I'm not going to try it, although it might actually work.

5. To prepare the environment, create a file containing:

$ cat environment
export LIBS="-L${TOOLCHAINS_HOME}/lib/gcc/mips-linux/3.4.2"
export INCLUDES="-I${TOOLCHAINS_HOME}/include/c++/3.4.2 \
-I${TOOLCHAINS_HOME}/mips-linux/sys-include \
export CFLAGS="${INCLUDES} ${LIBS} -static"
export LDFLAGS="-static"
export CC="${TOOLCHAINS_HOME}/bin/mipsel-uclibc-gcc"
export PATH="${PATH}:${TOOLCHAINS_HOME}/bin"

and set the environment before doing anything else:
# . ./environment

(yes, this is "dot space dot ...")

6. Let's proceed to the helloworld example. Create it's own folder:

mkdir /home/hajma/Documents/GPL_AM604G_ForRussia/GENERIC_6348_WLAN_A34_3-06-02-01/userapps/opensource/helloworld

and follow the steps described in the automake manual:

Create the following files in an empty directory.

  • src/main.c is the source file for the hello program. We
    store it in the src/ subdirectory, because later, when the package
    evolves, it will ease the addition of a man/ directory for man
    pages, a data/ directory for data files, etc.
    ~/amhello % cat src/main.c
    #include <config.h>
    #include <stdio.h>
    main (void)
    puts ("Hello World!");
    puts ("This is " PACKAGE_STRING ".");
    return 0;

  • README contains some very limited documentation for our little
    ~/amhello % cat README
    This is a demonstration package for GNU Automake.
    Type `info Automake' to read the Automake manual.

  • and src/ contain Automake
    instructions for these two directories.
    ~/amhello % cat src/
    bin_PROGRAMS = hello
    hello_SOURCES = main.c
    ~/amhello % cat
    SUBDIRS = src
    dist_doc_DATA = README

  • Finally, contains Autoconf instructions to
    create the configure script.
    ~/amhello % cat
    AC_INIT([amhello], [1.0], [])
    AM_INIT_AUTOMAKE([-Wall -Werror foreign])

Once you have these five files, it is time to run the Autotools to instantiate the build system. Do this using the autoreconf command as follows:
~/amhello % autoreconf --install installing `./install-sh' installing `./missing'
src/ installing `./depcomp'
At this point the build system is complete.
In addition to the three scripts mentioned in its output, you can see that autoreconf created four other files: configure,,, and src/ The latter three files are templates that will be adapted to the system by configure under the names config.h, Makefile, and src/Makefile. Let's do this:
In addition to the manual's instructions, the details of host architecture must be provided when compiling for another platform. Also I set the prefix as the flash drive gets mounted as /var/usb/usb_1:
# ./configure --build=i686-pc-linux-gnu --host=mipsel-linux --target=mipsel-linux --prefix=/var/usb/usb_1/hello
# make
# make install
7. Optionally you can strip (remove all unnecessary bits) the binary:
# cd /var/usb/usb_1/hello/bin
# /opt/toolchains/uclibc-crosstools/bin/mipsel-uclibc-strip -o hellostripped hello
8. Copy the files to the flash:
# /home/hajma/Documents/squashfs2.0r2/squashfs-tools/mksquashfs /var/usb/usb_1 /tmp/dir.sqsh -be -noI -noD -noF
# dd if=/tmp/dir.sqsh of=/dev/sdb1
9. Plug the flash drive to the router and verify all runs fine:
$ telnet
Connected to (
Escape character is '^]'.
BCM96348 ADSL Router
Login: admin
> sh
BusyBox v1.00 (2005.04.12-18:11+0000) Built-in shell (msh)
Enter 'help' for a list of built-in commands.
# cd /var/usb/usb_1/hello/bin
# ./hello
Hello World!
This is amhello 1.0.
# ./hellostripped
Hello World!
This is amhello 1.0.
Final note: if you get "hello: applet not found" instead, it means you somehow did not compile the program for correct platform and BusyBox was not able to execute it.
Customizing Asus AM200g - V. firmware modification Customizing Asus AM200g - IV. jabberd configuration Customizing Asus AM200g - III. jabberd and vim Customizing Asus AM200g - I. PREPARATION

No comments:

Post a Comment