Vagrant-based TinyOS Install

Here’s a quick procedure to get you up and running with TinyOS. Although it’s aimed and Windows users, it should work on Mac and Linux with some tweaks here and there.

The method proposed here runs the virtualbox in “headless” mode, which means that you only see a command line under Ubuntu Linux and not the whole windowing system. Don’t worry, you can use your favourite Windows editor to edit as all the important files will be accessible under Windows.

Step 1. Check that you have virtualization turned on

https://bce.berkeley.edu/enabling-virtualization-in-your-pc-bios.html

Virtualization is needed for the virtualbox to run normally but some laptop manufacturers turn it off by default. If you skip this step, you might see errors when you try to start Ubuntu. For example, it might suggest you enable PAE/NX (but don’t do this!). If you have a 64-bit CPU, this shouldn’t be needed and if you don’t, you can switch to using a 32-bit version of Ubuntu by changing the Vagrantfile.

Step 2. Install VirtualBox

Go to https://www.virtualbox.org/wiki/Downloads and download a recent version.

Step 3. Download and install the VirtualBox Oracle VM VirtualBox Extension Pack from the same address.

The extension pack is required for USB 3.0 and so if you later find that you haven’t got this option enabled, it’s probably because your extension pack is not properly installed. Note that downloading it is not enough, you need to get it installed into VirtualBox.

Step 4. Download and install Vagrant

http://www.vagrantup.com/downloads.html

Vagrant is a great tool for setting up virtual machines automatically.

Step 5. Download this Vagrantfile

https://raw.githubusercontent.com/jbrusey/cogent-house/master/Vagrantfile
After clicking on the link, you’ll see a text file. You need to tell your web-browser to save the page.

Note: Windows wants to put a file type of “.txt” on the end of this file name. You will need to manually rename this after downloading.

ren Vagrantfile.txt Vagrantfile

It contains a script—written in Ruby—that tells Vagrant what to do to install TinyOS on a Ubuntu virtual machine. Here’s the start:

# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT

The first line is an instruction to Emacs and the second to Vim, both to set the syntax highlighting etc to Ruby mode. The next line builds a script file (written in bash) and puts that in $script.

The script is run when the virtual box is provisioned or set-up for the first time. Let’s look at the first step:

wget -O - http://tinyprod.net/repos/debian/tinyprod.key | sudo apt-key add -
# add tinyprod to apt sources
tee -a /etc/apt/sources.list >/dev/null <<APTEOF
deb http://tinyprod.net/repos/debian squeeze main
deb http://tinyprod.net/repos/debian msp430-46 main
APTEOF

This downloads the public signing key for the tinyprod repository, installs it, then appends the tinyprod repository to the list of apt sources.
The rest of the script installs various bits of software, including linux-image-extra-virtual, which is needed for the FTDI driver that talks to the mote.

Step 6. Make a folder for your system

Create a folder or directory and put the Vagrantfile that you downloaded in the last step here.

Step 7. Open a terminal window and cd to folder

Open a terminal window. On Windows, this is done by going to the start menu and typing cmd. When you get a command prompt, you need to cd to the directory that you just created. If you don’t know how to do this, try searching for a tutorial on google. When you’ve got to the right directory, use dir to check to see that you can see the Vagrantfile there.

Step 8. Install vbguest plugin

Note: with the latest release, it seems to be better to put off installing the plugin until after Step 11.

To install, in the command window, type

vagrant plugin install vagrant-vbguest

to install the vagrant virtualbox guest installer. The VirtualBox guest is software that will be installed on your guest Ubuntu system. This is important as it allows us to share some disk space between the host (Windows) and the guest (Ubuntu), which is going to make it easier to edit files.

Step 9. Start the main install

From the command window, while in the folder with the Vagrantfile, type this:

vagrant up

This may take a while as it has lots to download. If you are on a slow connection and can move to a faster one, now is the time. Otherwise, time to make a coffee!

Note: if you get a message suggesting you need to do a vagrant init at this stage, it means that you are in the wrong directory. Don’t just do the vagrant init! Rather, you should go back and cd into the directory you created for the Vagrantfile.

Step 10. Reload

Once the vagrant up completes, you should see a recommendation about rebooting several times. You can do this with

vagrant reload

This step is needed because the provisioning process installs kernel drivers that are not installed until after a reboot.

Step 11. Test it out

To login to the system (after bringing it up with vagrant up), use

vagrant ssh

This will bring you to a command prompt that looks like this.

Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-143-generic x86_64)
...
Setting up for TinyOS
vagrant@vagrant-ubuntu-trusty-64:~$

If the guest additions have installed correctly, ls /vagrant should be non-empty, which means that it has correctly shared the folder that you put Vagrantfile in.

ls /vagrant
Vagrantfile

Now we’ll copy the Blink app into that directory:

cd /vagrant
cp -r /opt/tinyos-main/apps/Blink .

Compiling it is easy:

cd Blink
make telosb

. The result should look something like this:

mkdir -p build/telosb
    compiling BlinkAppC to a telosb binary
ncc -o build/telosb/main.exe  -Os -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DDEFINED_TOS_AM_GROUP=0x22 -DIDENT_APPNAME=\"BlinkAppC\" -DIDENT_USERNAME=\"vagrant\" -DIDENT_HOSTNAME=\"vagrant-ubuntu-\" -DIDENT_USERHASH=0x08307f04L -DIDENT_TIMESTAMP=0x5ab51409L -DIDENT_UIDHASH=0x787f74f2L  BlinkAppC.nc -lm 
    compiled BlinkAppC to build/telosb/main.exe
            2538 bytes in ROM
              56 bytes in RAM
msp430-objcopy --output-target=ihex build/telosb/main.exe build/telosb/main.ihex
    writing TOS image

Program a Telos mote

The Vagrantfile is set up to recognise Telos motes. Assuming that this is what you have, plugging the mote in and typing motelist should show you something like:

Reference  Device           Description
---------- ---------------- ---------------------------------------------
FTWGRY9A   /dev/ttyUSB0     FTDI MTM-CM5000MSP

If you get “no motes found” at this stage, it probably means that virtualbox is not grabbing the mote for you. See below for more info on how to fix this.

With the mote still plugged in, type

make telosb install

and you should see the same compile output as before, plus:

    found mote on /dev/ttyUSB0 (using bsl,auto)
    installing telosb binary using bsl
tos-bsl --telosb -c /dev/ttyUSB0 -r -e -I -p build/telosb/main.ihex.out
MSP430 Bootstrap Loader Version: 1.39-goodfet-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 ...
2598 bytes programmed.
Reset device ...

If you have problems here, it is usually something to do with the configuration of the VM (such as, not having USB 3.0 configured).

Once you’ve gotten this far, you can go and do the tutorial at: http://tinyos.stanford.edu/tinyos-wiki/index.php/Getting_Started_with_TinyOS

Things that can go wrong

These instructions depend on components that sometimes get broken. For example, the squeeze repository for tinyprod seems fine whereas the wheezy, not so much. The first rule when things don’t happen as expected is to carefully read the error message and google it if you still don’t understand.

/vagrant is empty or not found

This usually means that vboxsf didn’t get installed or is the wrong version for your guest operating system.

motelist doesn’t give a /dev/tty address

If your mote is plugged in but not being listed by motelist, there are several things to check.

  1. It could be something to do with the USB port. Try another one, if you can.
  2. It could be that the device filter is wrong. The Vagrantfile given has a filter for clone Telos motes only, so you may need to add additional filters to get your host to give the guest VM access, if you have a different sort of device.
  3. If you see a line for the mote, but no /dev/tty, it could be that the FTDI drivers are not installed. Try using dpkg -l linux-image-extra-virtual to see if you have them installed. If not, there may be other elements not installed and it is worth checking everything by looking through the Vagrantfile. Another possible cause here is that your system needs to be rebooted.

You only have a 32-bit processor

There’s a simple fix for this one. Just edit the Vagrantfile and change the line that says

config.vm.box = "ubuntu/trusty64"

so that it points to "ubuntu/trusty32". There is a problem with this image, though, in that the ethernet driver doesn’t work with the default ethernet card in VirtualBox. To fix this, change the ethernet card setting in VirtualBox to emulate a different card.

Vagrant hangs after “VirtualBox Guest Additions: Starting.”

I had this happen after upgrading to Vagrant 2.2.3 and VirtualBox 6.0.4. It seems to be due to a problem with the vagrant-vbguest plugin.

Having done many hours of testing last night trying various options, it seems like the simplest approach is to Ctrl-C out of the VirtualBox Guest Additions: Starting. message and then vagrant reload. Once it is up, use vagrant ssh to check that it is working ok. To test, try

ls /vagrant

and check that you can see files there. (it should not be empty)

Also, plug in a telos mote and type

motelist

which should give something like

Reference  Device           Description
---------- ---------------- ---------------------------------------------
MFVKDTBJ   /dev/ttyUSB0     FTDI MTM-CM5000MSP
More detail on why …

The instruction that is hanging is

modprobe vboxsf

It seems like the vagrant plugin uninstalls the virtualbox-guest-* packages but the kernel modules associated with this are still in memory. Specifically  “vboxvideo” cannot seem to be unloaded – I’ve tried lots of ways. The simplest fix is to just reboot.

This now seems to work with the latest VirtualBox and Vagrant versions.