Since many years i usually run some rather recent version of mainline linux on my Ubuntu production laptops using the Ubuntu Mainline Kernel PPA. Starting with Kernel 5.4 i kind of stopped since additional Kernel modules i use (with DKMS) stopped to compile. This article explains how i fixed them.
Get newer C compiler (gcc 9)
First problem, it seems the C compiler shipped with Ubuntu 18.04 (which is gcc 7) cannot build Kernels >= 5.4.
Checking the running Kernel’s version also shows the compiler it is compiled with:
$ cat /proc/version
Linux version 5.6.0-050600rc1-generic (kernel@tangerine) (gcc version 9.2.1 20200203 (Ubuntu 9.2.1-28ubuntu1)) #202002092032 SMP Mon Feb 10 01:36:50 UTC 2020
So the Kernel i currently use is built with gcc 9. So let’s get that.
Fortunately thats easy. The Ubuntu Toolchain Uploads (restricted) PPA contains gcc 9.
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt install gcc-9
$ gcc-9 -v
Using built-in specs.
COLLECT_GCC=gcc-9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.2.1-17ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.2.1 20191102 (Ubuntu 9.2.1-17ubuntu1~18.04.1)
Nice - that’s good enough.
Patch bbswitch-0.8 DKMS module (to disable discrete NVIDIA graphics)
So, now tell DKMS to use that compiler instead of the default. I quick and dirty modified the source (which is found in /usr/src/bbswitch-0.8
) in place like this.
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ KVERSION := $(shell uname -r)
KDIR := /lib/modules/$(KVERSION)/build
PWD := "$$(pwd)"
+CC=gcc-9
+
ifdef DEBUG
CFLAGS_$(obj-m) := -DDEBUG
endif
Turned out due to changes in the Kernel itself, another small patch is needed to make bbswitch compile.
--- a/bbswitch.c
+++ b/bbswitch.c
@@ -31,7 +31,7 @@
#include <linux/pci.h>
#include <linux/acpi.h>
#include <linux/module.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
#include <linux/suspend.h>
#include <linux/seq_file.h>
#include <linux/pm_runtime.h>
@@ -375,12 +375,12 @@ static int bbswitch_pm_handler(struct notifier_block *nbp,
return 0;
}
-static struct file_operations bbswitch_fops = {
- .open = bbswitch_proc_open,
- .read = seq_read,
- .write = bbswitch_proc_write,
- .llseek = seq_lseek,
- .release= single_release
+static struct proc_ops bbswitch_fops = {
+ .proc_open = bbswitch_proc_open,
+ .proc_read = seq_read,
+ .proc_write = bbswitch_proc_write,
+ .proc_lseek = seq_lseek,
+ .proc_release= single_release
};
That’s it. bbswitch
loads and functions just fine again.
Patch acpi-call-1.1.0 DKMS module for ACPI calls
I use acpi-call for stuff as well. Also fails to build for the same reasons as bbswitch above. Very simple to apply a similar patch to the files in /usr/src/acpi-call-1.1.0
. Then it loads and works again.
This is published here so it may be helpful to others.