You are not logged in.

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

isopod
Member
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.

Offline

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

Scimmia
Bug Wrangler
Registered: 2012-09-01
Posts: 8,197

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.

Offline

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

loqs
Member
Registered: 2014-03-06
Posts: 12,556

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>

pkgname=mpow-bh456a-driver
pkgver=20200610.0.0
pkgrel=1
pkgdesc='Driver for the MPOW BH456A USB bluetooth dongle (Realtek RTL8761BU)'
_srcname='20200610_LINUX_BT_DRIVER'
url='https://www.xmpow.com/'
arch=(x86_64)
license=(GPL2)
depends=(linux)
makedepends=(linux-headers)
source=(
	'https://mpow.s3-us-west-1.amazonaws.com/mpow_MPBH456AB_driver+for+Linux.tgz'
)
sha256sums=(
	'74001cd412363485751a8e11dda7de54919de51a74d7f060ce489d0a9291040b'
)

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)

Offline

Board footer

Powered by FluxBB