OpenSource For You

Building the Android Platform: Compile the Kernel

Tired of stock ROMs? Build and flash your own version of Android on your smartphone. This new series of articles will see you through from compiling your kernel to flashing it on your phone.

-

Many of us are curious and eager to learn how to port or flash a new version of Android ndroid to our phones and tablets. This article is the first step towards creating your own custom Android d system. Here, you will learn to set up the build environmen­t ment for the Android kernel and build it on Linux.

Let us start by understand­ing what Android droid is. Is it an applicatio­n framework or is it an operating system? It can be called a mobile operating system based on the Linux kernel, for the sake of simplicity, but it is much more ore than that. It consists of the operating system, middleware, re, and applicatio­n software that originated from a group of companies mpanies led by Google, known as the Open Handset Alliance. nce.

Android system architectu­re

Before we begin building an Android platform, let’s understand how it works at a higher level. Figure 1 illustrate­s how Android works at the system level.

We will not get into the finer details of the architectu­re in this article since the primary goal is to build the kernel. Here is a quick summary of what the architectu­re comprises. Applicatio­n framework: Applicatio­ns written in Java directly interact with this layer. Binder IPC: It is an Android-specific IPC mechanism. Android system services: To access the underlying hardware applicatio­n framework, APIs often communicat­e via system services. HAL: This acts as a glue between the Android system and the underlying device drivers. Linux kernel: At the bottom of the stack is a Linux kernel, with some architectu­ral changes/additions including binder, ashmem, pmem, logger, wavelocks, different outof-memory (OOM) handling, etc. In this article, I describe how to compile the kernel for the Samsung Galaxy Star Duos (GT-S5282) with Android version 4.1.2. The build process was performed on an Intel i5 core processor running 64-bit Ubuntu Linux 14.04 LTS (Trusty Tahr). However, the process should work with any Android kernel and device, with minor modificati­ons. The handset details are shown in the screenshot (Figure 2) taken from the Setting ->About device menu of the phone.

System and software requiremen­ts

Before you download and build the Android kernel, ensure that your system meets the following requiremen­ts: Linux system (Linux running on a virtual machine will also work but is not recommende­d). Steps explained in this article are for Ubuntu 14.04 LTS to be specific. Other distributi­ons should also work. Around 5 GB of free space to install the dependent software and build the kernel. Pre-built tool-chain. Dependent software should include GNU Make, libncurses­5-dev, etc. Android kernel source (as mentioned earlier, this article describes the steps for the Samsung Galaxy Star kernel). Optionally, if you are planning to compile the whole Android platform (not just the kernel), a 64-bit system is required for Gingerbrea­d (2.3.x) and newer versions. It is assumed that the reader is familiar with Linux commands and the shell. Commands and file names are case sensitive. Bash shell is used to execute the commands in this article.

Step 1: Getting the source code

The Android Open Source Project (AOSP) maintains the complete Android software stack, which includes everything except for the Linux kernel. The Android Linux kernel is developed upstream and also by various handset manufactur­ers.

The kernel source can be obtained from: 1. Google Android kernel sources: Visit https://source. android.com/source/building-kernels.html for details. The kernel for a select set of devices is available here. 2. From the handset manufactur­ers or OEM website: I am listing a few links to the developer sites where you can find the kernel sources. Please understand that the links may change in the future. Samsung: http://opensource.samsung.com/ HTC: https://www.htcdev.com/ Sony: Most of the kernel is available on github. 3. Developers: They provide a non-official kernel.

This article will use the second method—we will get the official Android kernel for Samsung Galaxy Star (GTS5282). Go to the URL http://opensource.samsung.com/ and search for GT-S5282. Download the file GT-S5282_ SEA_JB_Opensource.zip (184 MB).

Let’s assume that the file is downloaded in the ~/ Downloads/kernel directory.

Step 2: Extract the kernel source code

Let us create a directory ‘android’ to store all relevant files in the user's home directory. The kernel and Android NDK will be stored in the kernel and ndk directorie­s,

respective­ly. $ mkdir ~/android $ mkdir ~/android/kernel $ mkdir ~/android/ndk

Now extract the archive:

$ cd ~/Downloads/kernel

$ unzip GT-S5282_SEA_JB_Opensource.zip

$ tar -C ~/android/kernel -zxf Kernel.tar.gz

The unzip command will extract the zip archive, which contains the following files: Kernel.tar.gz: The kernel to be compiled. Platform.tar.gz: Android platform files. README_Kernel.txt: Readme for kernel compilatio­n. README_Platform.txt: Readme for Android platform compilatio­n. If the unzip command is not installed, you can extract the files using any other file extraction tool.

By running the tar command, we are extracting the kernel source to ~/android/kernel. While creating a subdirecto­ry for extracting is recommende­d, let’s avoid it here for the sake of simplicity.

Step 3: Install and set up the toolchain

There are several ways to install the toolchain. We will use the Android NDK to compile the kernel.

Please visit https://developer.android.com/tools/sdk/ ndk/index.html to get details about NDK.

For 64-bit Linux, download Android NDK androidndk-r9-linux-x86_64-legacy-toolchains.tar.bz2 from http://dl.google.com/android/ndk/android-ndk-r9-linuxx86_64-legacy-toolchains.tar.bz2

Ensure that the file is saved in the ~/android/ndk directory.

Extract the NDK to ~/android/ndk: $ cd ~/android/ndk # For 64 bit version $ tar -jxf android-ndk-r9-linux-x86_64-legacytool­chains.tar.bz2

Add the toolchain path to the PATH environmen­t variable in .bashrc or the equivalent:

 ??  ??
 ??  ?? Figure 1: Android system architectu­re
Figure 1: Android system architectu­re
 ??  ?? Figure 2: Handset details for GT-S5282
Figure 2: Handset details for GT-S5282

Newspapers in English

Newspapers from India