HOWTO TinyOS 2.x on Gentoo (using MoteIV Sky motes)

The first thing to do is double-check that your kernel is configured to create the special device file under /dev directory. To do this plug in your mote to the USB port and look in the /dev directory for ttyUSB0 (generally if you have other devices plugged in, the number in the end may be > 0, it's safer to do ls -l /dev/ttyUSB*). For other types of motes the special device file created may be differ: e.g. ttys0. Another way of checking what special device files your kernel generates is by doing (make sure the mote is unplugged when you type the first line, and plugged in when you type the second line):

ls -l /dev > before
ls -l /dev > after
diff before after

If you your kernel does not generate the special device files under /dev it may mean that you do not have USB Serial Converter Support enabled in your kernel. To double check this, do:

cd /usr/src/linux
make menuconfig

This will get you into the kernel config menu. Navigate to device drivers and then USB Support, and have a look at the general options to check if there is anything that you might need. As a rule of thumb make sure you have the USB host controller drivers enabled (OHCI, UHCI, EHCI). To enable USB-Serial Converted support make sure you include FTDI Driver (experimental). Re-compile your kernel (if you haven't done this before have a look at http://gentoo-wiki.com/HOWTO_Index under Kernel & Hardware and also take a look at USB while you are there. Also it might worth having a scan at http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=7 for general info on kernel configuration).

Once your kernel compiled, and you have rebooted, you should be able to plug in your mote in the USB port and see the ttyUSB0 (or > 0) special device file under the /dev directory. This means you are good to go with the installation.

Install Required Components

The general idea is outlined in the good TOS website under installation instructions. The first thing to do is install a Java SDK; we are installing IBM's SDK with the Java Comm API. It can be found on their website.

Next thing to do is install the native compilers. This document assumes you are using MoteIV's Tmote Sky (or Telos B) that has the TI MSP430. If you are using a different platform then you need to take a look at the TOS website and download the appropriate compilers for your platform. The tools you need to download are the following:

If you already use gentoo you 'll know that there is no default support for RPMs. You need to install a package of your choice to deal with this, I chose rpm2targz (but you may prefer to install the RPM itself by emerge rpm); as the name suggests rpm2targz converts and rpm package into a tar.gz. Then you can uncompress it and untar it in a location of your choice (note that a sensible choice for all the msp430 tools is /opt, if you install them elsewhere -not recommended- make sure your PATH points at them).

Install TOS Toolchain and Source Tree

Again following the instructions from TOS website:

Same thing goes as the above point about RPMs; use a package of your choice if you don't have RPM.

Configure your environment

As the instructions from TOS website, you need to configure:

It makes sense to put these lines either in your .bashrc or in a script or in your .profile so you don't have to type them in every time. Also note the dot (.) in the CLASSPATH is rather important; if you omit it, classes in the pwd will not be included and you will get compilation errors.

Install Graphviz (Optional)

Go to their download page and get the basic graphviz rpm (you don't need all the add-ons).

Follow instructions from TOS Tutorials

Start with Lesson 1. After you run tos-check-env and everything is ok, plug your mote in and type:

sudo chmod 666 /dev/ttyUSB0
cd $TOSROOT/apps/Blink
make tmote install

You will see the program getting compiled and the .ihex file getting copied to your mote using the msp430-bsl. Once the upload is done, the LEDS on the mote should blink. If anything fails, make sure you go to Lesson 1 and check if your error is listed.

Mote-to-PC Serial Comm

There is a tutorial in Lesson 4 that explains how to do this. However this hasn't worked for me. I had trouble with JNI finding the libtoscomm.so shared library (when it was clearly there), and once it found it a got a bunch of seg faults. Apparently few others had the same issue. So I decided to go with javacomm. Many people complain that javacomm is buggy and does not work properly but I did not have any problems whatsoever.

So to go with the java comm way rather than the libtoscomm way, you need to get tinyos-1.x/tools/java/net/tinyos/packet/SerialByteSource.java from sourceforge CVS. Replace the existing file in support/sdk/java/net/tinyos/packet with the one you just got from CVS. Go to support/sdk/java and type make to recompile all the classes and then make tinyos.jar to update the tinyos.jar with the new classes. Then go to the installation directory of your SDK and look for javax.comm.properties file (it should be in jre/lib or jre/lib/ext). At the end of the file you should see a line saying "uncomment the line below for USB-Serial support". Do as it says, uncomment the line. Now go to:

cd $TOSROOT/apps/tests/TestSerial
make tmote install
java TestSerial -comm serial@/dev/ttyUSB0:tmote

If everything works then you should see the output as outlined in Lesson 4.