Build Linux Kernel for Android Device

hahnavi |
about image

Download the Kernel Source Code

For example, kernel for Xiaomi Mi8937

git clone https://github.com/LineageOS/android_kernel_xiaomi_msm8937.git --depth=1

Install Cross Compiler

Arch Linux

sudo pacman -S aarch64-linux-gnu-gcc

Ubuntu

sudo apt install gcc-aarch64-linux-gnu

Compile the Kernel

Export the environment variable

export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64

Create the output folder

mkdir out

Locate the kernel defconfig for the device in arch/arm64/configs, run

make O=out <defconfig>

Example for my device

make O=out vendor/msm8937-perf_defconfig

Or we can copy the defconfig file from outside kernel source code and put in the out directory

cp <defconfig-file-path> out/.config
make O=out oldconfig

To modify the kernel configuration

make O=out menuconfig

Start compile process

make O=out -j`nproc`

The output file will be stored in the boot directory out/arch/arm64/boot/

comments powered by Disqus