Skip to content
Caleb Connolly edited this page Aug 18, 2022 · 11 revisions

You need to choose between android-mainline or GKI below.

Linux mainline

You may want to build your own kernels manually and copy the output.
We are going to use aospm/linux as example.

git clone https://github.com/aospm/linux.git -b aosp/sdm845-mainline sdm845-mainline
cd sdm845-mainline

Next the kernel needs to be cross-compiled. It is helpful to create an alias like:

mm () {
  make CC="$CC" CROSS_COMPILE=aarch64-linux-gnu- O=$KERNEL_OUTDIR/ ARCH=arm64 -j"$(($(nproc --all)-2))" $@
}

Future usages of mm assume above command.

Also make sure to export CC and KERNEL_OUTDIR.

Next you need to generate a defconfig out of aosp and sdm845 config fragments:

mm defconfig sdm845.config aosp.config

Order matters here! defconfig creates the initial base, sdm845.config sets all required options for sdm845 and aosp.config applies all required options for android.

Each config overrides options set by the previous one.

Adjust the defconfig to your liking and build the kernel:

mm

After building your kernel, generate modules:

rm -rf $KERNEL_OUTDIR/modules
mm INSTALL_MOD_PATH=modules modules_install

Your build output is now ready to get copied.
See this gist for an example script to copy kernel build output.

Here is a handy oneliner, which does all of the above steps (assuming you also set up above gist script as copymainlinekernel):

mm defconfig aosp.config sdm845.config && mm && rm -rf $KERNEL_OUTDIR/modules && mm INSTALL_MOD_PATH=modules modules_install && copymainlinekernel generic sdm845

GKI (android-mainline)

These steps only work for android-mainline kernels with android build files included.
Run following commands to clone the kernel source and prebuilt Android toolchains and build scripts:

mkdir kernel-repo
cd kernel-repo
repo init -u https://android.googlesource.com/kernel/manifest -b common-android-mainline
git clone [email protected]:pundiramit/android-local-manifests.git .repo/local_manifests -b kernel
repo sync -j$nproc
BUILD_CONFIG=beryllium/build.config.beryllium ./build/build.sh

Delete all objects in aosp-repo/device/generic/sdm845/prebuilt-kernel/android-mainline/.
Then copy build artifacts from kernel-repo/out/beryllium-android-mainline/dist/ to aosp-repo/device/generic/sdm845/prebuilt-kernel/android-mainline/ and build AOSP images again.

cd aosp-repo
source build/envsetup.sh
lunch beryllium-userdebug
make TARGET_KERNEL_USE=mainline -j$nproc

Now reflash the images as above and boot with your custom kernel.

NOTE:

By default the above instructions will sync/download beryllium-android-mainline branch to kernel-repo/beryllium directory.
If you want to reproduce android12-5.4 or GKI build then checkout common-android12-5.4 repo manifest and beryllium-android-5.4 branch instead.

Clone this wiki locally