Friday, December 07, 2012

Build Android Kernel Source Code

In my previous post, I talked about downloading Android kernel source codes and listed links of download sites from major players in the markets of Android devices.

So what are you going to do with the kernel codes after you download it?

Some guys would like to take a look at the Linux codes to see the changes,
others is going to twist it, build it, and flash the devices with the images from the build.

OEM usually provides the Android kernel to end users in zip format,
it may be only one zip file, or several zip files. To open the zip file, the zip tool would be needed. There are several free zip tools user can download from the internet.

After unzipping the downloaded zip file,  you can start to check the source codes. If you could like to build it the kernel, other tools and environment would be needed. It is recommended Linux machine would be used to run the build, you can either get an individual Linux PC, install a dual boot of popular Linux  OS, or install a virtual machine of Linux on your PC. Some of the Linux Os' are free for personal use.

For myself, I am using a Windows laptop, have a Oracle Virtual Box installed on it. I use Ubuntu Linux as a virtual machine on Virtual Box. You may download Oracle Virtual Box from this web page  https://www.virtualbox.org, and the Ubuntu Linux from http://www.ubuntu.com/download .

When you set up and configure the Ubuntu virtual machine in Oracle VirtualBox, please pay attention to the RAM, Storage size and number of processor of the host machine ( for me it is my Windows laptop), please choose proper amount of storage, RAM and number of processors to use by the virtual machine. If you assign too much ram and all the processor of the host machine for the virtual machine, when you run the virtual machine and do heavy jobs, the host machine may not be responsive.

After setting up the Linux machine, please follow the steps at http://source.android.com/source/index.html to set up the environment. You will need the tool chain from AOSP to build the Android kernel code. The tool chain is in the code base of AOSP source codes, or you can get it from somewhere else you could find, please put the tool chain in your path.

Please unzip and put the Android kernel source code in your project directory, for example,
/home/dave/Project/kernels/. Before start building the kernel, you may want to take a look at the build instructions that comes together with the Android kernel source codes, such as a readme.txt file in the directory, or any instructions the OEM lists on their website.

I happened to look at the Android kernels recently published at http://htcdev.com/devcenter/downloads ,
In the download file, there is a readme.txt, which contains the commands recommended to be used to build the kernel, including the instructions to set the path of the tool chain.

After finishing building the kernel, you may try to push some modules you just built on to you device. Please note that you may need to run at root privilege to do this.


Please make sure to back up your personal data, device settings, ect.., anytime you flash your devices with customized build module or rom, and make copy of the modules on your devices you are going to replace with the new modules, and this process is only for person with strong mobile technique experiences.


For example, if I want to put bluetooth driver module onto my device (but most of the time, all driver modules would be needed to push over to device to make the device work properly),
I will run the following commands:

adb remount
adb shell push ./drivers/bluetooth/bluetooth-power.ko system/lib/modules/
adb shell chmod 644 system/lib/modules/*
adb reboot

In case your devices got stuck to start up, you may need to run recovery and reset the device to factory settings (!!!! you would lose data on your device !!!!), you may need to put back the original modules you have backed up, or in the worst case, you may run to boot loader  mode and select the recovery or reset options from the menu, or run the recovery and reset command from the adb shell.

No comments: