Thursday, February 17, 2011

Compile Android Kernel for Goldfish

Goldfish is Google's ARM-based Android emulator.

First, we check out the source:

$ cd ~/Research/android/ginger/
$ git clone git://android.git.kernel.org/kernel/common.git android_kernel

This will clone the source into a directory android_kernel.

$ git checkout --track -b android-goldfish-2.6.27 origin/archive/android-goldfish-2.6.27


[tja@tja-desktop ginger]$ adb shell
# cat /proc/version
Linux version 2.6.29-00261-g0097074-dirty (digit@digit.mtv.corp.google.com) (gcc version 4.4.0 (GCC) ) #20 Wed Mar 31 09:54:02 PDT 2010

[tja@tja-desktop android_kernel]$ ARCH=arm
[tja@tja-desktop android_kernel]$ COSS_COMPILE=/home/tja/Downloads/android-ndk-r5b/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi-
[tja@tja-desktop android_kernel]$ make

Monday, February 14, 2011

Meeting the natives

Of course I want to tinker with Android to the fullest, so we install the Native Development Kit (NDK).

After downloading the appropriate NDK from Google, simply uncompress it into a suitable directory.
$ bunzip2 ~/Downloads/android-ndk-r5b-linux-x86.tar.bz2
$ tar xvf ~/Downloads/android-ndk-r5b-linux-x86.tar ./
Now the NDK is located is some directory /android-ndk-r5b/.

...and that's it! Now time to have some fun.


NDK Examples

First review the examples included with the NDK. The basic flow (as described by the NDK page):


  1. Place your native sources under <project>/jni/...
  2. Create <project>/jni/Android.mk to describe your native sources to the NDK build system
  3. Optional: Create <project>/jni/Application.mk.
  4. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level NDK directory:
    cd <project>
    <ndk>/ndk-build
    
    The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's project directory.
  5. Finally, compile your application using the SDK tools in the usual way. The SDK build tools will package the shared libraries in the application's deployable .apk file.
For complete information on all of the steps listed above, please see the documentation included with the NDK package.

Getting to the source...

Getting repo installed
$ mkdir ~/bin
$ export PATH=${PATH}:~/bin
$ curl http://android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
Now initialize the repo

The new stuff, gingerbread...create it in any directory $ANDROID_SOURCE. This clones the entire platform, not just a kernel.
$ mkdir $ANDROID_SOURCE
$ cd $ANDROID_SOURCE
$repo init -u git://android.git.kernel.org/platform/manifest.git -b gingerbread
When prompted, configure for the user.
repo initialized in /home/tja/Research/android/android_latest
Pull down default files specified in the manifest with sync:
$ repo sync
At this point feel free to get a sandwich and a Dogfish Head. This is going to take a while...

Verify GIT tags
$ gpg --import
THEN PASTE THIS IN, TERMINATE WITH CTRL-D (EOF)
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV 
lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7
8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD 
u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z 
wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq 
/HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5
jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4
MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9
b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv 
aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k 
cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX 
gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI 
2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl 
QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up 
hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk 
C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX 
LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+
OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M 
pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s 
KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb 
N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA 
vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo 
G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ 
hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l 
EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
=Wi5D 
-----END PGP PUBLIC KEY BLOCK-----
Building The Source

From Android Open-source:
$ cd ~/directory
$ source build/envsetup.sh
$ lunch
$ make
If your build fails because of a missing run-java-tool, try setting the ANDROID_JAVA_HOME environment variable before making.
$ export ANDROID_JAVA_HOME=$JAVA_HOME