Back to HOWTOs

Installing TinyOS for Telos Motes (and Mica2) on Linux

Background

This gives step-by-step instructions on how I installed TinyOS on Red Hat 9 and Fedora Core 3 (if you're using Slackware, I've been informed that this process only works with the 2.6 kernel) to work with Telos motes. I have also added an optional step to get Mica2 motes working with the installation as well. You can try installing TinyOS from RPMs as suggested on the TinyOS website. If this works for you, I suggest that you leave the office immediately and go buy a lottery ticket. Based on my experience, the more likely scenario is that you'll be on the verge of hurling a laptop through a window after a couple of days of trying to troubleshoot via the TinyOS mailing lists. Be forewarned that those instructions have some omissions that can cause the install to fail in a spectacular fashion (by spectacular, I mean that I had to use a System Rescue CD to be able to log back into my system).

These instructions on how to install from the source are much better, but still have a few pitfalls that I had to get around. So the instructions from the Moteiv website will serve as my basis in this HOWTO. My instructions assume that you are doing the install as root using the bash shell.

Note: Anytime that you add something to your ~/.bashrc file, you'll have to do a source ~/.bashrc for the changes to take effect in the current terminal or start a new terminal.

Related Pages

HOWTO

  1. Download the IBM 1.4 Java Development Kit (JDK) and javax.comm RPMs (not the Sun JDK...the JavaComm package is much more difficult to install).

    1. Download the IBM SDK for 32-bit xSeries (Intel compatible) RPM from IBM's JDK site. This requires you to register with IBM...such is life.

    2. Install the RPMs. Assuming that these are the only two RPMs in the directory in which you saved them, you can do:

      rpm -ivh --prefix /opt *.rpm

      which will install Java in the directory /opt/IBMJava2-142 (the IBMJava directory may have a slightly different name based on the version you are installing).

    3. Set the Java root and add it to your path in ~/.bashrc:

      export JAVA_HOME=/opt/IBMJava2-142
      export JDKROOT=$JAVA_HOME
      export PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH"
  2. Download and install the RPMs from TinyOS's Linux tools directory The graphviz tool is not necessary. Having the avr tools will save you some compile errors later, though they may not be strictly necessary.

    rpm -ivh *.rpm

    (assuming they are the only RPMs in the directory to which you saved them.)

    Note: The make RPM needs to be installed with -Uvh instead of -ivh if you already have an old version of make on your system. The TinyOS make version fixes a bug in verion 3.80.

    Note: If, later in the installation, you get an "unknown MCU: msp430x1611" error, you may need to use a newer version avr-binutils (e.g., >=2.15.1) than is provided in TinyOS's Linux tools directory. Some RPMs for Red Hat and Fedora can be found here.

  3. Download the TinyOS source from the CVS repository. In this example, I'll download the most recent tagged version (at the time of writing). I figure that it is easier to refer to a tagged version on mailing lists, etc. If you want the absolute latest code even if it hasn't been tagged, then leave off the -r switch in the cvs checkout command. (Just press enter at the password prompt)

    cd $HOME;
    cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/tinyos login;
    cvs -z3 -d:pserver:anonymous@cvs.sf.net:/cvsroot/tinyos co -r tos-1-1-14-candidate tinyos-1.x;

    Then, set your a variable for you TinyOS root in ~/.bashrc:

    export TOSROOT=$HOME/tinyos-1.x
  4. Install MSPGCC:

    cd $TOSROOT/tools/src/mspgcc;
    INSTALL_DIR=/opt/msp430 ./build-mspgcc install;

    (Note: You can leave out the INSTALL_DIR command line argument if the default location is acceptable.)

    (Note: If the file downloads in the script fail (e.g., when getting binutils, gcc-core, msp430-libc), you can remove the build, archive, and build-obj files if they exist to start the script anew. One alternative for the gcc-core files is ftp.gnu.org/gnu/gcc)

    If this doesn't work, see the Moteiv install page for a suggested alternative. Once everything is working, add the installed location of MSPGCC to your path and create a root variable:

    export MSPGCCROOT=/opt/msp430
    export PATH="$MSPGCCROOT/bin:$PATH"
  5. Symlink the boot strap loader for the motes:
    cd $MSPGCCROOT/bin;
    ln -s $TOSROOT/tools/src/mspgcc-pybsl/bsl.py ./msp430-bsl;
  6. Now is the part where we try out the neat little motelist-linux utility to find out what motes are attached to our computer (located in $TOSROOT/tools/src/motelist/). (Note: CVS version 1.5 works with older versions of Perl. The maintainers have modified the regular expression mentioned below.)

    This script requires a newer version of Perl than the one that comes with Red Hat 9 (Perl 5.8.0). I got a newer Perl RPM from the ActivePerl website. Install the newer Perl, if need be:

    rpm -ivh --prefix /opt *.rpm;

    Update your path variable:

    export PATH="/opt/ActivePerl-5.8/bin:$PATH"

    and change the first line of the motelist-linux script to be:

    #!/opt/ActivePerl-5.8/bin/perl -w

    Note that the reason this script needs a newer version of Perl is due to the following regular expression in the script:

    ($text =~ m/([^\s=]+)=\s*(.*?\S)\s*(?=[^\s=]+=|$)/mg)

    which returns null in older versions of Perl instead of 0 or 1.

    Finally, I had to change the usbserial in one line to be usb-serial to work on Red Hat 9 (Note: I did not have to make this change on Fedora Core 3). I.e., the line becomes:

    sudo cat /proc/tty/driver/usb-serial
  7. Symlink the motelist-linux utility to /usr/local/bin:
    cd /usr/local/bin;
    ln -s $TOSROOT/tools/src/motelist/motelist-linux motelist;
  8. Compile some TinyOS helper scripts:

    cd $TOSROOT/tools/scripts/;
    make install prefix=/usr/local;

    Add the script locations to your path:

    export PATH="/usr/local/bin:$PATH"
  9. Verify that the appropriate variables are set in your ~/.bashrc file:

    export PATH="/usr/local/bin:$PATH"
    export PATH="/opt/ActivePerl-5.8/bin:$PATH"

    # Java
    export JAVA_HOME=/opt/IBMJava2-142
    export JDKROOT=$JAVA_HOME
    export PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH"
    export CLASSPATH=.:$JAVA_HOME

    # MSPGCC
    export MSPGCCROOT=/opt/msp430
    export PATH="$MSPGCCROOT/bin:$PATH"

    # TinyOS
    export TOSROOT=$HOME/tinyos-1.x
    export TOSDIR=$TOSROOT/tos
    export CLASSPATH="`$TOSROOT/tools/java/javapath`"
    export MAKERULES=$TOSROOT/tools/make/Makerules

    Note: The single quotes in the CLASSPATH variable are both the one from the tilde key, not the one from the double quote key.

  10. Install nesC by downloading it from Sourceforge (version 1.1.3, not the newer 1.2 version...see the note below).

    Go to the directory were you unzipped nesC and do:

    ./configure;
    make;
    make install;

    If you use a nesC version less than 1.2, then do not install the TinyOS frontend as instructed on the Moteiv website. If you do the make install for the frontend (as instructed on the Moteiv website), it will write over the newer nesC tools that were installed in /usr/local/bin and the rest of the installation fails.

    A Note on nesC 1.2: This version has decoupled the tools from nesC in favor of the tools already in TinyOS. However, after searching the mailing list and some trial and error, it seems that there are no instructions on how to use nesC 1.2, the tools from TinyOS, and the avr RPMs. I tried the newer avr RPMs (and the older RPMS) in conjunction with the tools in TinyOS 1.1.15, but this combination never successfully compiled a mica2 binary. So, until the kinks are worked out, I would recommend using nesC 1.1.3.

  11. Now, we let the TinyOS Java compiling begin (Note: I skipped the TOSComm part from the Moteiv website since I installed the IBM packages and the TOSComm install seemed to give a lot of errors on my system) . Cross your fingers and do:

    cd $TOSROOT/tools/java;
    make;
    make;

    Also, install the JNI library for getenv.

    cd $TOSROOT/tools/java/jni;
    make install;
  12. Optional step for Mica2 motes

    Install the uisp tool to allow uploading via the serial port. Using TinyOS 1.1.14, I ran into a problem with one of the scripts. The DOS-style line breaks in the script cause the entire process to fail. This problem has been fixed in CVS version 1.2 of the script. Fixing the CVS 1.1 version of the script can easily be done:

    cd $TOSROOT/tools/src/uisp;
    dos2unix set-dates;
    chmod 755 set-dates;

    After the set-dates script is correct, you can run the COMPILE script (Note: If you want to change the default installation directory, add the --prefix=/new/installation/directory switch to the configure command in the COMPILE script).

    cd $TOSROOT/tools/src/uisp;
    ./COMPILE;
    make install;
  13. If everything went as planned, you should be able to compile, upload, and run the famous Blink application:

    cd $TOSROOT/apps/Blink;
    make telosb install.1 bsl,/dev/ttyUSB0;

    Where /dev/ttyUSB0 is the device location returned by motelist.

    For Mica2 motes, you do:

    cd $TOSROOT/apps/Blink;
    make mica2 install.1 mib510,/dev/ttyS0;

    Where /dev/ttyS0 is the device location of the serial port connected to the mote.

    If the red light starts blinking slowly on the mote, then everything works!

    Note: If you are using Telos motes and want to run TinyOS applications that require communication with a PC (e.g., SerialForwarder), you need make a small modification to the IBM Java files to use the USB port, instead of the serial port, for mote-to-PC communication. In $JAVA_HOME/jre/lib/javax.comm.properties, you need to change the line that reads:

    dev/ttyS=PORT_SERIAL

    To be:

    dev/ttyUSB=PORT_SERIAL
  14. (Optional) You might find is useful to add the following functions to your ~/.bashrc file:

    function telosb_install {
       make telosb install.${1} bsl,/dev/ttyUSB0;
    }
    function telosb_reinstall {
       make telosb reinstall.${1} bsl,/dev/ttyUSB0;
    }
    function mica2_install {
       make mica2 install.${1} mib510,/dev/ttyS0;
    }
    function mica2_reinstall {
       make mica2 reinstall.${1} mib510,/dev/ttyS0;
    }

    For ease of use so that you can execute the commands:

    telosb_install 3;
    mica2_install 3;

    Where "3" can be replaced to specify the desired ID for the mote.

Code

My TinyOS code is available on the Project Code Page.