How to compile linux kernel with some patches?
linux, kernel, realtime ·Unfortunately, my nettop candidate (Beelink Mini S12 Pro) for CNC mill has a problem with Wi-Fi on Debian 12. This is common for intel PC and there is a wide range of solutions in the Internet. For my particular case there is a good kernel patch on AskUbuntu. Also, there are more details for those who want to understand the topic deeper.
If in short, here is the patch:
--- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c 2023-04-04 10:22:33.957021791 +0800
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c 2023-04-04 11:51:37.377716152 +0800
@@ -1091,7 +1091,7 @@
_IWL_DEV_INFO(IWL_CFG_ANY, IWL_CFG_ANY,
IWL_CFG_MAC_TYPE_SO, IWL_CFG_ANY,
IWL_CFG_RF_TYPE_HR1, IWL_CFG_ANY,
- IWL_CFG_160, IWL_CFG_ANY, IWL_CFG_NO_CDB, IWL_CFG_ANY,
+ IWL_CFG_ANY, IWL_CFG_ANY, IWL_CFG_NO_CDB, IWL_CFG_ANY,
iwl_cfg_so_a0_hr_a0, iwl_ax101_name),
_IWL_DEV_INFO(IWL_CFG_ANY, IWL_CFG_ANY,
IWL_CFG_MAC_TYPE_SO, IWL_CFG_ANY,
@@ -1108,7 +1108,7 @@
_IWL_DEV_INFO(IWL_CFG_ANY, IWL_CFG_ANY,
IWL_CFG_MAC_TYPE_SOF, IWL_CFG_ANY,
IWL_CFG_RF_TYPE_HR1, IWL_CFG_ANY,
- IWL_CFG_160, IWL_CFG_ANY, IWL_CFG_NO_CDB, IWL_CFG_ANY,
+ IWL_CFG_ANY, IWL_CFG_ANY, IWL_CFG_NO_CDB, IWL_CFG_ANY,
iwl_cfg_so_a0_hr_a0, iwl_ax101_name),
_IWL_DEV_INFO(IWL_CFG_ANY, IWL_CFG_ANY,
IWL_CFG_MAC_TYPE_SOF, IWL_CFG_ANY,
Of course, this is not for Debian 12 and not for me current version of kernel which is 6.1.146. Therefore, need to apply al that changes manually. But where to find a kernel?
Debian has its own patches over a vanilla linux kernel. But I don’t want to understand all that nuances right now! Therefore, was found an excellent manual about compiling kernel for LinuxCNC.
This is easy:
- install all required packages (Reddit has a good thread):
sudo apt install build-essential linux-headers-$(uname -r) libncurses5-dev bc bison flex rsync libelf-dev libssl-dev debhelper-compat libncurses-dev dwarves wget
- download source code of kernel 6.1.146 from kernel.org
- download RT patch to enable PREEMPT_FULL from kernel.org
- extract kernel + patch and appy it:
tar -xpf linux-6.1.146.tar.xz gunzip patch-6.1.146-rt53.patch.gz cat patch-6.1.146-rt53.patch | patch -p1
- manually apply the Wi-Fi patch from above by editing
vim drivers/net/wireless/intel/iwlwifi/pcie/drv.c
- copy the current kernel config
cp /boot/config-6.1.0-38-rt-amd64 ./.config
- optionally: check PREEMPT section in
make menuconfig
to be sure in checked PREEMPT_FULL option - compile the kernel with
-iwlwifi
suffix:make deb-pkg LOCALVERSION=-iwlwifi KDEB_PKGVERSION=$(make kernelversion)-1 -j4
- wait a while… for me it was ~1.5 hours on regular kernel and more than 3 hours on RT-full kernel
- install compiled kernel
sudo dpkg -i ../linux-image-6.1.146-rt53-iwlwifi_6.1.146-1_amd64.deb sudo dpkg -i ../linux-headers-6.1.146-rt53-iwlwifi_6.1.146-1_amd64.deb
In case of any errors - ask Google, AI or any other assistance on your choice.
Advanced tweaks
To speed up the compilation process you can disable debug info by CONFIG_DEBUG_INFO=n
.
Main problem - this leads to a compilation error in a very end of the process. Theoretically,
BTF disabling should solve the problem. See corresponding thread for details.