1
0

doc: add end of report for lab01-module

This commit is contained in:
2026-04-02 21:07:20 +02:00
parent 6b0246b2a5
commit 76699b8d19
4 changed files with 27 additions and 8 deletions

View File

@@ -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. 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( #figure(
image("./dev-environment.drawio.svg"), image("./dev-environment.png"),
caption: "Development environment schema" caption: "Development environment schema"
) <fig:dev-env> ) <fig:dev-env>

View File

@@ -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```. 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`

View File

@@ -6,7 +6,7 @@
} }
= Linux Kernel Programming = 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, weve added a line to the makefile that copy the modules 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, weve added a line to the makefile that copy the modules 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 ```makefile
install: install:
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_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: We can show what there is in:
```bash ```bash
|> cat /proc/sys/kernel/printk |> 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()], [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 - `modinfo <module.ko>`: display information about a kernel module
- `insmod <module.ko>`: install a kernel module (without checking for dependencies) - `insmod <module.ko>`: install a kernel module (without checking for dependencies)
- `rmmod <module.ko>`: uninstall a kernel module - `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 - `modprobe -r <module>`: uninstall a kernel module and its dependencies
- `make`: build the kernel module - `make`: build the kernel module
- `make install`: install the kernel module in the root filesystem - `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.

View File

@@ -28,8 +28,7 @@ clean:
install: install:
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install $(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
install -d $(MODPATH)/etc/modprobe.d install -D -m 0644 $(SOURCE).conf $(MODPATH)/etc/modprobe.d/$(SOURCE).conf
install -m 0644 $(SOURCE).conf $(MODPATH)/etc/modprobe.d/$(SOURCE).conf
endif endif