Installing TinyOS from Source on Fedora 13 64bit

From TinyOS Wiki
Revision as of 11:05, 18 July 2010 by Moobsen (talk | contribs) (New page: TO DO: Format, Create links & add text. '''NOTE: Fedora does not add the default user to the /etc/sudoers file by default. Therefore one has to this before copy & pasting the commands, or...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

TO DO: Format, Create links & add text.

NOTE: Fedora does not add the default user to the /etc/sudoers file by default. Therefore one has to this before copy & pasting the commands, or replace every "sudo" with "su -c "<command>" ".

If you want to develop on a fresh installed Fedora, you need to first install the standard delevopment tools, since they are not part of every Fedora release:

  sudo yum install wget gcc gcc-c++ cvs svn git automake python-devel

Additional tools TinyOS uses:

  sudo yum install graphviz flex bison perl

The rest is not in the Fedora repos, so here begins the odyssey.

Install Sun's Java Platform

In Fedora 13 OpenJDK is the preinstalled java version. Since I'm not sure if it works with TinyOS, I replaced it with the "official" closed source version. Therefore I removed OpenJDK (sudo yum remove java-1.6.0-openjdk) and installed Sun's (Oracle's) Java Platform (JDK):
Go to http://java.sun.com/javase/downloads/index.jsp and download the JDK. I chose "jdk-6u21-linux-x64-rpm.bin". The website will annoy you by asking you to register, but you can skip that and download without registration.
Make the file executeable and run it with root rights:

  chmod +x jdk-6u21-linux-x64-rpm.bin
  sudo ./jdk-6u21-linux-x64-rpm.bin

For some, to me unknown reason, the installer does not create the necessary environment variables nor does register the new java version with the system. So one has to do this by hand. First, I created the script "/etc/profile.d/custom.sh" with the following content:

  #Java Variables
  export JAVA_HOME=/usr/java/jdk1.6.0_21:/jre/bin

Then I ran the following commands as root user:

  export JAVA_HOME=/usr/java/jdk1.6.0_21
  export JAVA_ALTERNATIVE_PRIORITY=16021
  /usr/sbin/update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --install /usr/bin/javadoc javadoc $JAVA_HOME/bin/javadoc $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --install /usr/bin/appletviewer appletviewer $JAVA_HOME/bin/appletviewer $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --install /usr/bin/javah javah $JAVA_HOME/bin/javah $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --install /usr/bin/jar jar $JAVA_HOME/bin/jar $JAVA_ALTERNATIVE_PRIORITY
  /usr/sbin/update-alternatives --auto java
  /usr/sbin/update-alternatives --auto javadoc
  /usr/sbin/update-alternatives --auto appletviewer
  /usr/sbin/update-alternatives --auto javah
  /usr/sbin/update-alternatives --auto javac
  /usr/sbin/update-alternatives --auto jar

The Sun JDK should now be installed. To verify this one can type:

  java -version

which should result in:

  java version "1.6.0_21"
  Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
  Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

or similar.

Install native compilers

I'm not sure if the versions in the Fedora repositories will work with the hardware, or if one needs modified version... for now I'm only simulating, so the repo versions will do.

  sudo yum install avr-binutils avr-gcc avr-libc avarice avr-gdb avrdude

Install TinyOS toolchain

a) NesCC - For the NesC compiler there do exist various .rpms, but none in the official Fedora repositories, so I compiled from source.

  wget http://sourceforge.net/projects/nescc/files/nescc/v1.3.1/nesc-1.3.1.tar.gz/download
  tar -xvf nesc-1.3.1.tar.gz
  cd nesc-1.3.1/
  ./configure
  make
  sudo make install

b) Deputy Compiler - This is also not in the repos, again compiled from source. Yet this program is written in Objective Caml, whose compiler also needs to be compiled from source, since there's no version in the repo's. *sigh*. IMPORTANT: To compile deputy-1.1 one needs ocaml-3.09.0. I initially downloaded the latest version (ocaml-3.11.2), and deputy DID NOT COMPILE.

  wget http://caml.inria.fr/pub/distrib/ocaml-3.09/ocaml-3.09.0.tar.gz
  tar xvf ocaml-3.09.0.tar.gz
  cd ocaml-3.09.0/
  ./configure
  make world
  make opt
  sudo make install
  wget http://deputy.cs.berkeley.edu/deputy-1.1.tar.gz
  tar xfv deputy-1.1.tar.gz
  cd deputy-1.1
  ./configure
  make
  sudo make install

Install the TinyOS 2.x source tree

Originally I wanted to download the tarball from Sourceforge, but apparently they were just migrating to Google Code and both repos were disabled. So I checked out the cvs repo, which also has the advantage that I can be sure to have the very latest version.

  cd ~/opt/
  cvs -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos login
  cvs -z3 -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos co -P tinyos-2.x

Also, one has to set the TinyOS environement variables. So I added to /etc/profile.d/custom.sh the following lines:

  #Tiny OS Variables  
  export TOSROOT=~/opt/tinyos-2.x
  export TOSDIR=$TOSROOT/tos
  export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
  export MAKERULES=$TOSROOT/support/make/Makerules

Install tinyos-tools

Once you have the source tree correctly set up, you need to compile the tools which are included there as source.

  cd $TOSROOT/tools/
  ./Bootstrap
  cd platforms/mica/uisp;./bootstrap; cd $TOSROOT/tools/
  ./configure
  make
  sudo make install

The programs you just installed include:

  /usr/bin/mig
  /usr/bin/motelist
  /usr/bin/ncc
  /usr/bin/ncg                                                                                                                                                                         
  /usr/bin/nesdoc                                                                                                                                                                      
  /usr/bin/tinyos.py                                                                                                                                                                   
  /usr/bin/tos-bsl                                                                                                                                                                     
  /usr/bin/tos-build-deluge-image                                                                                                                                                      
  /usr/bin/tos-channelgen                                                                                                                                                              
  /usr/bin/tos-check-env                                                                                                                                                               
  /usr/bin/tos-deluge                                                                                                                                                                  
  /usr/bin/tos-ident-flags                                                                                                                                                             
  /usr/bin/tos-install-jni                                                                                                                                                             
  /usr/bin/tos-locate-jre                                                                                                                                                              
  /usr/bin/tos-mote-key                                                                                                                                                                
  /usr/bin/tos-mviz                                                                                                                                                                    
  /usr/bin/tos-serial-configure                                                                                                                                                        
  /usr/bin/tos-serial-debug                                                                                                                                                            
  /usr/bin/tos-set-symbols
  /usr/bin/tos-storage-at45db
  /usr/bin/tos-storage-stm25p
  /usr/bin/tos-write-image
  /usr/bin/uisp

Verification

Congrats, you're pretty much done! To verify everything installed correctly run

  tos-check-env

In my case I got 2 Warnings, because I have newer versions of the installed programs than the script checks for, but I hope this will not lead to problems. Even though in the case of the ocaml compiler, it just did...

[Optional] TOSSIM

Since by the time of the installation I did not have access to any actual hardware, I wanted to compile some example programs for TOSSIM, the TinyOS simulator. Typing

  cd $TOSROOT/apps/Blink
  make micaz sim

resulted in an error. Apparently make could not find the file "Python.h". To fix that one has to search for that file and add the path to the CFLAGS variable. If one does not find "Python.h", one needs to install python-devel (or whatever the dev packet is called in your distribution -- in Fedora do "sudo yum install python-devel").

  cd /
  locate Python.h

the path where Python.h lies then has to be added to "$TOSROOT/support/make/sim.extra" like this:

  CFLAGS += -I/path

in my case the path was "/usr/include/python2.6/" so the line I added to "$TOSROOT/support/make/sim.extra" was:

  CFLAGS += -I/usr/include/python2.6/

That was that.