Compile Android Kernel for the Emulator (Goldfish)
Compiling Android for the SDK emulator (known as Goldfish) is a natural first step into the world of Android kernel development. The first step is to get your build environment setup. Once that’s done we can begin by obtaining the source via git.
Getting the source
$ cd /some/android/dir $ git clone git://android.git.kernel.org/kernel/common.git android_kernel
Now the source will be created under android_kernel. Next we need to check out the Goldfish branch.
[tja@tja-desktop android_kernel]$ git branch * android-2.6.36 [tja@tja-desktop android_kernel]$ git branch -r origin/HEAD -> origin/android-2.6.36 origin/android-2.6.35 origin/android-2.6.36 origin/android-2.6.37 origin/android-2.6.38 origin/archive/android-2.6.25 origin/archive/android-2.6.27 origin/archive/android-2.6.29 origin/archive/android-2.6.32 origin/archive/android-gldfish-2.6.29 origin/archive/android-goldfish-2.6.27 [tja@tja-desktop android_kernel]$ git checkout --track -b android-goldfish-2.6.27 origin/archive/android-goldfish-2.6.27 [tja@tja-desktop android_kernel]$ git branch android-2.6.36 * android-goldfish-2.6.27
Configure the kernel parameter
We can use the emulator’s base configuration as a starting point.
$ emulator -avd my_avd ... $ adb pull /proc/config.gz $ gunzip config.gz $ cp config .config
Use make menuconfig to configure the kernel just like Linux.
Compiling!
Now we are finally ready to compile, er cross-compile. For ARM. We need to reference the Android cross-compiler toolchains – I did this from the NDK. When we call make we must define ARCH and CROSS_COMPILE. CROSS_COMPILE will be a prefix for the toolchain path which is later appended with gcc, ld, etc…
Here are the executables used by CROSS_COMPILE:
arm-eabi-addr2line arm-eabi-g++ arm-eabi-gprof arm-eabi-readelf arm-eabi-ar arm-eabi-gcc arm-eabi-ld arm-eabi-run arm-eabi-as arm-eabi-gcc-4.4.0 arm-eabi-nm arm-eabi-size arm-eabi-c++ arm-eabi-gcov arm-eabi-objcopy arm-eabi-strings arm-eabi-c++filt arm-eabi-gdb arm-eabi-objdump arm-eabi-strip arm-eabi-cpp arm-eabi-gdbtui arm-eabi-ranlib
So build it:
$ cd $ANDROID_SOURCE/android_kernel/ $ make ARCH=arm CROSS_COMPILE=${NDK}/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi-
Now you can go get a refreshing ale and return in hopes of success. If everything worked OK, you should see the following:
Kernel: arch/arm/boot/Image is ready Kernel: arch/arm/boot/zImage is ready
Time to test it out:
[tja@tja-desktop android_kernel]$ emulator -kernel ./arch/arm/boot/zImage -show-kernel -verbose -avd ginger_2_3_3
Notes:
- make-3.81 is needed for the kernel build – make-3.82 fails with “mixed implicit and normal rules”