Sei sulla pagina 1di 5

How to cross-compile program for MICAZ on Linux

Here I have gathered my experience from installing MIZAZ cross compiler on Linux and running
Contiki applications on this sensor node. Thank to all people who have shared their experiences before
me and I benefited them.

1 Installing cross-compiler on Linux


This method is useful for debian systems like Ubuntu otherwise you need to build the packages in other
ways or follow the other methods mentioned in Section 3.

I followed partly the instructions of "How Build your own packages" at this website:

http://blog.coldtobi.de/1_coldtobis_blog/archive/21_updating_avr-
gcc_binutils_to_get_the_devices_update_now_also_includes_deb_files.html

1. Get the sources and build the dependencies:


apt-get source gcc-avr binutils-avr
apt-get build-dep gcc-avr binutils-avr

depending on the version of your linux and your previously installed packages, it may ask you to install
some required packages and usually yuo can do that easily with sudo apt-get-install. As I needed
to install dpkg-dev.

2. Apply binutils patches:


The patches provided at this website would not be useful for you because there are related to old
versions of binutils.
I tried following but new file had the exactly same size as previous one:
cd binutils-avr-2.18/debian
rm binutils-2.18.tar.bz2
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2

And for this one also there was no patch available:


wget http://frost.de/files/binutils-patch-2.18.gz -o binutils-patch-2.18.gz

You can try the binutils patched at this address:


http://avr32linux.org/twiki/bin/view/Main/BinutilsPatches

3. Build the binutils package:


fakeroot dpkg-buildpackage -b -uc -us

Here you may receive message that it needs some packages like bison, flex and dbs. I installed all
with apt-get install and run the above command again.
4. Install the binutils package:
sudo dpkg -i ../binutils-avr_2.18-4ubuntu1_amd64.deb
5.Here you have two options:
1. installing avr-libs with apt-get install which installs gcc-avr as well or follow to step 6.
sudo apt-get install avr-libc

Now you can go to step 10.

6.Download gcc:
wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.3.2/gcc-core-
4.3.2.tar.bz2

wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.3.2/gcc-g++-
4.3.2.tar.bz2

In this case also the patches don't exist in the mentioned path at this website.

7. Build and install gcc package like binutils:


fakeroot dpkg-buildpackage -b -uc -us
sudo dpkg -i gcc-avr_4.3.2-1_i386.deb

8. Get avr-libc source and compile:


apt-get source --compile avr-libc
You may need to download oxygen and transfig packages.

9. In this case you have already made the avr-libc package and just need to install it:
sudo dpkg -i avr-libc_1.6.2.cvs20080610-2_all.deb

10. At this point everything is ready to cross-compile our programs for MICAz sensor node (In other
words for AVR microprocessors inculding MICAz sensor nodes :) ). And you can use avr-gcc to
compile your programs as follows:
avr-gcc -mmcu=atmega128 test1.c

If you haven't managed to make the avr-gcc compiler up and running, you can follow the insructions at
Section 2 otherwise go to Section 3 to compile your programs for Contiki OS running on the MICAZ
nodes.

2 1 Installing cross-compiler on Linux without Debian packages

2.1 Building the cross-tool chain from avr32linx.org


Follow the instruction on http://avr32linux.org/twiki/bin/view to install necessary tools and compilers
for MICAZ nodes on Linux.

Anyway this website lacks some of the steps that you may encounter during installation so
here I have included them as well:

2.1.1Binutils
First thing to do here is to visit the BinutilsPatches page and either grab the pre-prepared source or the
patch. Note that if you get the patch you must follow the rest of the procedure on that page in order to
prepare your source for building, you cannot simply dive in.
Once you have your prepared source, either manually prepared or downloaded pre-prepared the rest of
the process is to execute the familiar configure: make: make install procedure:
$ ./configure --target=avr32-linux
$ make
$ sudo make install

Note: While you make the binutils, you may get some errors which are non-fatal warnings but new gcc
versions like the one shipping with Ubuntu 8.10 stop on them. In order to prevent this, you need to add
-Wno-error to compiler flags in the MakeFile. Find the following lines in the MakeFile
and edit them accordingly:
CFLAGS = -g -O2
CXXFLAGS = -g -O2

CFLAGS=-g -O2 -Wno-error


CXXFLAGS=-g -O2 -Wno-error

2.1.2 GCC (bootstrap version)


A full-fledged build of GCC won't succeed unless the C library has already been installed. And the C
library obviously can't be built and installed before the C compiler is installed. To solve this chicken-
and-egg problem, we initially install a reduced version of GCC which can be used to build the C library
and install the full version later.
The basic procedure is the same. Note that gcc actually requires that you build in some other directory
than the source tree:
$ mkdir build-avr32-linux-gcc
$ cd build-avr32-linux-gcc
$ ./configure --target=avr32-linux --enable-languages=c --disable-threads --
disable-libmudflap
$ make
$ sudo make install

You may get such an error:


error: Building GCC requires GMP 4.1+ and MPFR 2.3.2+.

If you haven't already installed, you need to do that and specify their locations using --with-gmp and
–with-mpfr.
You may need to install m4 for gmp if it complains while configuring it. You can install m4 (sudo
apt-get install m4). You need to install gmp and mpfr.

Note, however, the extra options to configure. Since we don't have a C library, there is simply no way
we can build the C++ support libraries. Thread support requires support from the C library as well, so it
must be disabled for now.
libmudflap and libssp are both run-time checking libraries which have been known to cause errors
at this early stage. They can safely be disabled for this bootstrap build though neither seem to cause an
error for the main build described below.
2.3 AVR32studio

The AVR Studio 4 is the Integrated Development Environment (IDE) for developing 8-bit AVR
applications in Windows NT/2000/XP/Vista/7 environments. They do not support Linux. But there are
some users that find their way to implement it on Linux. You can refer to the third party website
www.avrfreaks.net where similar kind of discussions on AVR devices are taken place.

3 Contiki on MICAZ
Since 9th of September 2009, Contiki supports MICAZ nodes as well as other platforms like TmoteSky.
At this stage, you need to have "avr-gcc", "avr-libc" and "uisp" installed.

Do not install uisp using apt-get install because it seems that this official verion of uisp
does not work with MIB510 programming boards. You have to use TinyOS version of uisp. They
have done some modifications.

1. Get the file from this address: http://azadeha.at.ifi.uio.no/uisp.tar.gz' and run following commands to install
uisp:
# tar -xvzf uisp.tar.gz
# cd uisp
# ./bootstrap
# ./configure
# make
# sudo make install

You can compile applications as usual in other platforms. For example: In "hello-world" application,
you can use the following command to compile and upload the OS to MICAz node.

make TARGET=micaz hello-world.upload PORT=/dev/ttyUSB0 PRGBOARD=mib510

Currently, only "mib510" programming board is supported. Serial communication, LEDs and simple
radio communication are tested on real MICAz nodes. Joakim Eriksson is working on Cooja simulation
support for the port Moreover, drivers for MTS300 sensor board are added but not tested for
correctness of the readings. Since MICAz port is still experimental, bugs, bug fixes and comments are
welcomed with great pleasure.

4 Some programming tips


Floating point printf is not supported in avr-gcc. You have to do it yourself, e.g.:

printf("\naverage rssi: %d.%02u \n",total_rssi/33,(100*total_rssi)/33-


100*(total_rssi/33)); //---------? %f

5 Useful links
AVR cross compiler for Mac OS X: http://www.ethernut.de/en/documents/cross-toolchain-osx.html
AVR forum: http://www.avrfreaks.net/
AVR32 Linux tool chain: http://avr32linux.org/twiki/bin/view/Main/
AVR MCU producer: www.atmel.com
Contiki homepage: http://www.sics.se/contiki/
Contiki developers mailing list: http://sourceforge.net/mailarchive/forum.php?forum_name=contiki-
developers

Potrebbero piacerti anche