IMote2 Compiler

From TinyOS Wiki
Jump to: navigation, search

This article focuses on the cross compiler required to obtain exec files for the iMote2 platform. It does not deal with TinyOS tree, for that information see iMote2 article on this wiki or the regular TinyOS installation instructions. However, users should be aware of fact that regarding iMote2 the latter includes instructions that may not work out at all times or are outperformed by alternatives referred hereafter.

Introduction

iMote2 integrates an XScale processor (PXA271) whose core is ARM. Therefore, suitable compilers for iMote2 can be named after the processor family name or the overall architecture, namely ARM.

Contents are structured in two more sections: one for packaged compilers (deb or rpm) which is the fastest and cleanest way of installing and deleting the compiler and another one to do it from source code, which is just recommended if such packages are unavailable or incompatible with your system setup.

Packaged compilers

This is the simplest and fastest way to install our compiler either on Debian-based systems or on Cygwin (Windows), for other Linux distributions see section on Install from source code. Generally, you will need to download one or more files (packages) and install them on the command line or simply double clicking if you have X Window installed.

GCC 4.x

GCC v4.x is just available as Debian packages. However, Debian/Ubuntu users will likely perceive a noticeable improvement regarding exec size, execution times and compatibility with other WSN platforms such as micaZ whose compiler had installation conflicts with previous packaged versions (v3.4.3). Two flavours are available for two different compiler versions: elf and eabi. Both have been reported to work fine <ref>Compiling for an ARM architecture: iMote2-TinyOS. Experiences at Consolider COMONSENS</ref>, eabi is the most recent definition for binary files though.

Download and Install

You may download and install any package or even both on the same system as they are not mutually incompatible. Upon compiling your application you will have to decide which one to invoke. Most likely you will not change it every now and then as two files from your TinyOS tree need to be edited. For further information on elf and none-eabi regarding these packages see Compiling for an ARM architecture: iMote2-TinyOS. Unlike other packages, all you need to install is the compiler from the links below: there is no need to search binutils or newlib since they are already included within the same package.

Once you have them downloaded, installation can be done on the command line or, if you have an X Window system, assisted by an application such as GDebi. Command line users can do it moving to the directory where the packages were downloaded:

$ cd <same_directory_as_downloaded_packages> 
$ dpkg --install arm-compiler-<flavour>.deb

After the installation is completed, it is possible to invoke them from the command line, but a few minor edits in your TinyOS tree installation are required to build your TinyOS applications by means of them. It is recommended to check section 7 of Compiling for an ARM architecture: iMote2-TinyOS <ref>Compiling for an ARM architecture: iMote2-TinyOS. Technical Report.</ref> for such changes and indications to optimize your compilation.

After installing, you may see if your compiler works properly. See Verify subsection for a simple way to check it out.

GCC 3.4.3

This version is available both as Debian and RPM packages and it is the one referred at the regular TinyOS installation instructions on this wiki <ref name="inst-TOS211"> Installing TinyOS 2.1.1. TinyOS installation method. TinyOS wiki</ref>. Still, this way is faster than doing from source. Some users have reported installation incompatibilities with avr-gcc-tinyos, if you do not need to code for mica2 or micaZ you can remove it before installing.

Download and Install

You will need to download three packages, depending on your working environment they will be RPMs or deb:

Package Cygwin (Windows) Debian
xscale-elf-binutils xscale-elf-binutils-2.15tinyos-1.cygwin.i386.rpm xscale-elf-binutils-2.15-2.i386.deb
xscale-elf-gcc xscale-elf-gcc-3.4.3-1.cygwin.i386.rpm xscale-elf-gcc-3.4.3-2.i386.deb
xscale-elf-newlibc xscale-elf-newlib-1.11.0tinyos-1.cygwin.i386.rpm xscale-elf-newlib-1.13.0-1.i386.deb

these deb packages are hosted on a server at UC Merced, different from the ones referred in <ref name="inst-TOS211"/>

Once downloaded, they should be installed in the same order as listed above since there are dependencies among them.

If you wish to see other alternatives on GCC 3.4.3, there is an outstanding compilation that takes into account several ways of setting up the iMote2 compiler <ref>iMote2 environment installation. Includes a thorough compilation of installation tutorials. Paul Shin.</ref>.

Verification

It is as simple as building Blink or other application code you wish:

$ cd $TOSROOT/apps/Blink
$ make intelmote2

If you obtain an executable output, most likely your set up did the trick.

Install from source code

GCC 3.4.3

This section is suitable for you in the event that you cannot use the previous package files on your computer.

Download

To compile a working XScale elf compiler on debian from source, you will need to download the following source distributions:

Note: The links to the source files are different from the ones on the Harvard imote2 install page.

Define environment variables

These can be removed after the installation.

$ export TARGET=xscale-elf
$ export PREFIX=/usr

If you don't already have the bin subdir of the directory specified by PREFIX added to your PATH, add it now:

$ export PATH=${PREFIX}/bin:${PATH}

Build binutils

$ tar xzf xscale-elf-binutils-2.15.tgz
$ cd xscale-elf-binutils-2.15
$ mkdir build; cd build
$ ../configure --target=$TARGET --prefix=$PREFIX
$ make all install

Build bootstrap compiler

$ tar xzf xscale-elf-gcc-3.4.3.tgzInstall from source code
$ cd xscale-elf-gcc-3.4.3
$ mkdir build; cd build
$ ../configure --target=$TARGET --prefix=$PREFIX \
   --with-newlib --without-headers --with-gnu-as \
   --with-gnu-ld --disable-shared --enable-languages=c
$ make all-gcc install-gcc

Build newlib

$ tar xzf newlib-1.13.0.tar.gz
$ cd newlib-1.13.0
$ mkdir build; cd build
$ ../configure --target=$TARGET --prefix=$PREFIX
$ make all install

Rebuild gcc

$ cd xscale-elf-gcc-3.4.3
$ cd build
$ rm -rf *
$ ../configure --target=$TARGET --prefix=$PREFIX \
   --with-gnu-as --with-gnu-ld --enable-languages=c
$ make all install

Verification

You should now be able to compile Blink:

$ cd $TOSROOT/apps/Blink
$ make intelmote2

You should see an executable output.

--Ian Freeman

Note: These instructions were tested and found to be working on Ubuntu 8.04 and XubunTOS-2.0 (Ubuntu 7.04). Some times during the testing, instead of the

/usr

, we tried with

/opt

directory and it still works.

Using Newer Toolchain

Given that several members of our group had had difficulty compiling certain applications using the GNU toolchain described above, I have tested these instructions using GCC 4.2.4 and Binutils 2.17 (later versions of Binutils (2.18) may work; I did test with GCC 4.3.1 and was unable to compile for the "arm-eabi" target.) (Bor-rong Chen update: I was able to compile the toolchain using GCC 4.3.2, binutils 2.18, newlib 1.16)

A few small diffs are needed against the generally excellent instructions above, including:

  • Apparently xscale-elf support is being phased out, so you need to export TARGET=arm-eabi.
  • Once you have compiled and installed the toolchain, you need to fix a few things in various places in the T2 tree to get the compilation process to work correctly. In our T2 tree I've created a new compilation target called intelmote2-gcc42, which should be apparently how to do from the diffs below, but in general you need to make the following changes in the following places:
    • support/make/pxa27x/pxa27x.rules, to fix various pieces of the toolchain:
      • s/xscale-elf-as/arm-eabi-as/, s/xscale-elf-objdump/arm-eabi-objdump/, s/xscale-elf-objcopy/arm-eabi-objcopy/. You can probably do a global search and replace changing "xscale-elf" to "arm-eabi".
      • Add "PFLAGS += -mcpu=xscale". If you do not set this correctly the compiler will emit incorrect instructions causing some things to work and others to fail miserably.
    • tos/platforms/intelmote2/.platform, to fix the compiler target: (not sure why this is hidden here)
      • s/xscale-elf-gcc/arm-eabi-gcc/.

Testing Newer Toolchain

So far the following things seem to work:

  • apps/Blink
  • apps/RadioCountToLeds
  • Our volcano application, which is quite complex and exercises the radio and Flash as well as a number of other things.

I've run a few of the things in the test directory for fun:

  • Radio
    • apps/tests/LplBroadcastCountToLeds (needs to add TARGET_INTELMOTE2 to the list of supported targets to compile)
    • apps/tests/LplBroadcastPeriodicDelivery (needs to add TARGET_INTELMOTE2 to the list of supported targets to compile)
    • apps/tests/LplUnicastPeriodicDelivery (needs to add TARGET_INTELMOTE2 to the list of supported targets to compile)
    • apps/tests/TestAcks/
    • apps/tests/TestPacketLink/
  • Flash
    • apps/tests/storage/Block
    • apps/tests/storage/CircularLog
    • apps/tests/storage/Config

Feel free to add to either of these lists if you successfully use the GCC 4.2.4 tools.

--Gwa 14:07, 11 July 2008 (EDT)

References

<references/>