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 -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/ which we need to modify for guiding the compilation. The most important parameters we need to set in are as below,

 $ vim build/ 

Now, we can start the compilation as,

 $ build/ 

You can go through above mentioned link, or 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
├── Image
├── kernel-headers.tar.gz
├── kernel-uapi-headers.tar.gz
└── vmlinux

0 directories, 5 files
Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question