The Android project provides a fancy, QEMU-based emulator for testing components in software without needing to flash anything to a physical device. The Android “goldfish” kernel is specifically designed to run on the Android emulator, which simulates an ARM-based mobile device.
http://source.android.com/ gives an overview of how to initialize your build environment and compile an Android kernel, but it leaves out some crucial, time-saving details.
Quickstart
Compile the Goldfish Kernel
Initialize your build enviromnent, or verify that it’s set up correctly. Make sure you have a complete and functional toolchain to build for arm devices. Once your build environment is set, perform the following steps (adjusting for your desired kernel and arm-eabi-gcc versions accordingly):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ git clone https://android.googlesource.com/kernel/goldfish $ cd goldfish/ $ git branch -a $ git checkout -t origin/android-goldfish-2.6.29 -b goldfish $ export PATH=<ANDROID BASEDIR>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH $ export ARCH=arm $ export SUBARCH=arm $ export CROSS_COMPILE=arm-eabi- $ make goldfish_armv7_defconfig $ make |
To test your new goldfish kernel in the emulator, manually specify the name of a pre-existing AVD or set the ANDROID_PRODUCT_OUT environment variable:
|
1 2 3 |
$ path/to/emulator -kernel path/to/goldfish/arch/arm/boot/zImage -avd <your avd> -verbose |
To target an AVD you’ve already set up, add -avd <name> as an argument to the emulator. I also like to include the -verbose flag to see what kind of messages the emulator is emitting.
My Android SDK installation is in /opt and I’m using a 64-bit system, so the location of my emulator is /opt/android-sdk/tools/emulator64-arm. The SDK also provides emulators for x86 and MIPS architectures.
Detailed instructions
Git clone the goldfish kernel repository
Cloning android kernel repositories can be a little confusing because everything seems to download correctly, but the result of the
git clone
operation is an empty directory with a very large .git folder. As AOSP architect Jean-Baptiste Queru explained,
That’s done on purpose. There’s no notion of master branch in the kernel (and there’s not even a notion of current development branch), but the various tools we use don’t work if there’s no master branch, so we add an empty master branch to make the tools happy.
So an empty directory after a git clone operation is normal. To set everything right, enter the empty directory you just cloned and check out a branch. To see what branches are available, type
git branch -a
. When you’ve decided which branch you want, check it out with
|
1 2 3 |
$ git checkout -t origin/android-goldfish-2.6.29 -b goldfish |
where origin/android-goldfish-2.6.29 is the name of the remote branch and -b specifies the branch’s local name.
Export environment variables
Parts of the make process take environment variables as arguments. The following setup will compile the kernel for ARM:
|
1 2 3 4 5 6 |
$ export PATH=<ANDROID BASEDIR>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH $ export ARCH=arm $ export SUBARCH=arm $ export CROSS_COMPILE=arm-eabi- |
Make the kernel for your architecture
export ARCH=arm
specified the target architecture, and configurations for each architecture are found in goldfish/arch/<ARCH>/configs. In the past, goldfish_defconfig was a good option, but it doesn’t boot in the emulator at this point.
|
1 2 3 4 |
$ make goldfish_armv7_defconfig $ make |
To speed the compilation process, add the -jX flag after the make command, where X is the number of cores you would like to use for parallel compilation. At the end of the build (following some cool debugging information), the last line of output will be the path to the compressed kernel, zImage.
Test your new goldfish kernel in the emulator
To run the emulator with the Goldfish kernel you just compiled, issue the following command:
|
1 2 3 |
$ path/to/emulator -kernel path/to/goldfish/arch/arm/boot/zImage |
This assumes that you’ve set the ANDROID_PRODUCT_OUT environment variable, or that your emulator knows which AVD to use. If the emulator prints the “emulator: ERROR: You did not specify a virtual device name, and the system directory could not be found” message, try again after you export ANDROID_PRODUCT_OUT (instructions here).
Before
After
arm-eabi-gcc: Command not found
If you type “make” and get the error “arm-eabi-gcc: Command not found,” you either don’t have the arm toolchain installed on your system, or the toolchain’s components (arm-eabi-gcc etc) aren’t in your PATH.
The Android kernel guide recommends:
|
1 2 3 4 |
$ git clone https://android.googlesource.com/platform/prebuilt $ export PATH=$(pwd)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH |
Check to make sure that the the prebuilt arm-eabi-gcc toolchain isn’t already on your system before reinstalling it in another directory. If it’s already on your system, adding it to your path will fix the “arm-eabi-gcc: Command not found” error.



You should mark “Kernel version” but not “Build number”.
haha yeah, I realized that after I took the screenshots.
Thank you Mark for the great post. It saved me lot of frustration.