From 76699b8d1952f55447662b2c6641ca6da643700f Mon Sep 17 00:00:00 2001 From: Klagarge Date: Thu, 2 Apr 2026 21:07:20 +0200 Subject: [PATCH] doc: add end of report for lab01-module --- doc/lab00-env/main.typ | 2 +- doc/lab01-module/ex06.typ | 2 +- doc/lab01-module/main.typ | 28 ++++++++++++++++++++++++---- src/01-skeleton/Makefile | 3 +-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/doc/lab00-env/main.typ b/doc/lab00-env/main.typ index 6e8701a..05a48ed 100644 --- a/doc/lab00-env/main.typ +++ b/doc/lab00-env/main.typ @@ -5,7 +5,7 @@ In this laboratory, we see how to setup our environnement and how to have severa We also see how to debug our system with a remote debugger. That allow us to use debug in our code editor (vscode) a programm that run on the target. #figure( - image("./dev-environment.drawio.svg"), + image("./dev-environment.png"), caption: "Development environment schema" ) diff --git a/doc/lab01-module/ex06.typ b/doc/lab01-module/ex06.typ index aff53ce..42966e5 100644 --- a/doc/lab01-module/ex06.typ +++ b/doc/lab01-module/ex06.typ @@ -5,4 +5,4 @@ Develop a module which allows to instanciate a thread in the kernel. This thread will display a message every 5 seconds. Use the function ```ssleep(5)``` to sleep the thread from ``` linux/delay.h```. ] -Easy exercice, a thread in the kernet is a `struct task_struct*` that can be created with `kthread_run` +Easy exercice, a thread in the kernel is a `struct task_struct*` that can be created with `kthread_run` diff --git a/doc/lab01-module/main.typ b/doc/lab01-module/main.typ index acb9c57..62fd21f 100644 --- a/doc/lab01-module/main.typ +++ b/doc/lab01-module/main.typ @@ -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 exercice 3 ask us what does it mean the 4 values in ```/proc/sys/kernel/printk``` ? +The exercise 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 `: display information about a kernel module - `insmod `: install a kernel module (without checking for dependencies) - `rmmod `: uninstall a kernel module @@ -57,3 +65,15 @@ In #ln(4), we see how to dynamically create elements in the kernel. - `modprobe -r `: 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. diff --git a/src/01-skeleton/Makefile b/src/01-skeleton/Makefile index e32a182..9d4b9b2 100644 --- a/src/01-skeleton/Makefile +++ b/src/01-skeleton/Makefile @@ -28,8 +28,7 @@ clean: install: $(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install - install -d $(MODPATH)/etc/modprobe.d - install -m 0644 $(SOURCE).conf $(MODPATH)/etc/modprobe.d/$(SOURCE).conf + install -D -m 0644 $(SOURCE).conf $(MODPATH)/etc/modprobe.d/$(SOURCE).conf endif