Installing tinyos-2.x on Mac OS X (Tiger & Leopard)

From TinyOS Wiki
Revision as of 13:42, 19 October 2007 by Klueska (talk | contribs) (New page: <div id="decoration1" style="display: none"><div id="publishinfo"> {| id="navigation" width="100%" | width="80%" align="center" | <div id="published" class="smalltext" style="display: non...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Installing tinyos-2.x on Mac OS X (Tiger)

This tutorial provides instructions for getting tinyos-2.x up and running on Mac OS X v10.4 (Tiger). This procedure has been tested on an intel dual core Macbook Pro, but should be helpful for other platforms as well. If you run into problems, find that something doesn't work for you in this tutorial, or want to provide feedback of any kind, feel free to email me (Kevin Klues) at klueska(at)gmail.com and I'll try and update this tutorial as soon as possible.

This tutorial assumes that you are installing tinyos-2.x from a vanilla distribution of Tiger without any additional software. Because of this, some of the initial steps involve setting up the development tools and other additional software that is required by more important steps later on. Some of these steps may be skipped if you think you have already performed them, but be warned that doing anything other than following the procedure listed here may cause you to run into problems.

OK, lets get started.....

Installing the Developer Tools

If you are doing any sort of development work at all in OS X it's probably a good idea to download the set of tools described in this section. You can either install them directly from the Tiger installation cd or from the apple developer website. Most of you will probably have already completed this step before reading this tutorial.

Installing from the installation cd:

Installing from the cd is very straightforward and much faster than downloading the XCode developer tools from the website. Simply insert the tiger installation cd and follow the steps listed below.
  • Open the Xcode Tools folder in the Finder window that pops up
    • If no finder window pops up, just open a new one and select the installation CD from the list of mounted drives in the Toolbar
  • Double click XCodeTools.mkpkg and run the installation
Installing from the developer website:

If you decide to install these tools from the developer website, you will need to sign up for a developer account. After signing in, go to the Downloads section and select Developer Tools from the Download menu on the right hand side of the screen. Scroll down to Xcode Tools 2.2.1 and download the disk image to your hard drive. Once you have downloaded the '.dmg' file follow the instructions below to install the Xcode tools.
  • Open a Finder window and browse to the location you saves the Xtools disk image.
  • Open the downloaded xcode_2.2_*.dmg file to mount the disk image
  • Double click on XCodeTools.mkpkg and run the installation

Installing Fink

Fink is a package management system for Mac OS X that uses the Debian tools dpkg and apt-get to perform its package management features. The fink project aims to "bring the full world of Unix Open Source software to Darwin and Mac OS X". For more information on fink, please see the official Fink website.

For non-intel-based Macs (i.e. PPC), fink can be installed using the binary installer found here.
For intel-based Macs, use this one.

Once fink is installed, its probably a good idea to run the 'selfupdater' that comes with it to make sure you have the most recent version. Just run fink selfupdate' and let it take its time to complete. After this you will probably want to run fink configure' as well.


Once fink is done self updating and you have configured it properly, packages can be installed by running fink install <package>. For a list of available packages, please refer to the fink package distribution website.


NOTE: Some of the packages included in this installation are only available from the unstable fink tree. You will have to instruct fink to look in this tree when trying to install its packages. Please refer to FAQ question 5.8 to learn how to do so.

Installing Stow

Once you have installed fink, a whole new world of applications are made available for use on the Mac. One of these programs is known as stow. Stow is another package management system similar to fink, but it contains some slightly different features. Stow allows one to "organize applications available in standard tar files and keep application binaries logically arranged for easy access". We will be using stow to keep our installation of the various tools required by tinyos-2.x organized. More information about stow can be found at this website.

Now that we have fink at our disposal, installing stow is very straight forward. We simply need to run the following command.
  • sudo fink install stow
  • cd /sw
  • sudo mkdir stow
Thats all there is too it. We create a folder called stow in /sw though so that we have a consistent place for installing all of the programs found below. How to actually perform these installations using stow will become clear later on in the tutorial.

Downloading tinyos-2.x from cvs

For anonymous cvs access, browse to the location where you want to install the tinyos-2.x source tree and run the following set of commands.

  • 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
If you are a developer (and you know it if you are), browse to the location where you want to install the tinyos-2.x source tree and run this alternate set of commands, replacing developername with your sourceforge username as appropriate.
  • export CVS_RSH=ssh
  • cvs -z3 -d:ext:developername@tinyos.cvs.sourceforge.net:/cvsroot/tinyos co -P tinyos-2.x

You will also want to download tinyos.sh for setting up your tinyos environment variables correctly. You will need to edit this file to have TOSROOT point to the absolute path of your tinyos-2.x installation directory. You can put this file wherever you please, but I have chosen to place it inside of my tinyos-2.x folder. I have also added the line "source $TOSROOT/tinyos.sh" into the '.profile' file in my home directory so that this script gets run any time I open a new shell. Again, if you choose to do this, $TOSROOT will have to be replaced with the absolute path to your tinyos-2.x tree.

Installing nesc

tinyos-2.x requires nesc-1.2 or higher in order to compile source code to binaries. The steps involved in installing nesc version 1.2.9 can be seen below.
  • NOTE: If you plan to install the avr tools for mica support, make sure to use nesc 1.2.9 or above!!
  • Download the nesc-1.2.9 tarball from sourceforge (or whichever is the newest)
  • Install nesc using the standard configure/make/make install procedure
    • cd nesc-1.2.9
    • ./configure --prefix=/sw/stow/nesc-1.2.9
    • make
    • sudo make install
  • Run stow to install nesc into standard installation directories
    • cd /sw/stow
    • sudo stow nesc-1.2.9

Installing avr tools for Mica Support

To get the newest avr tools simply run the following...
  • sudo fink install avr-libc1.4
  • sudo fink install avr-gcc
  • sudo fink install avr-binutils
In order to get these versions of the avr tools to work nicely with nesc you will have to modify the default avr.rules file in your $TOSROOT/support/make/avr folder.
  • Open your $TOSROOT/support/make/avr/avr.rules file
  • Go to line 32 and add the following definition
    • NESC_SEPARATOR = \never1096WritE
  • Now go to line 33 (AMADDR= .......) and change it to
    • AMADDR = ActiveMessageAddressC$(NESC_SEPARATOR)addr
  • Finally go to line 42 (PFLAGS += .......) and add the flag
    • -fnesc-separator=$(NESC_SEPARATOR)
By default nesc uses the "$" character to create symbol names in the C code that it ultimately generates. Using this symbol causes compilation errors by the standard avr tools that have just been installed. To get around this problem, we are able to specify a new value for use by nesc when generating its symbol names for C. The value for the NESC_SEPARATOR that you specify is arbitrary as long as you can be reasonably sure that it will never be used anywhere in the code that you write. Please note that the "\" character at the beginning of the directive is intentional. Without it, you would only be able to specify a single character instead of an entire string.

Installing msp430 tools for Telos Support

Getting the msp430 tools to compile correctly was a bit tricky. Because of this, I am right now just providing a tarball with all of the compiled binaries. When I have time, I will update this tutorial to include instructions on how to compile these tools yourself, but to get people going immediately, here is how to install the binaries.

For intel-based Macs:
  • Download the tarball found here.
  • Extract the tarball into your /sw/stow directory
    • tar zxvf msp430_tools-i686-apple-darwin.tar.gz
    • sudo mv msp430 /sw/stow/
  • Use stow to install the tools
    • cd /sw/stow
    • sudo stow msp430

For power pc based Macs (binaries compliments of Ram Kumar from UCLA):

  • Download the tarball found here.
  • Extract the tarball into your /sw/stow directory
    • tar zxvf msp430toolchain.tar.gz
    • sudo mv msp430 /sw/stow/
  • Use stow to install the tools
    • cd /sw/stow
    • sudo stow msp430

Installing FTDI Drivers

Go tothis web address and download the drivers appropriate for your platform.
Install the drivers by opening up the disk image file and double clicking on FTDIUSBSerialDriver.pkg.

Installing the tinyos-2.x toolset

(Note: Before proceeding further, make sure you have setup your tinyos.sh script correctly and have run it in the current environment.)

Now, cd into your $TOSROOT directory and run the following commands:
  • cd tools
  • ./Bootstrap
  • ./configure --prefix=/sw/stow/tinyos-2.x-tools
  • make
  • sudo make install
  • cd /sw/stow/
  • sudo stow tinyos-2.x-tools
  • sudo tos-install-jni
  • cd $TOSROOT/support/sdk/java
  • make
Depending on the version of java you have installed you may see some warnings during this stage of compilation. As long as you don't see any errors, you should be good to go.

Compiling an Application

Run the following commands to compile the Blink application for telosb
  • cd $TOSROOT/apps/Blink
  • make telosb

If all has gone well, the compilation should complete without problems. There will probably be an error, however, in executing the command objdump and displaying the correct number of bytes in RAM and ROM. This is due to the lack of objdump and ld in Mac OS X. This error will not hav any adverse affects on compiling or installing your program however, so it is safe to continue.


One way to avoid this error is to create links from your msp430-objdump into your standard /sw/bin directory.

  • cd /sw/bin
  • sudo ln -s msp430-objdump objdump
Since avr and msp430 binaries are both stored in standard elf format, this new link will work for binaries compiled for both mica and telos based platforms.

Installing an Application for Mica Based Motes

Since the mica motes need to be programmed from a programming board that only has a serial input, the first thing you will need to do is get ahold of a USB-serial cable that is compatible with your mac. I've been told that most of the ones out there work, but if you run into problems in this section you may want to try a different cable before proceeding.

OK, so once you have your cable and you have connected it to your MIB510 programming board, simply run the following commands:
  • cd $TOSROOT/apps/Blink
  • make mica2 install mib510,/dev/'<serialport>'
Where <serialport> gets replaced by the tty device used by your USB-serial cable. (On my machine this was at /dev/tty.USA19H5d1P1.1).

Installing an Application for telos Based Motes

Installing an application on a telosb mote in Mac OS is similar to how it is done in linux except for in how the USB device itself is named.
Installing the Blink application on a telos mote that has an FTDI chip with serial ID M4A5L58H would be performed as follows:
  • cd $TOSROOT/apps/Blink
  • make telosb install bsl,/dev/tty.usbserial-M4A5L58H

To see which telos devices you currently have plugged in, you can always run the command motelist and match the serial ids against the devices listed in your /dev directory.

Running a Java Application

To test that serial applications are running on Java, we can use the TestSerial application in the tinyos-2.x/apps/tests directory. Simply run the following.
  • For Telos based motes
    • cd $TOSROOT/apps/tests/TestSerial
    • make telosb install bsl,/dev/tty.usbserial-M4A5L58H
    • java TestSerial -comm serial@/dev/tty.usbserial-M4A5L58H:telos
  • For mica based motes
    • cd $TOSROOT/apps/tests/TestSerial
    • make mica2 install mib510,/dev/tty.USA19H5d1P1.1
    • java TestSerial -comm serial@/dev/tty.USA19H5d1P1.1:mica2

NOTE: See the 'telosb' and 'mica2' directives at the end of the call to 'java TestSerial'. If you install this application on the micaz, or tmote platforms you will want to make sure you change this accordingly.

You should now see output similar to the following:

$ java TestSerial -comm serial@/dev/tty.usbserial-M4A5L58H:telos
serial@/dev/tty.usbserial-M4A5L58H:115200: resynchronising
Sending packet 0
Received packet sequence number 4481
Sending packet 1
Received packet sequence number 4482
Received packet sequence number 4483
Sending packet 2
Received packet sequence number 4484
Sending packet 3
Received packet sequence number 4485
Sending packet 4
Received packet sequence number 4486
Sending packet 5
Received packet sequence number 4487
Sending packet 6
Received packet sequence number 4488
Sending packet 7
Received packet sequence number 4489
...

If all has worked out, you should be be up and running with your new installation of tinyos-2.x on Mac OS X!!!!
Questions or comments can either be sent directly to me (klueska(at)gmail.com) or the tinyos-help mailing list.