Friday, January 30, 2015

Build Your Own Customized Android Kernel


Build Your Own Customized Android Kernel




Get Android and Kernel Source

Follow the instructions on AOSP Downloading the Source Tree to get the source of the Android Platform you're going to work on. It takes about 1 or 2 hours which depends on your network to download the source tree!

Build and Run Android with Prebuilt Kernel

Make sure you setup the build environment following this link. You need to download and install Oracle JDK manually if you use other linux distributions other than ubuntu or you just want to try. You can refer to this tutorital to install and setup Oracle JDK. After that, you can build and run Android platform following the instructions. If you successfully build the kernel, you'll see the output like this:
... ... Installed file list: out/target/product/generic/installed-files.txt Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img Install system fs image: out/target/product/generic/system.img
Note that the emulator tool in which you should run the platform you built is on the path out/host/linux-x86/bin/, not the one you installed in your Android SDK.
For the users of Ubuntu 12.04 or higher version, it's better to use gcc-4.4 and g++-4.4 (gcc-4.4-multilib and g++-4.4-multilib for 64-bit machine) and that will save you lots of problems and time!! Just use make CC=gcc-4.4 CXX=g++-4.4

Download and Build Kernel

The amazing thing about Android is that you can use your own customized linux kernel. Also, there are instructions on AOSP about how to download and build the kernel you'd like to hack. You can also browse all the projects on the site https://android.googlesource.com/, find the kernel project and add it to repo manifest file .repo/manifest.xml as follows: Then use command repo sync to download the kernel. To build kernel for goldfish android emulator, you need to download the kernel for goldfish and issue the following commands:
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ make goldfish_armv7_defconfig
# # configuration written to .config #
$ make
Instead of export ARCH and CROSS_COMPILE everytime you build the kernel, you can add them to Makefile file of the kernel. The image is output as arch/arm/boot/zImage. You can run Android with this customized kernel image by
$ emulator -kernel [path to kernel image]

No comments:

Post a Comment