1
0

feat(lab02): add module/exercice1

This commit is contained in:
2026-03-20 16:17:03 +01:00
parent 6f10dd0333
commit eab03b73aa

View File

@@ -7,6 +7,9 @@
#import "@preview/fractusist:0.1.1":*
#import "@preview/grape-suite:3.1.0": exercise
#import exercise: task, subtask
//-------------------------------------
// Template config
//
@@ -53,6 +56,9 @@ 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.
// PLACEHOLEDER SCHEMA
== Questions
=== How to generate U-Boot?
We use buildroot, a tool to build embedded Linux.
@@ -69,7 +75,7 @@ In buildroot, with `make menuconfig`, we can select the package we want in `Targ
=== How to modify the Linux kernel configuration?
Like all package, with `make <package-name>-menuconfig` command. So, for Linux kernel:
```bash
make linux-menuconfig
|> make linux-menuconfig
```
=== How to generate a custom rootfs?
@@ -93,9 +99,118 @@ If we develop only user space program, we don't need to load kernel by tftp. But
#pagebreak()
= Linux Kernel Programming
#lorem(150)
== Exercises
//-------------------
// Exercise 1: Generate kernel module out of tree
//-------------------
#task(
[Generate kernel module out of tree],
[],
)
//--------------
#subtask[
Create the skeleton of a kernel module and generate it outside the kernel sources using a Makefile. The module should display a message when it is registered and when it is uninstalled.
]
We already have a skeleton in `src/02-modules/exercice01`. We see on the Makefile that the module is generated outside the kernel sources with the `KDIR` variable imported from `src/kernel_settings`. This variable point to the kernel sources.
The Makefile also use the `PWD` variable to the current directory.
The `make` command will use these variables to generate the module in the current directory.
```makefile
$(MAKE) -C $(KDIR) M=$(PWD) ARCH=$(CPU) CROSS_COMPILE=$(TOOLS) modules
```
//--------------
#subtask[
Test on the host machine the command modinfo1 on your module skeleton and compare the information returned with that of the source code.
]
```bash
|> modinfo mymodule.ko
filename: /workspace/src/02_modules/exercice01/mymodule.ko
license: GPL
description: Module skeleton
author: Daniel Gachet <daniel.gachet@hefr.ch>
depends:
name: mymodule
vermagic: 5.15.148 SMP preempt mod_unload aarch64
parm: text:charp
parm: elements:int
```
//--------------
#subtask[
Install the module (insmod) and check the kernel log (dmesg)
]
```bash
|> insmod mymodule.ko
[ 1727.896902] mymodule: loading out-of-tree module taints kernel.
[ 1727.903442] Linux module 01 skeleton loaded
```
We can see the module is indead out-of-tree and correctly loaded.
```bash
|> dmesg | tail -5
[ 1381.694764] CIFS: Attempting to mount \\192.168.53.4\workspace
[ 1727.896902] mymodule: loading out-of-tree module taints kernel.
[ 1727.903442] Linux module 01 skeleton loaded
[ 1727.907659] text: dummy text
[ 1727.907659] elements: 1
```
//--------------
#subtask[
Compare the results obtained by the lsmod command with those obtained with the cat /proc/modules command
]
```bash
|> lsmod
Module Size Used by Tainted: G
mymodule 16384 0
···
|> cat /proc/modules
mymodule 16384 0 - Live 0xffff8000011bf000 (O)
···
```
//--------------
#subtask[
Uninstall the module (rmmod).
]
```bash
|> rmmod mymodule.ko
[ 2989.535793] Linux module skeleton unloaded
```
//--------------
#subtask[
Adapt the Makefile of the module to allow the installation of the module with other kernel modules allowing the use of the modprobe command. The module should be installed in the root filesystem used in cifs by the target.
]
```bash
# On host:
|> make install
# On target:
|> modprobe mymodule
[ 3359.811183] Linux module 01 skeleton loaded
```
//-------------------
// Exercise 2: Adapt the kernel module to receive parameters
//-------------------
#task(
[Adapt the kernel module to receive parameters],
[
Adapt the kernel module of the previous exercise to receive two or three parameters of your choice. These parameters will be displayed in the console when the module is loaded.
],
)
#lorem(50)
//-------------------------------------
@@ -103,4 +218,3 @@ If we develop only user space program, we don't need to load kernel by tftp. But
//
#heading(numbering:none, outlined: false)[] <sec:end>
#make_glossary(gloss:gloss, title:i18n("gloss-title"))