The Linux Kernel Module Programming Guide

by eating555on 8/2/2021, 2:00 PMwith 30 comments

by fmntfon 8/2/2021, 6:55 PM

In my opinion the best way to do kernel development is to just look at device drivers in kernel sources, study what current drivers do and write your own driver. The kernel supports su much heterogeneous devices and its APIs change continuously that it is practically impossible to write a complete guide on this topic.

by joezydecoon 8/2/2021, 4:29 PM

Just a warning if you do embedded work with Linux (RPi, Beaglebone, etc)... this guide doesn't cover the Devicetree APIs. Doesn't even acknowledge their existence.

by asicspon 8/3/2021, 4:47 AM

See also: https://0xax.gitbooks.io/linux-insides/

by mrmattyboyon 8/3/2021, 5:38 PM

Not sure if the eating555 is the author or whether the author is watching this thread...

This is awesome.. my only comment is the first thing I went to do was to copy and paste the code blocks and found end of line whitespace and double line breaks were included (presumably for the line numbering etc.)

e.g.

sudo apt-get update

apt-cache search linux-headers-`uname -r`

by nrclarkon 8/2/2021, 5:54 PM

A semi-related question: do kernel modules play nicely with device-tree instantiations?

Like let's say I wanted to instantiate an I2C with a custom driver in my device-tree. Can I put the controller's driver in a kernel module that lives in /lib/modules? Or do I need to compile it into the kernel?

by yurishon 8/3/2021, 8:29 AM

Tried to make text size larger at https://sysprog21.github.io/lkmpg/ and could not, it stays fixed. It would be great to fix this problem.

by Namidairoon 8/3/2021, 7:19 AM

Would I be out of line in suggesting DKMS to be used?

I figure it would be close to mandatory for anyone who wanted to distribute their module to others, without having to tell them to rebuild every time their kernel changed.

by sprc86on 8/2/2021, 7:29 PM

can you update the Makefile so it generate a PDF only? Also, the "make all" doesn't seems to be working as expected here. Probably missing some dependency.