Build LineageOS 20 kernel with wireguard module on linux

Install required packages

Bash
1
sudo apt install bc bison build-essential ccache curl flex git git-lfs gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev python3 python-is-python3

Clone required repositories

Bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# android kernelf for oneplus 7 pro (change according to your device)
git clone https://github.com/LineageOS/android_kernel_oneplus_sm8150

# gcc
git clone -b lineage-19.1 https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9.git

# clang
git clone https://github.com/LineageOS/android_prebuilts_clang_kernel_linux-x86_clang-r416183b.git

# wireguard kernel module
git clone https://github.com/WireGuard/wireguard-linux-compat.git

# built-tools
git clone -b android-13.0.0_r0.117 https://android.googlesource.com/kernel/prebuilts/build-tools

git clone https://github.com/LineageOS android_prebuilts_tools-lineage.git

Now run this script to build kernel. Place it in the directory where you have all the repositories

Bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
ROOTDIR=$PWD

rm -rf build
mkdir build

cd android_kernel_oneplus_sm8150

make clean && make mrproper

BINARIES=$PATH:$ROOTDIR/build-tools/linux-x86/bin:$ROOTDIR/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9/aarch64-linux-android/bin:$ROOTDIR/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9/bin:$ROOTDIR/android_prebuilts_clang_kernel_linux-x86_clang-r416183b/bin:$ROOTDIR/android_prebuilts_tools-lineage/linux-x86/bin

make O=../build ARCH=arm64 PATH=$BINARIES CC=clang CROSS_COMPILE=aarch64-linux-android- CLANG_TRIPLE=aarch64-linux-gnu- BRAND_SHOW_FLAG=oneplus TARGET_PRODUCT=msmnile vendor/sm8150-perf_defconfig

make -j4 O=$ROOTDIR/build ARCH=arm64 PATH=$BINARIES CC=clang CROSS_COMPILE=aarch64-linux-android- CLANG_TRIPLE=aarch64-linux-gnu- DEFCONFIG=sm8150-perf_defconfig DTC_EXT=$ROOTDIR/android_prebuilts_tools-lineage/linux-x86/dtc/dtc BRAND_SHOW_FLAG=oneplus TARGET_PRODUCT=msmnile

Now, let's patch the kernel with wireguard.

Copy wireguard-linux-compat/src to android_kernel_oneplus_sm8150/net/wireguard and then add following lines in kernel sources

  1. obj-$(CONFIG_WIREGUARD) += wireguard in net/Makefile
  2. source "net/wireguard/Kconfig" in net/Kconfig

Rerun the build script and image file should be present in $ROOTDIR/build/arch/arm64/boot/