The Linux Kernel: Android?

Discussion in 'Linux Kernel' started by DevynCJohnson, Feb 2, 2014.

  1. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,138
    Likes Received:
    972
    Trophy Points:
    113
    Series Index - http://www.linux.org/threads/linux-kernel-reading-guide.5384/

    Aloha! Now that we have studied the Linux kernel very well and learned how to make our own, we will move on to a slightly different direction in this series. 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". 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 valid.

    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.

    android_03.png

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

    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).

    android_01.png

    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.

    To configure the kernel, do as you would for a Vanilla kernel - open a terminal in the source code directory and type "make <PREFERRED CONFIG TOOL>". 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_04.png

    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).

    android_02.png

    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 -

    Code:
    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") -

    Code:
    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).

    Making a symbolic link for this library may help on some systems -

    Code:
    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.

    android_05.png

    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.


    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).

    There are a few different kinds of Android kernels as seen on the Android kernel's Git page (https://android.googlesource.com/?format=HTML).
    The Goldfish kernel (https://android.googlesource.com/kernel/goldfish/) is for emulated platforms like running a virtual Android system within a host system on a desktop computer.
    The MSM kernel (https://android.googlesource.com/kernel/msm/) is for Qualcomm MSM chipsets.
    The OMAP kernel is for the TI OMAP chipsets (https://android.googlesource.com/kernel/omap/).
    Samsung hummingbird chipsets use the Samsung kernel (https://android.googlesource.com/kernel/samsung/).
    The NVIDIA Tegra chipsets run on the Tegra chipset kernel (https://android.googlesource.com/kernel/tegra/).
    The Exynos kernel is used by Samsung Exynos chipsets.
    These various kernels mainly variety in their driver availability. For example, the Exynos kernel will have drivers for Exynos Samsung devices while the OMAP kernel does not.

    Now, your understanding of Android should be larger than it was before. Feel free to send me more ideas on this article series or any Linux article in general. I hope to make this series continue for as long as I can. Mahalo!

    Attached Files:

    • slide.JPG
      slide.JPG
      File size:
      21.5 KB
      Views:
      120,235
    Last edited: May 11, 2014
    Haider92 and |)/-\|) like this.
  2. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,128
    Likes Received:
    376
    Trophy Points:
    83
  3. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,138
    Likes Received:
    972
    Trophy Points:
    113
    Thanks @ryanvade for the great link.

    Here is a quote from that page that I find very interesting -

    Haider92 and ryanvade like this.
  4. labrat

    labrat Active Member

    Messages:
    104
    Likes Received:
    41
    Trophy Points:
    28
    You can post "Android is Linux" as many times as you like, but it's not going to get any truer...

    Android is a Linux kernel based embedded OS, that's just about where the similarity ends.

    Comparing the GNU userland with something like Dalvik is an erroneous and misleading comparison. You need only read briefly about the two to find that there is no analogue between them.

    GNU/Linux is the operating system we use and why we are here posting on this forum. Distributions are "packagers" for this OS - including what they want to include, excluding what they don't want to include - but the vast bulk of a GNU/Linux system is the same, the same kernel, one of a handful of init systems, libc,

    Linux is just a kernel. Android is not the only embedded Linux based system. Cisco and many other routers, kindle, TomTom, etc all fit the bill... it goes on and on...

    GNU/Linux is a true Linux based computer operating system. Many of the apps, window managers, desktop environments and tools you take for granted are UNIX stuff or *BSD stuff as well as GNU stuff like glibc, gcc, coreutils, binutils, bash, etc. Many apps, X.org, most X apps and the desktops/WMs for example, are cross platform *nix software, not GNU/Linux software.

    GNU/Linux belongs to a family of UNIX-like operating systems - but few *nix systems are fully POSIX compliant. Android and other Linux based embedded systems certainly do not belong simply by virtue of being Linux based - and none are even remotely close to POSIX compliancy.
    DevynCJohnson likes this.

Share This Page