@@ -6,7 +6,7 @@
}
= Linux Kernel Programming
In this lab, we learn how to develop a tiny kernel module. We initially create a tiny skeleton that just print a message when the module is loaded and unloaded in #ln ( 1 ) . Then in #ln ( 2 ) , we see how to use parameters with insmod and with modprobe. To make things easier for us, we’ ve added a line to the makefile that copy the module’ s configuration file (that contain the parameters for the modules) to the correct directory on the target. The `install` command is used as combination of `mkdir` , `cp` and `chmod` .
In this lab, we learn how to develop a tiny kernel module. We initially create a tiny skeleton that just print a message when the module is loaded and unloaded in #ln ( 1 ) . Then in #ln ( 2 ) , we see how to use parameters with insmod and with modprobe. To make things easier for us, we’ ve added a line to the makefile that copy the module’ s configuration file (that contain the parameters for the modules) to the correct directory on the target. The `install` command is used as a combination of `mkdir` , `cp` and `chmod` .
`` `makefile
install:
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
@@ -14,7 +14,7 @@ install:
` ``
The exercic e 3 ask us what does it mean the 4 values in `` ` /proc/sys/kernel/printk``` ?
The exercis e 3 ask us what does it mean the 4 values in `/proc/sys/kernel/printk` ?
We can show what there is in:
`` `bash
|> cat /proc/sys/kernel/printk
@@ -44,9 +44,17 @@ This number matches with this table (#link("https://www.kernel.org/doc/html/late
[ KERN_CONT], ["c"], [pr_ cont()] ,
)
In #ln ( 4 ) , we see how to dynamically create elements in the kernel.
In #ln ( 4 ) , we see how to dynamically create elements in the kernel. We use `kcallo` instead of `kzalloc` to allocate all the memory at once and be certain we have the necessary place for all elements of our module. It also a better approach in our opinion to avoid fragmentation.
== Cheatsheet commands
We spent some time on the #ln ( 5 ) to understand that the `request_mem_region` failed because we have an overlap with the EEPROM.
The #ln ( 6 ) was a straightforward exercise where we had to develop a module that instantiated a thread.
In the #ln ( 7 ) was on concurrency. We had 2 threads with a wait queue. We learn how to suspend a thread, how to wake it up and how to do atomic operation.
In the last exercise of this lab, #ln ( 8 ) , we see how to manage interruptions and connect them to a gpio.
== Cheat sheet commands
- `modinfo <module.ko>` : display information about a kernel module
- `insmod <module.ko>` : install a kernel module (without checking for dependencies)
- `rmmod <module.ko>` : uninstall a kernel module
@@ -57,3 +65,15 @@ In #ln(4), we see how to dynamically create elements in the kernel.
- `modprobe -r <module>` : uninstall a kernel module and its dependencies
- `make` : build the kernel module
- `make install` : install the kernel module in the root filesystem
== Zed
For this lab, we start to work with another code editor than vscode. Not because we don't like Microsoft, ... but mostly for this reason. We use zed with the new devcontainer implementation on this wonderful code editor. To be able to work in nice condition, we add our own `.clangd` build with the help `bear` .
This clangd, allow us to have a perfect autocompletion and a enjoyable code navigation. We can easily jump to the definition of a function and see the documentation of a function.
Thanks to Zed teams for this awesome code editor and \ @Fastium for his clangd
== Conclusion
All this lab was done by iteration on the initial skeleton. We develop everything in the #link ( "https://github.com/Klagarge/MSE-MA-CSEL/tree/main/src/01-skeleton" ) [ src/01-skeleton] folder.
It was a very delightful introduction lab that show us some possibilities when we want to create a kernel module. Everything was new for us, so even it's basics concept, this was a bit challenging to grasp the subject.