Home » Linux Kernel » Compile custom Linux kernel for Android / AOSP on Ubuntu

Compile custom Linux kernel for Android / AOSP on Ubuntu

If you want to compile compile custom kernel for your android platform, android provides the open source kernel code in repo. We have to download it and compile using android provided scripts. Follow below procedure for the compilation.

Dependency : you must have “gcc” and “repo” installed on your Ubuntu

$ sudo apt-get install repo gcc

Now, we will need to download the AOSP kernel source code from googlesources using repo command as below, currenly we are compiling most recent branch as “common-android-4.19” , you can find most recent versions at HERE

$ repo init -u https://android.googlesource.com/kernel/manifest -b  common-android-4.19
$ repo sync

Once you have downloaded the source code, change to that directory and check the directory structure. The actual kernel source code is in “common/” directory and this directory has multiple build.config.** files which defines the necessary parameters such as kernel default config and toolchain used etc. We have to select right build.config file for our platform.

In this post, we will try to compile for 64 bit emulator, hence our interested build.config is located at common/build.config.goldfish.arm64

This source also has a build script at build/build.sh which we need to modify for guiding the compilation. The most important parameters we need to set in build.sh are as below,

$ vim build/build.sh
BUILD_CONFIG=common/build.config.goldfish.arm64
KERNEL_DIR=common

Now, we can start the compilation as,

$ bash build/build.sh

You can go through above mentioned link, or build.sh to understand if you want to finetune the compilation after its compiled once, such as skip mrproper for second compilation etc.

Once the compilation is completed, you can get the binaries at,

kernel$ tree out/android-4.4/dist
out/android-4.4/dist
├── Image
├── kernel-headers.tar.gz
├── kernel-uapi-headers.tar.gz
├── System.map
└── vmlinux

0 directories, 5 files

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment