Get the brand new 3.4 Android kernel working for the x86 emulator

New kernel means new features. The stable emulator kernel is 2.6.29 which is pretty old. 3.4 is not the latest Linux kernel either, but it’s the latest we’ve got for Android. This is not yet working directly from Google’s source code, so you’ll need to do some extra things if you want to use it.

Download the sources for the 3.4 kernel

If you haven’t already done this, you need to download the goldfish kernel sources and checkout the 3.4 branch:

$ git clone https://android.googlesource.com/kernel/goldfish.git
$ cd goldfish
$ git checkout -b 3.4 origin/android-goldfish-3.4

Where is goldfish_defconfig?

Not in Google’s code. Code is missing from this branch and is not yet ready to use:

$ make goldfish_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
***
*** Can't find default configuration "arch/x86/configs/goldfish_defconfig"!
***
make[1]: *** [goldfish_defconfig] Error 1
make: *** [goldfish_defconfig] Error 2

We can check Google’s Gerrit for new patches not yet merged.
Searching for status:open project:kernel/goldfish branch:android-goldfish-3.4 we get a lot of new patches: https://android-review.googlesource.com/#/q/status:open+project:kernel/goldfish+branch:android-goldfish-3.4,n,z.

Patch the kernel

The latest patch in the series is https://android-review.googlesource.com/#/c/40433/
You need to use git pull on the latest patch so you get all dependencies as well:

$ git pull https://android.googlesource.com/kernel/goldfish refs/changes/33/40433/2

As the latest patch says, this will make the emulator work for x86 but not for arm.

Compile the kernel

Just as a reminder, these are the steps to compile it:

$ export CROSS_COMPILE=${ANDROID_BUILD_TOP}/external/qemu/distrib/kernel-toolchain/android-kernel-toolchain-
$ export REAL_CROSS_COMPILE=${ANDROID_BUILD_TOP}/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-
$ export ARCH=x86
$ export SUBARCH=x86
$ make goldfish_defconfig
$ make

Run the emulator with the new kernel

Start the emulator with the newly compiled kernel:

$ cd ${ANDROID_BUILD_TOP}
$ emulator -kernel ~/workspace/android/goldfish/arch/x86/boot/bzImage -wipe-data &

Connect with adb to the running emulator and check the kernel version:

$ adb shell cat /proc/version
Linux version 3.4.0+ (yaap@yaap-desk) (gcc version 4.6 20120106 (prerelease) (GCC) ) #2 PREEMPT Sun Sep 23 14:41:45 EEST 2012

Leave a comment