back to homepage

Setting up TinyOS-2.x/Tmote on MacOS X

Abstract

These instructions describe how a TinyOS-2.x cross-development environment for tmote Sky (MSP430) platform can be setup on MacOS from CVS source code. Note: The steps described below successfully set up a working environment on Apple MacOS X 10.4.10 on PowerPC (G5). Other platforms were not tested.

The old instructions for TinyOS-2.x/Mica2 (AVR) can still be found here.

Outline

Setting up the cross-development environment on the Mac requires a working GNU toolchain and a couple of GNU tools, such as wget. The installation process consists of the following steps:

  1. Installation of the Fink distribution
  2. Installation of the MSP430 tool chain (from source)
  3. Get the TinyOS-2.x sources from CVS and setup the environement
  4. Installation of the nesC compiler
  5. Building of the TinyOS tools
  6. Installation of MacOS FTDI driver for the tmote

In the description that follows we use the following directories. If you want to use a different layout please apply the corresponding changes.

1. Installation of the Fink Distribution

Download the Fink installer (Intel or PowerPC) from www.finkproject.org. Follow the installation instructions. In the sequel we assume that the default installation directory /sw is used for the Fink packages.
Install at least the following packages: autoconf, automake, bzip2, cvs, fileutils, gzip, m4, tar, wget, vim-nox. Make sure that the /sw appears before /usr/bin and /bin in the PATH environment variable, such that the Fink tools are used instead of the MacOS X system tools.

2. Installation of MSP430 tool chain

The MSP430 tool chain, i.e., binutils, libc and gcc, can confortably be built from a script. This script can be found in the TinyOS-1.x CVS distribution. So, we first check out the tinyos-1.x sources:

$ cd ~
$ mkdir TinyOS
$ cvs -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos login 
<hit return>
$ cvs -z3 -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos co -P tinyos-1.x
...

Before we can start the script we need to edit it. The script defines its new PATH environment variable. We must edit this variable such that our /sw Fink directory appears first.

$ cd tinyos-1.x/tools/src/mspgcc
$ vim build-mspgcc

Edit the line

export PATH="$INSTALL_DIR/bin:/usr/local/bin:/usr/bin:/bin/"

to

export PATH="$INSTALL_DIR/bin:/sw/bin:/usr/local/bin:/usr/bin:/bin/"

Start the script as user root since we are going to install the tools right away:

$ sudo bash 
Password:
# INSTALL_DIR=/usr/local/msp430 ./build-mspgcc install
...

3. Get the TinyOS-2.x sources and setup the environment

Download the TinyOS-2.x from CVS:

$ cd ~<YOUR-USERNAME>/TinyOS
$ cvs -z3 -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos co -P tinyos-2.x

The build process in TinyOS-2.x is controlled by a number of environment variables. Depending on their setting one can either build TinyOS-1.x or TinyOS-2.x projects. Therefore, I put two shell scripts into each TinyOS directory (1.x and 2.x) that setups the environment variables. The following is for TinyOS-2.x:

$ cd tinyos-2.x
$ vim setupenv.sh   

Add this to the file:

export TOSROOT=/Users/<YOUR-NAME>/TinyOS/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java/tinyos.jar:.
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/usr/local/msp430/bin:$PATH

Before building a project simply source this file. Do this now (remember to redo it in case you repoen the console).

$ source ./setupenv.sh

4. Install the nesC Compiler

Download the nesC compiler (nesC 1.2.8a) from sourceforge. Place the nesc-1.2.8a.tar.gz file into the tinyos-2.x directory and untar it (once you installed the compiler into /usr/local/msp430 you can remove it again.

$ tar xfz nesc-1.2.8a.tar.gz
$ cd nesc-1.2.8a
$ ./configure --prefix=/usr/local/msp430
$ make 
$ sudo make install

5. Building of the TinyOS tools

Now things start getting really tricky as we have to build the Java native code for the getenv (I do not know why they insist of reading environment variables from Java, here one could use Java properties anyway, but that is beside the point) and the toscomm library. The later is the long awaited replacement for the problematic CommAPI from Sun. Unfortunately, MacOSX is not really supported by TinyOS-2.x crew. They added native code for the darwin platform but it is not correctly integrated in the GNU build process. So we need to do it ourselves. The first thing we need to do is to make sure that the native code for JNI stuff is build correctly. We edit the ~/TinyOS/tinyos-2.x/tools/tinyos/java/env/Makefile.am. So change

EXTRA_PROGRAMS = ibgetenv-32.so libgetenv-64.so getenv.dll 

to

EXTRA_PROGRAMS = libgetenv.jnilib libgetenv-32.so libgetenv-64.so getenv.dll

and add at the end of the file

libgetenv.jnilib: net_tinyos_util_Env.h net_tinyos_util_Env.c
<THIS-NEEDS-TO-BE-A-TAB>gcc -o $@ -dynamiclib \
   -I/System/Library/Frameworks/JavaVM.framework/Headers \
   -framework JavaVM net_tinyos_util_Env.c 

Next, we need to adapt the automake file for the second JNI library 'libtoscomm.jnilib'.

$ cd ~/TinyOS/tinyos-2.x/tools/java/serial
$ vim Makefile.am

Edit Makefile.am in this directory as well. Change and add

 
   EXTRA_PROGRAMS = libtoscomm-32.so libtoscomm-64.so toscomm.dll

to

EXTRA_PROGRAMS = libtoscomm.jnilib libtoscomm-32.so libtoscomm-64.so toscomm.dll

libtoscomm_jnilib_SOURCES = \
   NativeSerialEnums.h \
   NativeSerial_darwin.cpp \
   TOSComm_wrap.cxx

Before the line starting with "libtoscomm-32.so: $(libtoscomm_32_so_SOURCES)" add:

libtoscomm.jnilib: $(libtoscomm_jnilib_SOURCES)
<THIS-NEEDS-TO-BE-A-TAB>$(CXX) -o $@ -O2 -dynamiclib \
   -I/System/Library/Frameworks/JavaVM.framework/Headers \
   -framework JavaVM NativeSerial_darwin.cpp 

Now we need to change platform recognition such that libgetenv.jnilib and libtoscomm.jnilibwill be built on our darwin system. Open ~/TinyOS/tinyos-2.x/tools/configure.ac in a text editor. Change the section

AC_MSG_CHECKING(for cygwin)
case $host in
  *-*-cygwin*)
    AC_MSG_RESULT(yes)
    JNIPREFIX=
    JNISUFFIX=dll
    JNIVERSIONS=.
    INSTALLJNI="install --group=SYSTEM"
    CYGWIN=yes
    ;;
  *)
    JNIPREFIX=lib
    JNISUFFIX=so
    JNIVERSIONS="-32. -64."
    INSTALLJNI="install"
    AC_MSG_RESULT(no)
esac

into the section

AC_MSG_CHECKING(for platform)
case $host in
  *-*-cygwin*)
    AC_MSG_RESULT(cygwin)
    JNIPREFIX=
    JNISUFFIX=dll
    JNIVERSIONS=.
    INSTALLJNI="install --group=SYSTEM"
    CYGWIN=yes
    ;;
  *-*-darwin*)
    JNIPREFIX=lib
    JNISUFFIX=jnilib
    JNIVERSIONS=.
    INSTALLJNI="install"
    AC_MSG_RESULT(darwin)
    ;;
  *)
    JNIPREFIX=lib
    JNISUFFIX=so
    JNIVERSIONS="-32. -64."
    INSTALLJNI="install"
    AC_MSG_RESULT(linux)
esac

That should be it...
Next, run the run the bootstrap scripts that switch on the autoconf/automake machinery which will generate the configure scripts.

$ cd ~/TinyOS/tinyos-2.x/tools
$ ./Bootstrap

Now run configure.

$ cd ~/TinyOS/tinyos-2.x/tools
$ ./configure --prefix=/usr/local/msp430

Give it a try...

$ cd ~/TinyOS/tinyos-2.x/tools
$ make 
$ sudo make install

That should be it!

6. Installation of MacOS FTDI driver

The Tmote has a FTDI USB serial chip. Download and install a driver (kernel extension) for MacOS from FTDI Chip. You will have to restart your machine. After you restarted the computer connect a Tmote node. You should now see a new device in /dev. The device name carries the serial number of the chip. You will then use this name when programming or accessing the node. For example:

$ ls -la /dev/tty.* 
crw-rw-rw-    1 root     wheel      9,   4 Jul  7 20:15 /dev/tty.usbserial-M4AJ0EMP

7. Compiling a NesC Program

Try to compile the Blink example.

$ cd ~/TinyOS/tinyos-2.x/apps/Blink
$ make telosb
mkdir -p build/telosb
    compiling BlinkAppC to a telosb binary
ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DIDENT_PROGRAM_NAME=\"BlinkAppC\" -DIDENT_USER_ID=\"muellren\" -DIDENT_HOSTNAME=\"quad.home.ch\" -DIDENT_USER_HASH=0xa1f3929fL -DIDENT_UNIX_TIME=0x4690104bL -DIDENT_UID_HASH=0xc33c81ccL  BlinkAppC.nc -lm 
    compiled BlinkAppC to build/telosb/main.exe
            2664 bytes in ROM
              55 bytes in RAM
msp430-objcopy --output-target=ihex build/telosb/main.exe build/telosb/main.ihex
    writing TOS image

Flash the mote. Note you need to specifcy the device with the name from step 6.

$ cd ~/TinyOS/tinyos-2.x/apps/Blink
$ make telosb install,0 bsl,/dev/tty.M4AJ0EMP

8. Testing the Mote-to-PC link

In order to test the communication from the mote to the PC (and the toscomm library) we use to nodes. On node 1 we install the RadioCountToLeds application that sends count messages over the radio. On node 0 we install the BaseStation which receives these messages and forwards them over the USB serial link to the Mac where we use a Java program to dump these messages.

We install the RadioCountToLeds application. So connect node1 to the Mac.

$ cd ~/TinyOS/tinyos-2.x/apps/RadioCountToLeds
$ make telosb install,1 bsl,/dev/tty.usbserial-M4AJ0EMH
mkdir -p build/telosb
    compiling RadioCountToLedsAppC to a telosb binary
ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DIDENT_PROGRAM_NAME=\"RadioCountToLed\" -DIDENT_USER_ID=\"muellren\" -DIDENT_HOSTNAME=\"quad.home.ch\" -DIDENT_USER_HASH=0xa1f3929fL -DIDENT_UNIX_TIME=0x469012afL -DIDENT_UID_HASH=0xafefdaa2L  RadioCountToLedsAppC.nc -lm 
    compiled RadioCountToLedsAppC to build/telosb/main.exe
           10804 bytes in ROM
             286 bytes in RAM
msp430-objcopy --output-target=ihex build/telosb/main.exe build/telosb/main.ihex
    writing TOS image
tos-set-symbols --objcopy msp430-objcopy --objdump msp430-objdump --target ihex build/telosb/main.ihex build/telosb/main.ihex.out-1 TOS_NODE_ID=1 ActiveMessageAddressC$addr=1
    installing telosb binary using bsl
tos-bsl --telosb -c /dev/tty.usbserial-M4AJ0EMH -r -e -I -p build/telosb/main.ihex.out-1
MSP430 Bootstrap Loader Version: 1.39-telos-8
Mass Erase...
Transmit default password ...
Invoking BSL...
Transmit default password ...
Current bootstrap loader version: 1.61 (Device ID: f16c)
Changing baudrate to 38400 ...
Program ...
10836 bytes programmed.
Reset device ...
rm -f build/telosb/main.exe.out-1 build/telosb/main.ihex.out-1

Now, connect node 0 and install the BaseStation application.

$ cd ~/TinyOS/tinyos-2.x/apps/BaseStation 
$ make telosb install,0 bsl,/dev/tty.usbserial-M4AJ0EMP     
mkdir -p build/telosb
    compiling BaseStationC to a telosb binary
ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DCC2420_NO_ACKNOWLEDGEMENTS -DCC2420_NO_ADDRESS_RECOGNITION -DIDENT_PROGRAM_NAME=\"BaseStationC\" -DIDENT_USER_ID=\"muellren\" -DIDENT_HOSTNAME=\"quad.home.ch\" -DIDENT_USER_HASH=0xa1f3929fL -DIDENT_UNIX_TIME=0x46901319L -DIDENT_UID_HASH=0xdf7a733bL  BaseStationC.nc -lm 
    compiled BaseStationC to build/telosb/main.exe
           13170 bytes in ROM
            1610 bytes in RAM
msp430-objcopy --output-target=ihex build/telosb/main.exe build/telosb/main.ihex
    writing TOS image
tos-set-symbols --objcopy msp430-objcopy --objdump msp430-objdump --target ihex build/telosb/main.ihex build/telosb/main.ihex.out-0 TOS_NODE_ID=0 ActiveMessageAddressC$addr=0
    installing telosb binary using bsl
tos-bsl --telosb -c /dev/tty.usbserial-M4AJ0EMP -r -e -I -p build/telosb/main.ihex.out-0
MSP430 Bootstrap Loader Version: 1.39-telos-8
Mass Erase...
Transmit default password ...
Invoking BSL...
Transmit default password ...
Current bootstrap loader version: 1.61 (Device ID: f16c)
Changing baudrate to 38400 ...
Program ...
13202 bytes programmed.
Reset device ...
rm -f build/telosb/main.exe.out-0 build/telosb/main.ihex.out-0

Now, we can start Java Listener program on the Mac and it will dump the packages sent by node 1.

$ java net.tinyos.tools.Listen -comm serial@/dev/tty.usbserial-M4AJ0EMP:telos 
serial@/dev/tty.usbserial-M4AJ0EMP:115200: resynchronising
00 FF FF FF FF 02 00 06 00 01 
00 FF FF FF FF 02 00 06 00 02 
00 FF FF FF FF 02 00 06 00 03 
00 FF FF FF FF 02 00 06 00 04 
00 FF FF FF FF 02 00 06 00 05 
00 FF FF FF FF 02 00 06 00 06 
00 FF FF FF FF 02 00 06 00 07 
00 FF FF FF FF 02 00 06 00 08 
00 FF FF FF FF 02 00 06 00 09

Contratulations! You have now a working TinyOS-2.x/Tmote programming environment on your Mac. The old instruction for TinyOS-2.x/Mica2 (AVR) can still be found here.


René Müller
last updated: July 8th, 2007

Valid XHTML 1.0 Strict