Purpose

To document the build process, when cross-compiling code to be executed on an AR.Drone. Results are considered satisfactory if we can compile a simple "hello world" program and execute the program on the drone, further we should be able to compile third-party libraries and likewise test them with simple programs on the drone.

Procedure - simple

The procedure for making and testing drone-executable code is rather simple: install a cross-compilation toolchain, make a "hello world" c program and cross compile it, transfer the program to the drone and execute it like any other program. The following steps assume you are using a linux distro.

  1. To install the codesourcery toolchain follow the instruction on the Nas-central website or just download and run this script (which originates from the Nat-center site).
    Run the following command to enter your cross compilation environment:

    $ codesourcery-arm-2009q3.sh
    


  2. Construct a simple C program, for instance:

    #include <stdio.h>
    
    int main ()
    {
      printf ("Hello World!\n");
    }
    


    Compile it for the AR.Drones ARM9 processor with the following command:

    $ arm-none-linux-gnueabi-gcc hello.c -o hello_arm
    


  3. Connect to the drone FTP server(assuming that you are already connected to the drone wifi) and put hello_arm on the drone. The server will place the file in /data/video/. Run the program like any other:

    $ ./hello_arm 
    Hello World!
    


Procedure - advanced

The advanced procedure deals with cross compiling a third party library, installing it to be used with the cross compiling toolchain and compiling a program using the library. For the example we will use libpcap as the third party library and compile a simple packet sniffer.

  1. Fetch the libpcap source here and unpack it.

  2. Start up the cross compile environment, build an ARM version of libpcap and install it with the following commands (remember the prefix part). To get the command right we used the ARM cross-compiling howto and the www.secdev.org guide for inspiration.

    $ codesourcery-arm-2009q3.sh
    $ CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/usr/local/codesourcery/arm-2009q3/arm-none-linux-gnueabi/ --host=arm-none-linux-gnu \ 
      --target=arm-none-linux-gnu --with-pcap=linux
    $ make
    $ sudo codesourcery-arm-2009q3.sh
    $ sudo make install
    


    Note that(on our system at least) make install must be called with root privileges, therefore the codesourcery script must also be started again with sudo.

  3. Now that the library has been built and installed all we need is to compile our sniffer program which uses the library.

    $ arm-none-linux-gnueabi-gcc *.c -lpcap -static -o sniffer   
    


    The output, sniffer, can be transferred to and executed on the drone.

Results

We were able to cross compile both the simple program, the library and the more advanced program utilizing the library. By doing a static compile of the advanced program, we don't have to transfer the library to the drone. We were also able to execute both programs on the drone.

References

Cross compilation guides:
Nas Central, cross compile setup
The ARM cross-compiling howto
The www.secdev.org guide

Code resources:
Cross compilation setup script
Libpcap source code