Sunday 2 May 2010

How to BUILD the LINUX KERNEL for the ANDROID EMULATOR (Eclair version)

DOWNLOAD THE KERNEL SOURCE CODE


First we download the kernel source code from https://android.googlesource.com

Within that page there are kernels for other platforms too. We choose to download kernel/goldfish project from there.

$ git clone https://android.googlesource.com/kernel/goldfish

A goldfish directory appears:
$ cd goldfish
This directory does not contain any source code in it.

We check which branch we have downloaded:
$ git branch
it shows * master , not the one we are searching for:

To list all remote available branches:
$ git branch -r
or
$ git remote show origin
origin/HEAD -> origin/master
  origin/android-goldfish-2.6.29
  origin/android-goldfish-3.4
  origin/linux-goldfish-3.0-wip
  origin/master


What does goldfish mean? (from android-kernel mail list)
Goldfish is the kernel hacked branch that supports the qemu based arm emulator for android, so it is the one we need.

Download GOLDFISH kernel version
Choose the version that suits you.
$ git checkout --track -b android-goldfish-2.6.29 origin/android-goldfish-2.6.29
$ git branch
* android-goldfish-2.6.29
  master


RUNNING THE EMULATOR


Within this link we will find how to get the android emulator, and launch it.
Building Android in Debian Sid

Showing the kernel version running in the emulator
$ adb shell
# cat /proc/version
Linux version 2.6.29-00261-g0097074 (digit@digit.mtv.corp.google.com) (gcc version 4.4.0 (GCC) ) #14 Tue Feb 2 15:49:02 PST 2010


OBTAINING KERNEL CONFIGURATION


We are going to obtain the kernel configuration .config file from within our running emulator.

$ cd /path/to/goldfish # we enter in the kernel source directory.
$ adb pull /proc/config.gz . # get compressed .config file from the emulator.

$ gunzip config.gz # uncompress it.
$ cp config .config # rename it into .config

Now you can edit .config file the way it suits you the most.


BUILDING AND COMPILING THE KERNEL


CROSS_COMPILE environment variable stores the path to the arm cross compiling toolchain. I use the one which comes with android source code.

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

Executing make will build the kernel.

Last lines will show:
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready


So we have obtained Image and zImage kernel binary files.


RUN THE EMULATOR USING THE NEW COMPILED KERNEL IMAGE


We need -kernel option:
$ emulator -kernel /path/to/goldfish/arch/arm/boot/zImage -show-kernel -verbose

We can check now the kernel version:
$ adb shell
# cat /proc/version
Linux version 2.6.29-00262-gb0d93fb (user@myPC) (gcc version 4.4.0 (GCC) ) #1 Sun May 2 14:27:31 CEST 2010


If we do not specify kernel option it usually uses the prebuilt one:
$ emulator -show-kernel -verbose
emulator: argv[01] = "-kernel"
emulator: argv[02] = "/path/to/mydroid/prebuilt/android-arm/kernel/kernel-qemu"


ACTIVATING MODULE LOADING SUPPORT IN THE KERNEL


Module loading support is previously disabled in the kernel, if we want to load modules in the kernel we have to enable it:

edit .config file and set:
CONFIG_MODULES=y

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

I am asked about some options when executing make. I ask yes for module related options.

After compiling I see several modules have been built.

MODPOST 6 modules
CC      drivers/video/fb_sys_fops.mod.o
LD [M]  drivers/video/fb_sys_fops.ko
CC      drivers/video/syscopyarea.mod.o
LD [M]  drivers/video/syscopyarea.ko
CC      drivers/video/sysfillrect.mod.o
LD [M]  drivers/video/sysfillrect.ko
CC      drivers/video/sysimgblt.mod.o
LD [M]  drivers/video/sysimgblt.ko
CC      drivers/video/vfb.mod.o
LD [M]  drivers/video/vfb.ko


We can upload the modules in the emulator and install them:
$ adb push drivers/video/fb_sys_fops.ko /data
$ adb shell
# insmod /data/fb_sys_fops.ko


REFERENCE


http://www.cianer.com/androidg1/28-building-android-kernel-images


YOU MAY ALSO BE INTERESTED IN:


Building Android in Debian Sid