WORK IN PROGRESS

So, you've got OpenWRT on your router. Now you'll probably want to compile some program to run on it. Well, the router isn't the best platform to build software on natively. Lack of space, limited RAM and processsor speed are few downsides. But never fear you can build applications on your linux PC using toolchains and buildroots.

 

There's a few different ways to do this, I'm going to use Kismet as an example

 

1. Use the Openwrt SDK

"When using the SDK you don't require a full buildroot. The SDK is a stripped down version of it,

which includes the toolchain and all the required library and header files to cross-compile applications for OpenWrt."

http://wiki.openwrt.org/BuildingPackagesHowTo

I havenít gotten this method to work yet

 

 

2. Install and configure a Buildroot (below)

buildroot documentation Read it through once then read it again, and again and then you can start

  

 

3. Install and use a toolchain library kinda like 1 and 2 but in a weird sorta going to visiting your aunt who chain smokes through her stoma way.

 

 

 

Using the Buildroot to compile Kismet

 

Once you successfully created your buildroot using the documentation on the OpenWRT site

http://downloads.openwrt.org/docs/buildroot-documentation.html

 

Setting up your environment

 

You can put the following into a nifty script and use sh to run it but Iím lazy and I just open up a terminal window and copy/paste.

 

Replace /home/user/whiterussian/openwrt with the location of your buildroot and watch for line wraps!

 

export PATH=/home/user/whiterussian/openwrt/staging_dir_mipsel/usr/bin:/home/user/whiterussian/openwrt/staging_dir_mipsel/mipsel-linux-uclibc:/home/user/whiterussian/openwrt/staging_dir_mipsel/bin:$PATH

export AR=/home/user/whiterussian/openwrt/staging_dir_mipsel/bin/mipsel-linux-uclibc-ar

export AS=/home/user/whiterussian/openwrt/staging_dir_mipsel/bin/mipsel-linux-uclibc-as

export LD=/home/user/whiterussian/openwrt/staging_dir_mipsel/bin/mipsel-linux-uclibc-ld

export NM=/home/user/whiterussian/openwrt/staging_dir_mipsel/bin/mipsel-linux-uclibc-nm

export CC=mipsel-linux-uclibc-gcc

export CPP=mipsel-linux-uclibc-cpp

export GCC=mipsel-linux-uclibc-gcc

export CXX=mipsel-linux-uclibc-g++

export RANLIB=mipsel-linux-uclibc-ranlib

export ac_cv_linux_vers=2.4.30

export LDFLAGS="-static"

export CFLAGS="-Os -s"

 

The most important one is the last one. This tells the mipsel compiler to strip the binary. This removes all the statically linked

information that is bloating the executable. This will take a 5Mb binary down to a managable 200k. In a non cross-compiled environment

this would be taken care of when you performed a 'make install' but we can't do that.

 

 

Now  itís time to Build Kismet

 ./configure --with-pcap=linux  --host=mipsel-linux --disable-curses --disable-panel  --disable-viha --without-ethereal --prefix=/tmp --disable-setuid --disable-pcre --disable-client

 

make

 

or

 

make CFLAGS='-Os -s' if you forgot it the first time

 

Once the process is finished you'll have a nice compact binary

Now we need to transfer this to our router using scp (secure copy)

Just in case let's make sure it's executable on the router by issuing

#chmod 777 <filename>