artur-rodrigues.com

Easy TinyOS development on a Virtual Machine

by

Install VirtualBox, the appropriate VirtualBox Extension Pack and Vagrant.

You will also need to install the vagrant plugin vagrant-vbguest. It will automatically install the new guest additions into the VM.

$ vagrant plugin install vagrant-vbguest

Create a Vagrantfile file with the contents below on your project folder or another convenient place. We are using Ubuntu Server 12.04 32 bits.

$script = <<SCRIPT
TOSPROD="/etc/apt/sources.list.d/tinyprod-debian.list"
TOSADDR="deb http://tinyos.stanford.edu/tinyos/dists/ubuntu natty main"
echo $TOSADDR | tee -a $TOSPROD

apt-get update -q
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" \
                                       -o Dpkg::Options::="--force-confold" \
                                       -qy dist-upgrade
apt-get install tinyos-2.1.2 tinyos-tools msp430-46 \
                g++ python-dev nesc vim -qy --force-yes

read -d '' PROFILE_SNIPPET <<"EOF"
export TOSROOT=/opt/tinyos-2.1.2
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java/tinyos.jar
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/opt/msp430/bin:$PATH
EOF
echo "$PROFILE_SNIPPET" | tee -a /home/vagrant/.profile

chown vagrant:vagrant  -R /opt/tinyos-2.1.2/
gpasswd -a vagrant dialout
SCRIPT

Vagrant.configure(2) do |config|
  config.vm.box = 'hashicorp/precise32'
  config.ssh.forward_agent = true

  config.vm.provider 'virtualbox' do |vb|
    vb.gui = true
  end

  config.vm.provision 'shell', inline: $script
end

We are now ready to spin up the VM. If this is your first time using the hashicorp/precise32 box it’ll take a little while to download it.

$ vagrant up

Login into the provisioned VM and test a few builds

$ cd /opt/tinyos-2.1.2/apps/RadioCountToLeds/
$ make iris
...
    writing TOS image
$ make iris sim
...
*** Successfully built iris TOSSIM library.

When the VM is launched a standard VirtualBox GUI is launched, use it to attach the USB devices from the host to the guest machine. Hack on!

References

http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2014-April/058267.html
http://www.stanford.edu/class/cs240e/assign/hw-tinyos.pdf
http://www.eetutorials.com/article/28/1/TinyOS-installation-guide-on-Ubuntu.html