en Compiling the Stock Vendor Kernel - JackA1ltman/NonGKI_Kernel_Build_2nd GitHub Wiki

Compiling the Stock Vendor Kernel

Somewhat counterintuitively, the stock kernel provided by a device manufacturer is often harder to compile successfully than a typical third-party kernel. That said, if you have never flashed a custom ROM, the stock vendor kernel is your safest starting point.

Each section in this page is independent — read only the one that applies to your device.

Note: Stock vendor kernels cannot be built directly through this project without modification. At minimum, either the kernel source or the project configuration must be adapted first.


OPPO / OnePlus / Realme

The three brands under the Guangdong Oujia Holdings Co., Ltd. maintain their kernel sources under separate GitHub accounts:

Brand GitHub Account
OnePlus oneplusoss
OPPO oppo-source
Realme realme-kernel-opensource

OPPO Reno 10

Toolchain: ZyC Clang 10 + Google AOSP GCC 4.9

Step 1: Get the Source Code

This example uses ColorOS 15. Branch naming convention: oppo/<CPU_codename>_<android_version_letter>_<ColorOS_version>_<device_model>

Kernel source

git clone -b oppo/sm7325_v_15.0.0_reno10 \
  https://github.com/oppo-source/android_kernel_oppo_sm7325 \
  /home/username/kernel/msm-5.4 --depth 1

Driver source

git clone -b oppo/sm7325_v_15.0.0_reno10 \
  https://github.com/oppo-source/android_kernel_modules_and_devicetree_oppo_sm7325 \
  /home/username/kernel_modules --depth 1

Step 2: Extract the defconfig

Pull /proc/config.gz from a rooted device, decompress it, rename the resulting config file to reno10_defconfig, and place it at:

/home/username/kernel/msm-5.4/arch/arm64/configs/reno10_defconfig

Step 3: Place the Driver Files

mv /home/username/kernel_modules/vendor /home/username/
mv /home/username/kernel_modules/kernel/msm-5.4/techpack/* \
   /home/username/kernel/msm-5.4/techpack/

Step 4: Build

export PATH=/home/username/Clang/bin:$PATH

# Generate .config
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LD=ld.lld LLVM=1 LLVM_IAS=1 \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi- \
  reno10_defconfig

# Full build
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LD=ld.lld LLVM=1 LLVM_IAS=1 \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi-

A successful build ends with OBJCOPY Image.


Xiaomi / Redmi / POCO

All kernel sources for Xiaomi Group brands are hosted in a single repository:

Redmi Note 9 5G

Toolchain: Clang r377782b + Google AOSP GCC 4.9

Step 1: Get the Source Code

This example uses MIUI 11. Branch naming convention: <device_codename>-<android_version_letter>-oss

Kernel source

git clone -b cannon-r-oss \
  https://github.com/MiCode/Xiaomi_Kernel_OpenSource \
  /home/username/cannon-kernel --depth 1

Driver source

git clone -b cannon-r-oss \
  https://github.com/MiCode/MTK_kernel_modules \
  /home/username/vendor/mediatek/kernel_modules --depth 1

Step 2: Confirm the defconfig

Xiaomi kernel sources typically include a complete defconfig. For this device, it is cannon_user_defconfig — no manual extraction needed.

Step 3: Patch the Drivers

Three known issues must be resolved before building:


Issue 1: fw_sample.i not found

Obtain the file from the community-maintained repository (credit: @xiaomi-mt6853-devs):

https://github.com/xiaomi-mt6853-devs/android_kernel_xiaomi_cannon/blob/lineage-20/drivers/input/touchscreen/fts8719/include/firmware/fw_sample.i

Place it at the correct path:

mkdir -p /home/username/cannon-kernel/drivers/input/touchscreen/fts8719/include/firmware/
cp fw_sample.i /home/username/cannon-kernel/drivers/input/touchscreen/fts8719/include/firmware/

Issue 2: Bluetooth and Wi-Fi driver integration fails

Edit drivers/misc/mediatek/connectivity/Makefile.

Replace:

ABS_PATH_TO_WMT_DRV      = $(srctree)/../$(PATH_TO_WMT_DRV)
ABS_PATH_TO_WLAN_CHR_DRV = $(srctree)/../$(PATH_TO_WLAN_CHR_DRV)
ABS_PATH_TO_WLAN_DRV     = $(srctree)/../$(PATH_TO_WLAN_DRV)
...
$(shell ln -s $(ABS_PATH_TO_WMT_DRV)      $(srctree)/$(src)/wmt_drv)
$(shell ln -s $(ABS_PATH_TO_WLAN_CHR_DRV) $(srctree)/$(src)/wmt_chrdev_wifi)
$(shell ln -s $(ABS_PATH_TO_WLAN_DRV)     $(srctree)/$(src)/wlan_drv_gen4m)
...
# For BT built-in mode start @{
# ifneq (,$(filter $(CONFIG_MTK_COMBO_CHIP), "CONSYS_6885"))
#     PATH_TO_BT_DRV       = vendor/mediatek/kernel_modules/connectivity/bt/mt66xx/connac2
#     ...
# endif
# ABS_PATH_TO_BT_DRV       = $(srctree)/../$(PATH_TO_BT_DRV)
# $(shell unlink $(srctree)/$(src)/bt)
# $(shell ln -s $(ABS_PATH_TO_BT_DRV)      $(srctree)/$(src)/bt)
# obj-y += bt/
# @} For BT built-in mode end

With:

ABS_PATH_TO_WMT_DRV      = $(abspath $(srctree)/../$(PATH_TO_WMT_DRV))
ABS_PATH_TO_WLAN_CHR_DRV = $(abspath $(srctree)/../$(PATH_TO_WLAN_CHR_DRV))
ABS_PATH_TO_WLAN_DRV     = $(abspath $(srctree)/../$(PATH_TO_WLAN_DRV))
...
$(shell ln -snf $(ABS_PATH_TO_WMT_DRV)      $(srctree)/$(src)/wmt_drv)
$(shell ln -snf $(ABS_PATH_TO_WLAN_CHR_DRV) $(srctree)/$(src)/wmt_chrdev_wifi)
$(shell ln -snf $(ABS_PATH_TO_WLAN_DRV)     $(srctree)/$(src)/wlan_drv_gen4m)
...
PATH_TO_BT_DRV       = vendor/mediatek/kernel_modules/connectivity/bt/mt66xx/legacy
ABS_PATH_TO_BT_DRV   = $(abspath $(srctree)/../$(PATH_TO_BT_DRV))
$(shell unlink $(srctree)/$(src)/bt)
$(shell ln -snf $(ABS_PATH_TO_BT_DRV)       $(srctree)/$(src)/bt)
obj-y += bt/

Key changes: wrap $(srctree) references with $(abspath ...) for reliable path resolution; change ln -s to ln -snf to avoid errors when symlinks already exist; uncomment and enable the Bluetooth driver section.


Issue 3: fw_entry multiply defined

Edit the following file:

drivers/misc/mediatek/connectivity/wlan_drv_gen4m/os/linux/gl_kal.c

Perform a global find-and-replace: replace every occurrence of fw_entry with fw_entry_wlan.


Step 4: Build

export PATH=/home/username/Clang/bin:$PATH

# Generate .config
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LD=ld.lld \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi- \
  cannon_user_defconfig

# Full build
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LD=ld.lld \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi-

A successful build ends with CAT Image.gz-dtb.


Xiaomi 10 Ultra

Toolchain: Clang r377782b + Google AOSP GCC 4.9

Step 1: Get the Source Code

Kernel source

git clone -b cas-q-oss \
  https://github.com/MiCode/Xiaomi_Kernel_OpenSource \
  kernel/msm-4.19 --depth 1

Driver sources (all three can be cloned in parallel)

git clone -b cas-q-oss --depth 1 https://github.com/MiCode/vendor_qcom_opensource_audio-kernel.git
git clone -b cas-q-oss --depth 1 https://github.com/MiCode/vendor_qcom_opensource_data-kernel.git
git clone -b cas-q-oss --depth 1 https://github.com/MiCode/vendor_qcom_opensource_wlan.git

Step 2: Embed the Drivers

mv vendor_qcom_opensource_audio-kernel kernel/msm-4.19/techpack/audio
mv vendor_qcom_opensource_wlan/* kernel/msm-4.19/drivers/staging/
mv vendor_qcom_opensource_data-kernel kernel/msm-4.19/techpack/data

Extra patch required for the data driver

The data driver is missing its Kconfig/Makefile integration files. Apply the following patch:

diff --git a/techpack/Kconfig b/techpack/Kconfig
new file mode 100644
index 00000000..c3197b62
--- /dev/null
+++ b/techpack/Kconfig
@@ -0,0 +1,5 @@
+menu "Tech packages"
+
+source "techpack/data/Kconfig"
+
+endmenu
\ No newline at end of file
diff --git a/techpack/data/Kconfig b/techpack/data/Kconfig
new file mode 100644
index 000000000000..696071f9cd05
--- /dev/null
+++ b/techpack/data/Kconfig
@@ -0,0 +1 @@
+source "techpack/data/drivers/Kconfig"
diff --git a/techpack/data/Makefile b/techpack/data/Makefile
new file mode 100644
index 000000000000..1ff634d5a361
--- /dev/null
+++ b/techpack/data/Makefile
@@ -0,0 +1 @@
+obj-y += drivers/
diff --git a/techpack/data/drivers/Kconfig b/techpack/data/drivers/Kconfig
new file mode 100644
index 000000000000..a45052c6bdc0
--- /dev/null
+++ b/techpack/data/drivers/Kconfig
@@ -0,0 +1,5 @@
+menu "RmNet extensions"
+
+source "techpack/data/drivers/rmnet/Kconfig"
+
+endmenu
diff --git a/techpack/data/drivers/Makefile b/techpack/data/drivers/Makefile
new file mode 100644
index 000000000000..7a2c7ff726fd
--- /dev/null
+++ b/techpack/data/drivers/Makefile
@@ -0,0 +1 @@
+obj-y += rmnet/
diff --git a/techpack/data/drivers/rmnet/Kconfig b/techpack/data/drivers/rmnet/Kconfig
new file mode 100644
index 000000000000..82b861ac06bd
--- /dev/null
+++ b/techpack/data/drivers/rmnet/Kconfig
@@ -0,0 +1,2 @@
+source "techpack/data/drivers/rmnet/perf/Kconfig"
+source "techpack/data/drivers/rmnet/shs/Kconfig"
diff --git a/techpack/data/drivers/rmnet/Makefile b/techpack/data/drivers/rmnet/Makefile
new file mode 100644
index 000000000000..82e56d0ab7c5
--- /dev/null
+++ b/techpack/data/drivers/rmnet/Makefile
@@ -0,0 +1,2 @@
+obj-y += perf/
+obj-y += shs/
diff --git a/techpack/data/drivers/rmnet/perf/Kbuild b/techpack/data/drivers/rmnet/perf/Kbuild
index e3537c75ed67..71bae10b8c1c 100644
--- a/techpack/data/drivers/rmnet/perf/Kbuild
+++ b/techpack/data/drivers/rmnet/perf/Kbuild
@@ -1,3 +1,3 @@
-obj-m += rmnet_perf.o
+obj-$(CONFIG_RMNET_PERF) += rmnet_perf.o
 rmnet_perf-y := rmnet_perf_config.o rmnet_perf_core.o rmnet_perf_opt.o \
 		rmnet_perf_tcp_opt.o rmnet_perf_udp_opt.o
diff --git a/techpack/data/drivers/rmnet/perf/Kconfig b/techpack/data/drivers/rmnet/perf/Kconfig
index e55d24e59668..f2af253aa93d 100644
--- a/techpack/data/drivers/rmnet/perf/Kconfig
+++ b/techpack/data/drivers/rmnet/perf/Kconfig
@@ -2,9 +2,9 @@
 # RMNET_PERF driver
 #
 
-menuconfig RMNET_PERF
-    tristate "Rmnet Perf driver"
-    default m
-#    depends on RMNET
-    ---help---
-        performance mode of rmnet driver
\ No newline at end of file
+config RMNET_PERF
+	tristate "Rmnet Perf driver"
+	default m
+	depends on RMNET
+	---help---
+	  performance mode of rmnet driver
diff --git a/techpack/data/drivers/rmnet/shs/Kbuild b/techpack/data/drivers/rmnet/shs/Kbuild
index 055d8561a80b..31ae0ce036c7 100644
--- a/techpack/data/drivers/rmnet/shs/Kbuild
+++ b/techpack/data/drivers/rmnet/shs/Kbuild
@@ -1,2 +1,2 @@
-obj-m += rmnet_shs.o
+obj-$(CONFIG_RMNET_SHS) += rmnet_shs.o
 rmnet_shs-y := rmnet_shs_config.o rmnet_shs_main.o rmnet_shs_wq.o
diff --git a/techpack/data/drivers/rmnet/shs/Kconfig b/techpack/data/drivers/rmnet/shs/Kconfig
index 52c401995bb3..b5c9199a4011 100644
--- a/techpack/data/drivers/rmnet/shs/Kconfig
+++ b/techpack/data/drivers/rmnet/shs/Kconfig
@@ -2,9 +2,9 @@
 # RMNET_SHS driver
 #
 
-menuconfig RMNET_SHS
-    tristate "Rmnet SHS driver"
-    default m
-#    depends on RMNET
-    ---help---
-        performance mode of rmnet driver
+config RMNET_SHS
+	tristate "Rmnet SHS driver"
+	default m
+	depends on RMNET
+	---help---
+	  performance mode of rmnet driver

Then append the following to the defconfig:

CONFIG_RMNET_PERF=y
CONFIG_RMNET_SHS=y

Step 3: Build

Use cas_user_defconfig:

export PATH=/home/username/Clang/bin:$PATH
 
# Generate .config
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LLVM=1 LLVM_IAS=1 \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi- \
  cas_user_defconfig
 
# Full build
make -j$(nproc --all) CC="ccache clang" O=out ARCH=arm64 \
  LLVM=1 LLVM_IAS=1 \
  CLANG_TRIPLE=aarch64-linux-gnu- \
  CROSS_COMPILE=/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android- \
  CROSS_COMPILE_ARM32=/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi-

A successful build ends with OBJCOPY arch/arm64/boot/Image.

Known Build Issues


Issue 1: multiple definition of 'yylloc'

Edit scripts/dtc/dtc-lexer.l and change:

YYLTYPE yylloc;

to:

extern YYLTYPE yylloc;

Issue 2: gcc-wrapper.py fails

In the top-level kernel Makefile, find:

REAL_CC		= $(CROSS_COMPILE)gcc

Rename REAL_CC to CC:

CC		= $(CROSS_COMPILE)gcc

Then remove the gcc-wrapper invocation entirely:

# Use the wrapper for the compiler.  This wrapper scans for new
# warnings and causes the build to stop upon encountering them
CC		= $(PYTHON) $(srctree)/scripts/gcc-wrapper.py $(REAL_CC)

Issue 3: built-in.a: member techpack/audio/dsp/elliptic in archive is not an object

Edit techpack/audio/Makefile and remove:

obj-y += dsp/elliptic
#for mius start
ifeq ($(CONFIG_US_PROXIMITY), y)
obj-y += dsp/mius
endif
#for mius end

Issue 4: error: relocation R_AARCH64_ABS32 cannot be used against symbol __crc_gsi_write_channel_scratch; recompile with -fPIC

Two files need to be patched. The fix in both cases is removing the __packed qualifier from union and struct types in function signatures — it is incompatible with AArch64 relocation rules.

drivers/platform/msm/gsi/gsi.c:

diff --git a/drivers/platform/msm/gsi/gsi.c b/drivers/platform/msm/gsi/gsi.c
index 7c09cd45..f9b7d46a 100644
--- a/drivers/platform/msm/gsi/gsi.c
+++ b/drivers/platform/msm/gsi/gsi.c
@@ -1724,7 +1724,7 @@ int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props, unsigned long dev_hdl,
 EXPORT_SYMBOL(gsi_alloc_evt_ring);
 
 static void __gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
-		union __packed gsi_evt_scratch val)
+		union gsi_evt_scratch val)
 ...
 int gsi_write_channel_scratch(unsigned long chan_hdl,
-		union __packed gsi_channel_scratch val)
+		union gsi_channel_scratch val)
 ...
-static union __packed gsi_channel_scratch __gsi_update_mhi_channel_scratch(
-	unsigned long chan_hdl, struct __packed gsi_mhi_channel_scratch mscr)
+static union gsi_channel_scratch __gsi_update_mhi_channel_scratch(
+	unsigned long chan_hdl, struct gsi_mhi_channel_scratch mscr)
 ...

(The full patch covers all function signatures containing __packed in this file — replace every union __packed / struct __packed with union / struct.)

include/linux/msm_gsi.h:

diff --git a/include/linux/msm_gsi.h b/include/linux/msm_gsi.h
index 177e1abd..8aed281b 100644
--- a/include/linux/msm_gsi.h
+++ b/include/linux/msm_gsi.h
 int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
-		union __packed gsi_evt_scratch val);
+		union gsi_evt_scratch val);
 ...
 int gsi_write_channel_scratch(unsigned long chan_hdl,
-		union __packed gsi_channel_scratch val);
+		union gsi_channel_scratch val);
 ...

(The full patch covers all function declarations and inline functions in this header that contain __packed — the fix is identical throughout.)