Loadable kernel modules sandbox used to learn about LKMs.
Install kernel headers for your kernel version if they are missing in /usr/src/
sudo apt-get install linux-headers-$(uname -r)
If gcc is not installed
sudo apt install gcc
If make is not installed
sudo apt install make
cd
to each module directory and run make
To clean output files use make clean
To load module into the kernel use sudo make load
To unload module from the kernel use sudo make unload
Good method to observe kernel log in real time is following:
dmesg -wH
- 00_basic_module
- initialization of basic module
- usage of printk function
- 01_basic_tasklet
- 02_basic_sleep
- usage of workqueue
- schedulink works and delayed works
- one callback for both types of work
- msleep used for delay in callback
- developed way to distinguish which type of work started callback
- added counting semaphore to clean module when no callbacks are active
- 03_basic_timers
- improved kernel timer api [8]
- regular and high resolution timer configuration with callbacks
- 04_basic_char
- 05_char_ioctl
- 06_char_sysfs
- 07_timers_conf
- improved kernel timer api [8]
[1] Linux Device Drivers, Third Edition, O’Reilly
[2] Linux Device Drivers Development, John Madieu
[3] Writing a Linux Kernel Module by Derek Molloy: Part 1 and Part 2
[4] Linux Driver Tutorial: How to Write a Simple Linux Device Driver
[5] The Linux Kernel Module Programming Guide by Peter Jay Salzman and Ori Pomeranz
[6] Device Drivers, Part 4: Linux Character Drivers, Open Source For You
[7] LINUX KERNEL DEVELOPMENT – CREATING A PROC FILE AND INTERFACING WITH USER SPACE
[8] Improving the kernel timers API
- Add linux kernel include folders to Visual Studio Code. Paste following into c_cpp_properties.json file in section includePath. Adjust your kernel version.
"${workspaceFolder}/**",
"/usr/src/linux-headers-5.0.0-29-generic/*",
"/usr/src/linux-headers-5.0.0-29-generic/include/*",
"/usr/src/linux-headers-5.0.0-29-generic/include/linux/*",
"/usr/src/linux-headers-5.0.0-29-generic/include/asm-generic/*"