You are not logged in.

#1 2021-01-11 18:59:15

Registered: 2021-01-11
Posts: 1

Best practice for packaging kernel modules?

I made a package for a driver and thought about adding it to the AUR. But I'm not really sure if what I'm doing is the correct way. I simply wrapped the manufacturer's installer Makefile and slightly modified it so it installs into a prefix instead of /, so it can be packaged. This Makefile uses "uname -r" to detect the module directory at compile time. I already ran into a problem with this when I tried to rebuild the package after updating the kernel (prior to reboot), since the version running wasn't the same as the one that was installed. It will also be a problem if someone uses multiple kernels since it will only install the module for the kernel that was running at compile time. Is there a better way to do this?

I vaguely remember reading something about pacman hooks and recompiling modules automatically once. Could that be used here?

Here's what I have so far.


#2 2021-01-11 23:16:41

Bug Wrangler
Registered: 2012-09-01
Posts: 8,204

Re: Best practice for packaging kernel modules?

DKMS is the simplest way of doing this. If you want pre-compiled modules, the normal package should be built specifically for the 'linux' package and not whatever happens to be running. You can have -lts, -zen, etc variants if you want to build against those kernels. You should be able to override the variable the makefile is using for uname -r.


#3 2021-01-12 00:35:00

Registered: 2014-03-06
Posts: 12,600

Re: Best practice for packaging kernel modules?

If you wanted to package for the linux kernel,  this skips to the Makefile for the kernel module to avoid calls to rmmod depmod and others that should be avoided,  the firmware would need to be added back e.t.c..
patch, gcc, and make are in devtools,  coreutils is a dependency of util-linux which is in devtools so you do not need to include them in makedepends.  linux-headers is needed to build kernel modules and linux is a build depends if you are targeting that kernel.  prefix custom variables with an _ e.g. _srcname.

# Maintainer: Philip Zander (isopod) <philip.zander+arch at gmail dot com>

pkgdesc='Driver for the MPOW BH456A USB bluetooth dongle (Realtek RTL8761BU)'

build() {
	cd "${srcdir}/${_srcname}/usb/bluetooth_usb_driver"
	make KDIR=/usr/src/linux

package() {
	_modulesdir="${pkgdir}$(realpath /usr/src/linux/../kernel/drivers/bluetooth)"
	install -Dm 644 -t "$_modulesdir" "${_srcname}/usb/bluetooth_usb_driver/rtk_btusb.ko"
	xz "$_modulesdir/"*.ko

Last edited by loqs (2021-01-12 00:37:36)


Board footer

Powered by FluxBB