From 6b0246b2a5c3e6bc063a3f1250dac5a4c618c51c Mon Sep 17 00:00:00 2001 From: Klagarge Date: Thu, 2 Apr 2026 18:28:29 +0200 Subject: [PATCH] refactor: modify until exercice 4 --- doc/lab-01_02.typ | 12 +++++++ doc/lab01-module/ex02.typ | 10 +++--- doc/lab01-module/ex03.typ | 5 +-- doc/lab01-module/ex04.typ | 34 +++++++++---------- doc/lab01-module/ex05.typ | 30 ++++++++--------- doc/lab01-module/ex06.typ | 13 +++----- doc/lab01-module/ex07.typ | 12 +++---- doc/lab01-module/ex08.typ | 24 ++++++-------- doc/lab01-module/main.typ | 61 +++++++++++++++++++++++++---------- doc/lab02-peripheral/main.typ | 6 ++++ 10 files changed, 113 insertions(+), 94 deletions(-) diff --git a/doc/lab-01_02.typ b/doc/lab-01_02.typ index 4d49bb4..bf0d605 100644 --- a/doc/lab-01_02.typ +++ b/doc/lab-01_02.typ @@ -52,7 +52,19 @@ #pagebreak() = #i18n("appendix-title", lang: option.lang) == Exercices Lab 01 + #include "lab01-module/ex01.typ" +#pagebreak() +#include "lab01-module/ex02.typ" +#include "lab01-module/ex03.typ" +#pagebreak() +#include "lab01-module/ex04.typ" +#pagebreak() +#include "lab01-module/ex05.typ" +#include "lab01-module/ex06.typ" +#pagebreak() +#include "lab01-module/ex07.typ" +#include "lab01-module/ex08.typ" //------------------------------------- // Glossary diff --git a/doc/lab01-module/ex02.typ b/doc/lab01-module/ex02.typ index 6722c82..10a8299 100644 --- a/doc/lab01-module/ex02.typ +++ b/doc/lab01-module/ex02.typ @@ -1,11 +1,9 @@ #import "/doc/metadata.typ": * -#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. - ], -) +=== Adapt the kernel module to receive parameters +#colorbox(title: "Exercise", color: hei-blue)[ + 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. +] ```bash |> modprobe mymodule diff --git a/doc/lab01-module/ex03.typ b/doc/lab01-module/ex03.typ index 35ea0c7..5db89d5 100644 --- a/doc/lab01-module/ex03.typ +++ b/doc/lab01-module/ex03.typ @@ -1,9 +1,6 @@ #import "/doc/metadata.typ": * -#task( - [What does it mean the 4 values in ```/proc/sys/kernel/printk``` ?], - [] -) +=== What does it mean the 4 values in ```/proc/sys/kernel/printk``` ? We can show what there is in: diff --git a/doc/lab01-module/ex04.typ b/doc/lab01-module/ex04.typ index ff14993..90c1cf5 100644 --- a/doc/lab01-module/ex04.typ +++ b/doc/lab01-module/ex04.typ @@ -1,16 +1,12 @@ #import "/doc/metadata.typ": * -#task( - [ - Create module with dynamic allocation and a chained list - ], - [ - Create dynamically elements in the kernel. Adapt a kernel module to specify at the installation the number of element to create a initial text. - Each element will contain a unique number. The elements are create at the installation of the module adn chained in a list. - These elements will be destruct during the uninstallation of the module. - Some information messages are emits to allow debugging. - ] -) +=== Create module with dynamic allocation and a chained list +#colorbox(title: "Exercise", color: hei-blue)[ + Create dynamically elements in the kernel. Adapt a kernel module to specify at the installation the number of element to create a initial text. + Each element will contain a unique number. The elements are create at the installation of the module adn chained in a list. + These elements will be destruct during the uninstallation of the module. + Some information messages are emits to allow debugging. +] To allocate memory in the kernel, we can use the `kcalloc` function. It allows to allocate directly the memory for all element. It's also possible to use `kzalloc` in a loop to allocate memory for each element. We prefer allocate all the memory at once to avoid fragmentation and to be sure all the memory can be allocated. @@ -18,12 +14,12 @@ To allocate memory in the kernel, we can use the `kcalloc` function. It allows t struct element* element_ptr = kcalloc(elements, sizeof(struct element), GFP_KERNEL); for (int i = 0; i < elements; i++) { - struct element* e = element_ptr + i; - if (e != 0) { - strncpy(e->text, text, TEXT_LENGTH_MAX - 1); - e->unique_number = i; - list_add_tail(&e->node, &list_unique_elements); - pr_info ("add element %d: %s\n", e->unique_number, e->text); - } - } + struct element* e = element_ptr + i; + if (e != 0) { + strncpy(e->text, text, TEXT_LENGTH_MAX - 1); + e->unique_number = i; + list_add_tail(&e->node, &list_unique_elements); + pr_info ("add element %d: %s\n", e->unique_number, e->text); + } +} ``` diff --git a/doc/lab01-module/ex05.typ b/doc/lab01-module/ex05.typ index 935ca8f..26fe37a 100644 --- a/doc/lab01-module/ex05.typ +++ b/doc/lab01-module/ex05.typ @@ -1,24 +1,20 @@ #import "/doc/metadata.typ": * -#task( - [ - Display the processor chip ID, CPU temperature and the MAC adress of the Ethernet controller - ], - [ - - Chip ID registers: _0x01c1'4200_ to _0x01c1'420c_ - - 32 bits register of the temperature sensor: _0x01c2'5080_ - - two 32 bits registers of the Ethernet controller MAC address: _0x01c3'0050_ and _0x01c3'0054_ +=== Display the processor chip ID, CPU temperature and the MAC adress of the Ethernet controller +#colorbox(title: "Exercise", color: hei-blue)[ + - Chip ID registers: _0x01c1'4200_ to _0x01c1'420c_ + - 32 bits register of the temperature sensor: _0x01c2'5080_ + - two 32 bits registers of the Ethernet controller MAC address: _0x01c3'0050_ and _0x01c3'0054_ - To calculate the temperature value, there is this formul: - $ - "temperature" = -1991 dot "register value" / 10 + 223000 - $ + To calculate the temperature value, there is this formul: + $ + "temperature" = -1991 dot "register value" / 10 + 223000 + $ - The chip ID can be verified in ```/proc/iomem```. - The register value of the temperature can be verified in the file: ```/sys/class/thermal/thermal_zone0/temp```. - The MAC address can be verified with ``` ifconfig```. - ] -) + The chip ID can be verified in ```/proc/iomem```. + The register value of the temperature can be verified in the file: ```/sys/class/thermal/thermal_zone0/temp```. + The MAC address can be verified with ``` ifconfig```. +] The resources are savec in a struct: ```c diff --git a/doc/lab01-module/ex06.typ b/doc/lab01-module/ex06.typ index 0505b72..aff53ce 100644 --- a/doc/lab01-module/ex06.typ +++ b/doc/lab01-module/ex06.typ @@ -1,13 +1,8 @@ #import "/doc/metadata.typ": * -#task( - [ - Kernel thread - ], - [ - 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```. - - ] -) +=== Kernel thread +#colorbox(title: "Exercise", color: hei-blue)[ + 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` diff --git a/doc/lab01-module/ex07.typ b/doc/lab01-module/ex07.typ index 1e7542e..b01b29d 100644 --- a/doc/lab01-module/ex07.typ +++ b/doc/lab01-module/ex07.typ @@ -1,13 +1,9 @@ #import "/doc/metadata.typ": * -#task( - [ - Sleeping - ], - [ - Develop a module which instanciate 2 threads in the kernel. The first one will wait a wake up notification from the second thread and will sleep. The second will send the notification every 5 seconds. Then it will sleep. We will use the waitqueue for the sleeping function. To allow debugging, each thread will send a message when it wakes up. - ] -) +=== Sleeping +#colorbox(title: "Exercise", color: hei-blue)[ + Develop a module which instanciate 2 threads in the kernel. The first one will wait a wake up notification from the second thread and will sleep. The second will send the notification every 5 seconds. Then it will sleep. We will use the waitqueue for the sleeping function. To allow debugging, each thread will send a message when it wakes up. +] This exercice make 2 threads in concurrency with wait queue. Here the queue ware declare statically with the macro `DECLARE_WAIT_QUEUE_HEAD`. Then for this exercice we use an atomic diff --git a/doc/lab01-module/ex08.typ b/doc/lab01-module/ex08.typ index ae3cfeb..708a0de 100644 --- a/doc/lab01-module/ex08.typ +++ b/doc/lab01-module/ex08.typ @@ -1,20 +1,16 @@ #import "/doc/metadata.typ": * -#task( - [ - Interrupts - ], - [ - Develop a module which allows to detect every push on the button of the nanopi with interrupt. Every interrupts will send a message for debugging. +=== Interrupts +#colorbox(title: "Exercise", color: hei-blue)[ + Develop a module which allows to detect every push on the button of the nanopi with interrupt. Every interrupts will send a message for debugging. - - Use the service ``` gpio_request(,