How to build and deploy a Linux driver?

19,017

It seems the kernel you built isn't a 1:1 match. Also, generally there's no need to compile a new kernel.

The simplest way to deal with an out-of-tree driver deployment is to use DKMS.

What you need to provide is just a dkms.conf file specifying the package name, version, and driver names and destinations (within /lib/modules/{kernel}).

In the following examples, things within braces need to be replaced with the real thing, e.g. if version is 1.0.0, then {version} with 1.0.0, obviously.

Example dkms.conf:

PACKAGE_NAME="{mydriver}"
PACKAGE_VERSION="{version}"
BUILT_MODULE_NAME[0]="{mydriver}"
BUILT_MODULE_LOCATION[0]="/{mycompany?}"
AUTOINSTALL="yes"

Then you just need to install the sources to /usr/src/{mydriver}-{version}, and run dkms:

 dkms add -m {mydriver} -v {version}
 dkms build -m {mydriver} -v {version}
 dkms install -m {mydriver} -v {version}

You should take a look at what other people have done in this area, there's a great deal of automation you can apply to testing and release processes. Bluecherry's solo6x10 out-of-tree version provides some useful make targets (disclosure: I'm the one who wrote that).

Also, you definitely want to build and distribute packages, you can use solo6x10/debian as a template, and you can read about repositories in the Debian wiki.

Share:
19,017
user2309998
Author by

user2309998

Updated on June 15, 2022

Comments

  • user2309998
    user2309998 almost 2 years

    I am using ubuntu, but the question is for linux in general.

    I installed a module/driver by compiling my linux kernel and install the new compiled kernel. It works fine.

    In order to make this driver work in another machine without installing the new kernel, I copy the .ko file to the new machine under /lib/modules/<version>/... and then run sudo depmod -a. Then run sudo modprobe <drivername>. The module can be loaded without a problem. but the device is not working well with this .ko module.

    The two machines are not identical to hardwares, BUT they are identical to kernel version and ubuntu release version. Normally, copying .ko file should work for the same linux release and the same kernel.

    More information about the driver. it's a hid pen tablet driver. All patch files:

    • one .c file in drivers/hid/
    • add one line in drivers/hid/Makefile
    • add a few lines to drivers/hid/usbhid/Kconfig
    • add a few lines to drivers/hid/hid-ids.h
    • add a few lines to drivers/hid/usbhid/hid-quirks.c's hid_blacklist struct before { 0, 0 }

    That's all.

    I even tried to copy the entire drivers/hid/ directory includig all the .ko files from the first machine to the second one. but no luck. The pen tablet can be recognized in the second machine, I am able to do mouse left click event with the pen, but the pen can not move the cursor.

    Hopefully, I provided enough details. My goal is to only install the module to identical linux release (kernel) without reinstalling the kernel. I am not sure how to achieve that or if it's possible.

    Thanks a lot.

    PS:

    In 1st machine, before plugging in the tablet, lsmod doesn't show the module. after plugging in, the module can be loaded automatically. I can see lsmod shows the module.

    In 2nd mahcine, the module can not be loaded automatically by plugging in the device. I have to do sudo modprobe <module> manually.

    Since I will have to install the module to many machines in my company, it's easier to install the module without reinstalling the kernel. I tried to install the kernel .deb packages which built in the 1st machine to the 2nd machine, it works fine in 2nd machine. but I don't feel good to reinstall the kernel to many machines. Thanks.