Android's Kernel: The Linux Kernel

This topic was published by and viewed 595 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts
  • DevynCJohnson
    DevynCJohnson
    Keymaster
    • Topics - 444
    • @devyncjohnson

    Now that we have studied the Linux kernel very well and learned how to make our own, we will learn something a little different. Many of you may be unaware of this, but Android is Linux. True, they are not quite the same, but Android is Linux. For example, Ubuntu is "GNU/Linux" while Android is "Dalvik/Linux" (in older Android versions). If an operating system uses the Linux kernel, then it is a Linux system. The userland (GNU and Dalvik) does not determine whether an OS is Linux or not. Android uses a modified Linux kernel. As we know, Android runs on phones. As you may remember from configuring the kernel, there were no drivers for phone devices (like small keypads, 3G/4G cards, SIM cards, etc.). The Linux kernel used in Android lacks drivers that would not be in phones and instead has drivers for phone devices. In other words, no Android system uses a Vanilla Kernel.

    NOTE: Some people say "Android/Linux" instead of "Dalvik/Linux". However, both are considered correct.

    Linux kernels for Android can be downloaded or viewed here - (https://android.googlesource.com/?format=HTML). Just like the Vanilla kernel, the Android kernel is open-source software (due to the GPL license on the Vanilla kernel). The generic Android kernel can be seen here - (https://android.googlesource.com/kernel/common.git/+/android-3.10) [for kernel v3.10] which looks very similar to the Vanilla kernel.

    Downloading-the-Android-Kernel
    Downloading-the-Android-Kernel

    NOTE: In this article and series, "Android Kernel" will be used interchangeably with "Linux kernel for Android" and other similar phrases.

    Android-Kernel-Source-Code
    Android-Kernel-Source-Code

    The ./android/ directory contains a configuration file for making the Android kernel. These files tell the configuration tool which features/modules/drivers to enable or disable (https://android.googlesource.com/kernel/common.git/+/android-3.10/android/configs/android-base.cfg).

    Some proprietary or special hardware may have a kernel designed specifically for them. For instance, kernels for Samsung phones can be downloaded here (https://android.googlesource.com/kernel/samsung/).

    DOWNLOAD: To download an Android kernel, look to the "tgz" hyperlink near "Commit" around the top of the screen. Here is a download link - https://android.googlesource.com/kernel/common.git/+archive/android-3.10.tar.gz

    As seen in the ./security/ folder of the kernel's source code, Android supports the same Linux Security Modules (LSMs) that a desktop/server kernel would. By looking at any part of the Android kernel, the Android and Vanilla kernel are nearly the same. For illustration, the same filesystems are seen in Android's filesystem driver directory (./fs/) as in the Vanilla kernel.

    Configuring the Kernel

    To configure the kernel, do as you would for a Vanilla kernel - open a terminal in the source code directory and type "make ". I will use "make menuconfig" for my screenshots. Here is the most important step, load an alternate configuration file such as "./android/configs/android-base.cfg". Now, you can configure the kernel. However, be careful not to undo a feature/option that is important to Android (like ashmem). Also, you may see in the configuration tool (after loading the proper config file) that Android is an embedded Linux system. Keep this in mind when configuring the kernel. When configuring the Android kernel, it is very important to note that it must be cross-compiled.

    Android-Kernel-Config-File
    Android-Kernel-Config-File

    NOTE: To know which features should not be changed, open the loaded configuration file in a text-editor (such as Gedit, Leafpad, etc.). The listed features should not be manipulated unless you have a specific purpose for doing so.

    Once you have finished configuring the system, save the configuration as "./.config". Overwrite the file if needed (make a backup if the original "./.config" is important).

    Configuring-the-Android-Kernel
    Configuring-the-Android-Kernel

    Compiling the Kernel

    Before compiling, the host system must have JDK 6, Python2.7, and various developer's libraries installed on your system. Many developers recommend compiling the kernel on a 64-bit system (doing so on a 32-bit system is possible, but more difficult). Also, remember to set these variables before executing the "make" command -

    export ARCH=arm
    export SUBARCH=arm
    export CROSS_COMPILE=arm-eabi-

    The developer libraries I mentioned can be installed like this (for RedHat-based systems, use "yum" instead of "apt-get") - sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

    Also, make sure that the proper cross-compiler is installed on your system (arm-eabi).

    Cross-compiler-for-ARM-(Synaptic)
    Cross-compiler-for-ARM-(Synaptic)

    Making a symbolic link for this library may help on some systems - sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

    NOTE: Some other libraries or links may be needed. If so, the compiler will give an error that a library or file is missing. Install or link as needed.

    If the configuration and compiling process went well, the Android kernel is ready for a device. The process of installing an Android kernel is a process that requires more knowledge in Android development and many more steps. So, I will not discuss the Android kernel that far.

    Patching the Kernel

    Patches can be applied to the Android kernel's source code the same way as the Vanilla kernel, except the patches must be Android patches. The patches on Kernel.org will not work. They may work in some instances, but you must know what you are doing and only apply them to drivers/modules that are still Vanilla (unaltered from the original).

    Android Kernels

    There are a few different kinds of Android kernels as seen on the Android kernel's Git page (https://android.googlesource.com/?format=HTML). These various kernels mainly vary in their driver availability. For example, the Exynos kernel will have drivers for Exynos Samsung devices while the OMAP kernel does not.

    Further Reading

    Attachments:
    1. Android-Kernel-Config-File
    2. Android-Kernel-Source-Code
    3. Configuring-the-Android-Kernel
    4. Cross-compiler-for-ARM-(Synaptic)
    5. Downloading-the-Android-Kernel
Viewing 1 post (of 1 total)