Cross compile code for the Motorola Milestone using Gentoo

02 Feb 2010 by man0lis

The toolchain build in this article currently only works with version 2.0 of the Milestone firmware, but I wrote another short article about getting a working toolchain for 2.0.1.

When I first used ConnectBot to get a local shell, I immediately felt some kind of incompleteness. I mean nearly everything important regarding the shell is missing. So I started working out a way to cross compile my favorite tools. Thanks Gentoo for the awesome crossdev script.

I simply called (like suggested in the Gentoo Wiki):

crossdev -t arm7-unknown-linux-gnu --b 2.19.1 --g 4.3.3 --l 2.9_p20081201-r1

And crossdev started to build a cross compiler environment. After the build was finished (it really took some time) I wrote a simple Hello Android program to test the cross compiler.

#include <stdio.h>

int main(int argc, char **argv) {
    printf("Hello Android...\n");
    return 0;

The result:

$ arm7-unknown-linux-gnu-gcc --static hello.c -o hello
$ adb push hello /tmp/
$ adb shell
$ /tmp/hello
Hello Android...

Yaay Succses! Now lets try to build the bash shell.

  1. Get the bash source from
  2. Untar it
  3. Use the following configure command: ./configure --host=arm7-unknown-linux-gnu --enable-static-link --without-bash-malloc
  4. Run make
  5. Use adb push bash /sdcard/ to copy the binary to your phone
  6. Type su and move bash to some place with execute rights (like /data)
  7. Run /data/bash on the phone

Result: bash-4.1#

In case you do not want to compile your own bash executable I will provide the one I created.

bash executable

Comments are welcome, but since this blog uses static pages there is no comment function. So when you have a comment or and addition, please write an email. (The authors name on top of the page is a mailto link.)

Update 1: Because the first executable was quite huge, I tried to build another cross compiler toolchain that uses the uclibc. After trying different versions of the toolchain components I ended up using the newest stable versions available. (By the time of writing: binutils-2.20, gcc-4.3.4, uclibc- First results seem good. The Hello Android program compiled with glibc has about 500kbyte (linked static), but the same program linked with uclibc has only 21kbyte (also linked static).

Command used to build the toolchain:

UCLIBC_CPU="ARM_XSCALE" crossdev -t arm7-unknown-linux-uclibc

This should enable some enhancements in uclibc for the predecessor cpu generation of the milestones cpu. I hope this works for the Milestone.

Beforehand you need to apply this patch to the configure script. Command to configure bash:

./configure --host=arm7-unknown-linux-uclibc --enable-static-link --without-bash-malloc

The result was larger than expected: 2.1 Mbyte. But still smaler.

bash_uclibc executable

Update 2:

It looks like my toolchain does not work with Firmware version 2.0.1. Thanks pille for the information.