Saturday, December 29, 2012

Cross-compile DTN2 for Raspberry Pi

Compiling DTN2 on the Raspberry Pi is fairly straight forward but can take some time. Now you ask yourself can I do better? Well, yes you can!

A cross compiler is essentially the act of compiling a program on a build machine that is not necessarily the same architecture as your target architecture. For example, say you have a super fast x86-based desktop which has oodles of horsepower (ie. RAM, CPU) compared to your $25/35 Raspberry Pi. Compiling programs on your super duper fast machine takes mere minutes where the Raspberry Pi can take considerably longer. What you need is to cross compile your programs on your super fast machine and then copy/transfer them over to your Raspberry Pi and it will run as if it was compiled natively on your Pi. Neat!

You will be required to cross compile a set of libraries before finally cross compiling DTN. Performing a Google search to "Cross compile DTN2" give you lots of hits. This post will give you a consolidated guide on cross compiling DTN2 for the Raspberry PI.


Build a Tool Chain

First build yourself a tool-chain for the arm processsor. Follow this excellent post from Luis Ibanez and Andrew Maclean on building yourself a tool chain for the Raspberry Pi. I won't go into any additions details since they did such a superb job on describing the steps.

http://www.kitware.com/blog/home/post/426


Cross Compile Tcl

Once you have a tool chain which includes the C and C++ compilers proceed with the following.

> wget http://sourceforge.net/projects/tcl/files/Tcl/8.6.0/tcl8.6.0-src.tar.gz
> gunzip < tcl8.6.0-src.tar.gz | tar xvf -
> cd tcl8.6.0/unix
Now, the following will depend on where you installed the tool-chain. On my system, it was installed to /home/pato/x-tools, however your setup might be different. 



Now, you will need to export the following environment variables. Remember that this will only be temporary for the life of your terminal session (ie. when you close your terminal window, you will need to do this again). 
> export LDFLAGS="-L /home/pato/x-tools/arm-unknown-linux-gnueabi/lib"
> export CFLAGS="-I /home/pato/x-tools/arm-unknown-linux-gnueabi/include"
> export CPPFLAGS="-I /home/pato/x-tools/arm-unknown-linux-gnueabi/include"
> export CC=arm-unknown-linux-gnueabi-gcc
> export AR=arm-unknown-linux-gnueabi-ar
> export RANLIB=arm-unknown-linux-gnueabi-ranlib
> export ac_cv_func_strtod=yes
> export tcl_cv_strtod_buggy=1
Whew! Now, run configure, however make sure you modify this according to your build machine. For example, if you are running another architecture you will need to modify the "--build" option for configure.

> uname -m (will list your build machine architecture)

Now, configure and compile!

> ./configure --build i686-linux --host arm-unknown-linux-gnueabi-gcc
> make

Cross Compile Berkley DB

Now, we turn our fingers to Berkley DB. Although not necessary for DTN2 to operate we will cross compile this one anyways since we can.

Open up a new terminal and get the source from Oracle. Note that the old environment variables may mess you up so I recommend starting from scratch on the environment variables.

> http://download.oracle.com/otn/berkeley-db/db-5.3.21.tar.gz

I created an account although I think you may be able to download it without one. By whatever means you get the source, eventually get it to your build machine. I used ssh to copy the source to the build machine.

Set the following environment variables

> export CC="arm-unknown-linux-gnueabi-gcc"
> export AR="arm-unknown-linux-gnueabi-ar"
> export RANLIB="arm-unknown-linux-gnueabi-ranlib"
> export STRIP="arm-unknown-linux-gnueabi-strip"

Now, run configure

> ../dist/configure host=i686-linux --build=arm-unknown-linux-gnueabi-gcc --prefix=/home/pato/DTN/berkley
> make
> make install



Cross Compile DTN2

Coming Soon!

References

The following links where used to make this post.



Tuesday, December 25, 2012

DTN2 on the raspberry pi

What is DTN2

DTN2 is an implmentation of the Bundle Protocol (RFC5050) which describes communication when disruption is the norm and not the exception. I won't go into a whole lot of detail but here is a short YouTube video which provides the basic idea.


Download Source

First, create a directory for everything and called it DTN

> mkdir DTN
> cd DTN

Next, get the source code for DTN and Oasys

> wget http://sourceforge.net/projects/dtn/files/DTN2/dtn-2.9.0/dtn-2.9.0.tgz
> wget http://sourceforge.net/projects/dtn/files/oasys/oasys-1.6.0/oasys-1.6.0.tgz

Next, unzip this two

> gunzip -c oasys-1.6.0.tgz | tar xvf -
> gunzip -c dtn-2.9.0.tgz | tar xvf -

Install Oasys

First, install some pre-requisites. On my system I had to install the following additional pre-requisites. The list of pre-requisites could differ on each system for take this as a guide. If you are missing a pre-requisite, then the configure step will highlight it. 

sudo apt-get install tcl tcl-dev libdb-dev libxerces-c2-dev libxerces-c28 libxerces-c3.1 libxerces2-java tcl-tclreadline

Now configure Oasys

>cd oasys-1.6.0
> sh configure

If there are any missing libraries, then this is the step at which you will see them. Install them one by one until the configure is happy (ie. you should see no errors)

Next compile and install
> make
> sudo make install

Install DTN

Now, go to your dtn-2.9.0 directory and issue the following commands:

> cd dtn-2.9.0
> sh configure -C
> make
> make install

Similarly, the configure step will tell you if anything is missing. Install and missing dependencies until it is happy (ie. no errors).

If everything went OK, then you should see the following applications installed under /usr/bin

pi@raspberrypi /usr/bin $ ls -l | grep dtn
-rwxr-xr-x 1 root root       81255 Dec 25 00:51 dtncat
-rwxr-xr-x 1 root root       70268 Dec 25 00:51 dtncp
-rwxr-xr-x 1 root root       71767 Dec 25 00:51 dtncpd
-rwxr-xr-x 1 root root    20346777 Dec 25 00:51 dtnd
-rwxr-xr-x 1 root root        3368 Dec 25 00:51 dtnd-control
-rwxr-xr-x 1 root root        7567 Dec 25 00:51 dtnhttpproxy
-rwxr-xr-x 1 root root       79028 Dec 25 00:51 dtnpeek
-rwxr-xr-x 1 root root      133488 Dec 25 00:51 dtnperf-client
-rwxr-xr-x 1 root root       83297 Dec 25 00:51 dtnperf-server
-rwxr-xr-x 1 root root       72117 Dec 25 00:51 dtnping
-rwxr-xr-x 1 root root       90454 Dec 25 00:51 dtnpublish
-rwxr-xr-x 1 root root       81048 Dec 25 00:51 dtnrecv
-rwxr-xr-x 1 root root      126657 Dec 25 00:51 dtnsend
-rwxr-xr-x 1 root root       72531 Dec 25 00:51 dtntraceroute
-rwxr-xr-x 1 root root      631425 Dec 25 00:51 dtntunnel




Installing and running "Wheezy" on Raspberry Pi

Downloading the image file

Download the image file from http://www.raspberrypi.org/downloads or you can download using bittorrent. Either way you will get the file in zip format.

Writing Image to SD

Writing the image file to the SD card is fairly simple in Linux with a few simple commands. There is a Windows equivalent but decided to go use 'dd' instead.

Once you have downloaded the image file from the website or through bit-torrent, you will need to un-zip it. Issue the following command

> unzip 2012-10-28-wheezy-raspbian.zip

Then using 'dd' copy the image file over to your SD hard. You will need to alter the command depending on how your SD hard get loaded. There are several ways to determine the device loaded but I would just look for the last loaded device by looking at dmesg

> dmesg | tail 

Once you find your device, issue the following command (with your alterations of course for device name)

> dd if=2012-10-28-wheezy-raspbian.img of=/dev/sdb bs=4M

Note, remember to write to the entire device and not just a single partition (ie. don't use sdb1).

For sanity, run the following command to flush the IO buffers

> sync

Done, remove your media card and put the sucker into your raspberry pi. Hook up the necessary peripherals (ie. monitor, mouse, keyboard) and you are done.