dh_dkms

Packaging a DKMS package with dh_dkms

Brief Backgound

  • DKMS - Dynamic Kernel Module Support
    • (manpage) dkms is a framework which allows kernel modules to be dynamically built for each kernel on your system in a simplified and organized fashion.
    • not Debian/Ubuntu only
  • Terminology used/mixed in HWE
    • dkms = the "framework" or the command itself
    • dkms package = a source/binary debian package that uses dkms
    • dkms ≠ a kernel driver tarball
    • dkms is not the only way to package a kernel module

How most dkms packages are generated in PES

DKMS package provided by HWE

  • No standard
  • could be just generated from dkms mkdsc

    • No Author (cannot be signed)
    • No descrption in debian/control
    • "uname -r" pitfall

Using dh_dkms

├── btloader
│   ├── Makefile
│   ├── mt76xx.c
│   └── mt76xx.h
├── firmware
│   ├── BT
│   │   └── mt76x0.bin
│   └── Wi-FI
│       └── MT7650E234.bin
├── ReadMe
└── rt2x00
    ├── build.sh
    ├── Kconfig
    ├── load.sh
    ├── Makefile
    ├── mt_linux.c
    ├── rt2400pci.c
    ├── rt2400pci.h
    ├── rt2500pci.c
    ├── rt2500pci.h
    ├── rt2500usb.c
    ├── rt2500usb.h
    ├── rt2800.h
    ├── rt2800lib.c
    ├── rt2800lib.h
    ├── rt2800pci.c
    ├── rt2800pci.h
    ├── rt2800usb.c
    ├── rt2800usb.h
    ├── rt2x00config.c
    ├── rt2x00crypto.c
    ├── rt2x00debug.c
    ├── rt2x00debug.h
    ├── rt2x00dev.c
    ├── rt2x00dump.h
    ├── rt2x00firmware.c
    ├── rt2x00.h
    ├── rt2x00leds.c
    ├── rt2x00leds.h
    ├── rt2x00lib.h
    ├── rt2x00link.c
    ├── rt2x00mac.c
    ├── rt2x00mmio.c
    ├── rt2x00mmio.h
    ├── rt2x00pci.c
    ├── rt2x00pci.h
    ├── rt2x00queue.c
    ├── rt2x00queue.h
    ├── rt2x00reg.h
    ├── rt2x00soc.c
    ├── rt2x00soc.h
    ├── rt2x00usb.c
    ├── rt2x00usb.h
    ├── rt61pci.c
    ├── rt61pci.h
    ├── rt73usb.c
    ├── rt73usb.h
    └── unload.sh

tar zxf MT7630E_Wi-Fi_BT_Source_V3.14_20140625_v2.tar.gz
mv MT7630E_Wi-Fi_BT_Source_V3.14_20140625_v2.tar.gz mt7630e_20140625-v2.orig.tar.gz
cd to the extracted direcotory
dh_make (choose 'm')
cd debian
rm -f docs init.d.ex manpage.* menu.ex mt7630e.cron.d.ex postinst.ex postrm.ex prerm.ex preinst.ex watch.ex mt7630e*
  • What needs to be done: 'copy the source to /usr/src and trigger dkms'

  • Add the following in the beginning of debian/rules

include /usr/share/dpkg/default.mk

DEB_BUILD_ARCH := $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEBVERS := $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2 \
                | cut -d- -f1)
VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/[+-].*//' -e 's/~//g')

override_dh_dkms:
        dh_dkms -V $(VERSION)

%:
        dh $@ --with dkms
  • Update the debian/rules

DKMS_WIFI_SRC_DIR := $(CURDIR)/debian/mt7630e-wireless/usr/src/mt7630e-wireless-$(VERSION)
DKMS_BT_SRC_DIR := $(CURDIR)/debian/mt7630e-bluetooth/usr/src/mt7630e-bluetooth-$(VERSION)

override_dh_auto_install:
        install -d $(DKMS_BT_SRC_DIR)
        install -d $(DKMS_WIFI_SRC_DIR)
        cp -a btloader/* $(DKMS_BT_SRC_DIR)
        cp -a rt2x00/* $(DKMS_WIFI_SRC_DIR)
        dh_auto_install
  • Update debian/control as follow

Source: mt7630e
Section: net
Priority: optional
Maintainer: Keng-Yu Lin <kengyu@lexical.tw>
Build-Depends: debhelper (>= 9), dkms
Standards-Version: 3.9.5
Homepage: http://www.mediatek.com/en/downloads/mt7630-pcie/

Package: mt7630e-wireless
Architecture: any
Depends: ${misc:Depends}, dkms, linux-headers-generic (< 3.15) | linux-headers-generic-lts-trusty
Description: MT7630 wireless driver and firmware
 MT7630 wireless driver in DKMS format and firmware.

Package: mt7630e-bluetooth
Architecture: any
Depends: ${misc:Depends}, dkms, linux-headers-generic | linux-headers-generic-lts-trusty
Description: MT7630 bluetooth firmware loader and firmware
 MT7630 bluetooth firmware and its kernel-space loader.
  • Use quilt to patch the Makefile for kernel modules

$ cat 0001-remove-uname-kver.patch 
--- a/btloader/Makefile
+++ b/btloader/Makefile
@@ -1,5 +1,4 @@
 obj-m := mt76xx.o
-KVERSION:= $(shell uname -r)
 
 all:
        $(MAKE) -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
--- a/rt2x00/Makefile
+++ b/rt2x00/Makefile
@@ -23,8 +23,6 @@
 obj-$(CONFIG_RT73USB)                  += rt73usb.o
 obj-$(CONFIG_RT2800USB)                        += rt2800usb.o
 
-KVERSION:= $(shell uname -r)
-
 all:
        $(MAKE) -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
 clean
  • Create the file debian/mt7630e-bluetooth.dkms and add the following

PACKAGE_NAME="mt7630e-bluetooth"
PACKAGE_VERSION="#MODULE_VERSION#"
MAKE[0]="KVERSION=$kernelver make"
BUILT_MODULE_NAME[0]="mt76xx"
DEST_MODULE_LOCATION[0]="/updates/"
AUTOINSTALL="yes"
  • Create the file debian/mt7630e-wireless.dkms and add the following

PACKAGE_NAME="mt7630e-wireless"
PACKAGE_VERSION="#MODULE_VERSION#"
MAKE[0]="KVERSION=$kernelver make"
BUILT_MODULE_NAME[0]="rt2x00lib"
BUILT_MODULE_NAME[1]="rt2x00pci"
BUILT_MODULE_NAME[2]="rt2x00mmio"
BUILT_MODULE_NAME[3]="rt2800lib"
BUILT_MODULE_NAME[4]="rt2800pci"
DEST_MODULE_LOCATION[0]="/updates/"
DEST_MODULE_LOCATION[1]="/updates/"
DEST_MODULE_LOCATION[2]="/updates/"
DEST_MODULE_LOCATION[3]="/updates/"
DEST_MODULE_LOCATION[4]="/updates/"
AUTOINSTALL="yes"
  • Update debian/changelog

mt7630e (20140625-v2-1) trusty; urgency=low

  * Initial release

 -- Keng-Yu Lin <kengyu@lexical.tw>  Thu, 27 Nov 2014 19:53:42 +0800
  • At this stage, the two dkms packages work.
  • Add the firmware installation part
    • Add the file debian/mt7630e-bluetooth.install

firmware/BT/mt76x0.bin /lib/firmware
  • Add the file debian/mt7630e-wireless.install

firmware/Wi-FI/MT7650E234.bin /lib/firmware

Reference

kengyu/dh_dkms (last edited 2015-11-24 10:31:09 by 61-228-164-191)