Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C

Kernel Modules using autoconf

5.00/5 (4 votes)
17 Dec 2015CPOL2 min read 12.8K   89  
Using the autoconf tool chain to add modules to the Linux kernel

Introduction

DKMS is the way to add modules to the linux kernel, but what if we didn't have access to the DKMS port? Embedded applications may not have it.

Background

DKMS has been around for a while, but the autoconf tool chain has been around a lot longer. What did kernel mod developers do before DKMS arrived? They used bizarre custom scripts, detailed recipes for implementers to follow, or they used autoconf. Autoconf is a rather mysterious black box of incantations and rituals to many people, I can't blame them for resorting to cmake for their projects, it's much simpler and straightforward than its older counterpart in the autoconf toolchain, but the underlying framework for cmake is infact that same arcane old system. Let's cut to the chase and use that underlying framework to implement a kernel mod where appropriate.

Using the Code

The code archive contains all the code necessary to build the old chardev kernel module example using the autoconf toolchain. The curious thing to note is the placeholder file "chardev.in" in the src directory that I added; this is necessary for a proper build of this code as a kernel module. Given that, the rest should fall into place for those familiar with autoconf builds (from the configure.ac file):

AC_CONFIG_FILES([Makefile module/chardev])

This reserves room in the build for the kernel module that isn't necessary in normal application builds. The toolchain is a rapidly moving target, one of the reasons people avoid it.

After compiling and installing the code, if you want to try the module, be sure to add the device node:

sudo mknod /dev/chardev c 60 0
sudo chmod 666 /dev/chardev
sudo insmod chardev.ko

And use the module as described in the Linux kernel module programming guide.

Points of Interest

Do make sure you note the necessary configure.ac directives, see especially:

AC_SUBST([with_kernel], [`uname -r`])
AC_SUBST([with_kernel_mod], [/lib/modules/$with_kernel/extra])
AC_SUBST([KERNEL_SRC], [/lib/modules/$with_kernel/build])
AC_SUBST([KERNEL_MOD], [$with_kernel_mod])

History

  • Version 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)