[Android] Warped420:
The president has spoken

STEP 9​

​

Building a kernel.

You're in deep waters once again.

To explain the kernel, I would say he is like the president of your phone.

He tells everyone what to do, and when to do it, and how to do it.

Kernel

The kernel is the core of an operating system. It functions on a low level (kernelspace) interacting between the hardware of the machine and the programs which use the hardware to run. To make efficient use of the CPU, the kernel uses a scheduler to arbitrate which tasks take priority at any given moment, creating the illusion of many tasks being executed simultaneously.

(From an article about Arch Linux)

"Do you like LAG?"

Well if you answered "no"

Then you better build a good kernel.

I entered "building a kernel for android" and i got a long list of tutorials on this.

So, if my section on kernels isn't enough, Google has more.

"git clone" is the code prefix if you luck out and find a kernel source on github.

first you would

$ cd android

$ cd system

$ cd kernel

$ mkdir <name of company>

$ cd <name of company>

$ git clone bla bla bla bla bla lol

But for the purpose of this step, you did not find a kernel source...

So, if you did step 8, or you found a device repo on Github, then you know alot more about your device now, specifically the hardware that pushes your device..

This table lists the name and locations of SOME kernel sources and binaries

Device / Binary location / Source location / Build configuration

manta / device/samsung/manta/kernel / kernel/exynos / manta_defconfig

mako / device/lge/mako-kernel/kernel / kernel/msm / mako_defconfig

grouper / device/asus/grouper/kernel / kernel/tegra / tegra3_android_defconfig

tilapia / device/asus/grouper/kernel / kernel/tegra / tegra3_android_defconfig

maguro / device/samsung/tuna/kernel / kernel/omap / tuna_defconfig

toro / device/samsung/tuna/kernel / kernel/omap / tuna_defconfig

panda / device/ti/panda/kernel / kernel/omap / panda_defconfig

stingray /device/moto/wingray/kernel / kernel/tegra / stingray_defconfig

wingray / device/moto/wingray/kernel / kernel/tegra / stingray_defconfig

crespo /device/samsung/crespo/kernel / kernel/samsung / herring_defconfig

crespo4g / device/samsung/crespo/kernel / kernel/samsung / herring_defconfig

This is for reference, these devices are supported..

You will want to look at the git log for the kernel binary in the device project that you are interested in.

Device projects are of the form device/<vendor>/<name>. This example is for the Panda...

$ git clone https://android.googlesource.com/device/ti/panda

$ cd panda

$ git log --max-count=1 kernel

The commit message for the kernel binary contains a partial git log of the kernel sources that were used to build the binary in question. The first entry in the log is the most recent, i.e. the one used to build that kernel. You will need it at a later step.

Downloading sources

Depending on which kernel you want,

Device projects are of the form device/<vendor>/<name>.

The goldfish project contains the kernel sources for the emulated platforms.

The msm project has the sources for ADP1, ADP2, Nexus One, Nexus 4, and can be used as a starting point for work on Qualcomm MSM chipsets.

The omap project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets.

The samsung project is used for Nexus S, and can be used as a starting point for work on Samsung Hummingbird chipsets.

The tegra project is for Xoom and Nexus 7, and can be used as a starting point for work on NVIDIA Tegra chipsets.

The exynos project has the kernel sources for Nexus 10, and can be used as a starting point for work on Samsung Exynos chipsets.

To git these

$ git clone https://android.googlesource.com/kernel/common.git

$ git clone https://android.googlesource.com/kernel/exynos.git

$ git clone https://android.googlesource.com/kernel/goldfish.git

$ git clone https://android.googlesource.com/kernel/msm.git

$ git clone https://android.googlesource.com/kernel/omap.git

$ git clone https://android.googlesource.com/kernel/samsung.git

$ git clone https://android.googlesource.com/kernel/tegra.git

Here are some other links for sources

http://www.htcdev.com/

http://opensource.samsung.com/

http://developer.sonymobile.com/wpor...ads/opensource

http://www.lg.com/global/support/ope...opensource.jsp

You may have to do some leg work and find your source.

As an example, we would build the kernel using the following commands:

Part A. Pre-build Steps

A. Open terminal and change to the root of your kernel directory

B. Type "export ARCH=arm"

C. Type "export CROSS_COMPILE=~/android/system/kernel/toolchains/arm-eabi-linaro-4.6.2/bin/arm-eabi-" (your toolchain may be different than this, it is an example)

Part B. The First Build

A. Type "make <your_config_name>_defconfig"

B. Type "make menuconfig" and make the required changes to use any modules you added or similar changes.

C. Type "make -j<maximum number of jobs>"

Part C. Re-Builds

A. Type "make clean"

B. Type "make oldconfig"

C. Type "make -j<maximum number of jobs>"

Part D. Building Modules

You have two options:

A. Type "make modules"

B. Type "make path/to/your/module.ko"

The above steps explained:

Part A.(These steps are required every time you close your terminal and re-open it to build again.)

A. Ok shouldn’t need to explain this.

B. This command sets your target architecture.

C. Defines the path to the toolchain we are going to use to compile our kernel. You can change this to point towards whatever toolchain you have downloaded or feel like using, the way it is currently configured it will use the Linaro toolchain that we downloaded above.

Part B.(These only need to be run the first time you build a kernel.)

A. Load's your configuration file from earlier.

B. Open up a menu to configure your kernel. It will use the config file you loaded in the previous step as a base.

C. Viola start the build. I typically allow 1 job per core, so on my quad core machine I put "make -j4". Just raising that number will not make your build faster, your processor needs to be able to support the number of jobs you are assigning it.

Part C. (Use the command's when you are building any-time outside of the first)

A. This command gets rid of any old/outdated binaries or modules you compiled before, and let's start fresh. I like to run it every I build unless my changes are really small and localized.

B. A very awesome command, it parses through what has changed and only prompts you about new options.

C. See the explanation for the above "Part C.".

Part D.(Use these for just building kernel modules.)

A. This will re-build all modules.

B. Will rebuild just the module you need. Very useful when you need to rebuild a WiFi module.

Outcome A. Build Succeds

W00t!! You have a kernel built by your self from source. There are a couple things you need in-order to use this kernel on your device any ".ko" modules and the zImage binary. If you pay attention to the output of your compiler then you will see the location of those objects. However the following commands will make your life a bit easier(Thanks Recognized Developer Hacre):

A. Open a terminal

B. Change to your root kernel directory

C. Type "mkdir ../<your_kernel>_output"

D. Type "cp arch/arm/boot/zImage ../<your_kernel>_output/zImage"

E. Type "find . -name "*.ko" -exec cp {} ../<your_kernel>_output \;"

The above steps explained:

A-C. Self-Explanatory

D. Move our kernel binary into our output folder

E. This handy bit of magic finds all ".ko" modules and also copies them into your output file.

You will also need to assemble a kernel image containing a initramfs for your device, along with the kernel binary and such. That however is beyond the scope of this tutorial. To get started though try searching the following phrases.

Code:

building android kernel image

xda build kernel image

xda unpack boot.img

Outcome B. Build Fails

Oh dear. It failed. Well guess what...this is going to happen..a LOT. Get used to it, and get used to googling and experimenting with different solutions. The following are some tips that will help you with debugging your issues.

Running a "Clean" build

A. Backup your config file(Type "cp .config ../backupConfig")

B. Re-run the build process using just your defconfig from earlier.

Limiting Output(Thanks Hacre.)

A. Another good tip is to run "make -j1" to get the error, as it will limit the amount of text you need to scroll through.

(from a kernel tutorial)(cred =thewadegeek)

The kernel binary is output as `arch/arm/boot/zImage`, and needs to be copied into the Android source tree in order to build the matching boot image.

Quotes from threads

"when building a whole ROM like AOSP,AOKP,PA or CM then they typically bundle the toolchain/kernel with the source, making this totally unneeded."

"You can typically find a manufacturer's configuration file in "arch/arm/configs". I believe the one for my HTC Flyer was called "flyer_hc_defconfig"

A Q&A from a thread

How can I build the latest kernel using all described stuff (aosp source, kernel config, latest kernel)?

Jean-Baptiste Queru

Mar 25

That's not possible without some work. Device-specific kernel are

typically 3 steps away from the upstream kernel: one step adds

android-specific code, one step adds chipset-specific code, one step

adds device-specific code.

THIS IS NOT COMPLETE.. IT IS A ADVANCED STEP ,LIKE STEP 8 it will take patience and time...