Compare commits

..

3 commits

Author SHA1 Message Date
8e0721c2fb
Apply new nixos version 2025-02-26 18:54:09 +01:00
643c25e774
fix build failed in nixos 2025-02-26 18:53:53 +01:00
Florian RICHER
91f8ca7f49 Begin work on rust versions of modules 2025-02-26 17:08:49 +01:00
27 changed files with 48 additions and 100 deletions

1
.gitignore vendored
View file

@ -11,7 +11,6 @@
# Ignore other compiled files and directories
*.o
*.o.d
*.mod
*.symvers
*.order

View file

@ -1,5 +1,6 @@
{
"recommendations": [
"ms-vscode.cpptools-extension-pack"
"ms-vscode.cpptools-extension-pack",
"rust-lang.rust-analyzer"
]
}

View file

@ -1,35 +0,0 @@
#!/usr/bin/env bash
# Définir les détails du périphérique USB et des pilotes
VENDOR_ID="1b1c"
DEVICE_ID="0c0b"
NEW_DRIVER="lightning-node-pro"
# Vérifier les identifiants avec lsusb
echo "Vérifiez que le périphérique est listé avec les identifiants corrects :"
lsusb | grep "${VENDOR_ID}:${DEVICE_ID}"
# Trouver le chemin du périphérique USB
USB_DEVICE_PATH=$(find /sys/bus/usb/devices/*/ -type f -name 'idVendor' -execdir sh -c 'grep -q '"$VENDOR_ID"' idVendor && grep -q '"$DEVICE_ID"' idProduct && pwd' \; | head -n 1)
if [ -z "$USB_DEVICE_PATH" ]; then
echo "Périphérique USB non trouvé"
exit 1
fi
echo "Chemin du périphérique USB : $USB_DEVICE_PATH"
# Extraire l'identifiant du périphérique (par exemple, 1-10)
DEVICE_IDENTIFIER=$(basename "$USB_DEVICE_PATH")
echo "Identifiant du périphérique : $DEVICE_IDENTIFIER"
# Délier le périphérique USB du pilote actuel
echo "Délier le périphérique USB du pilote actuel..."
echo -n "$DEVICE_IDENTIFIER" | sudo tee "/sys/bus/usb/devices/$DEVICE_IDENTIFIER/driver/unbind" > /dev/null
# Lier le périphérique USB au nouveau pilote
echo "Lier le périphérique USB au nouveau pilote..."
echo -n "$DEVICE_IDENTIFIER" | sudo tee "/sys/bus/usb/drivers/${NEW_DRIVER}/bind" > /dev/null
echo "Périphérique USB lié avec succès au nouveau pilote"

View file

@ -1,53 +0,0 @@
#include <linux/init.h>
#include <linux/usb.h>
#include <linux/module.h>
#define USB_VENDOR_ID_CORSAIR 0x1b1c
#define USB_DEVICE_ID_LIGHTNING_NODE_PRO 0x0c0b
static int lnp_driver_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
pr_info("Détection USB pour Lightning Node Pro\n");
return 0;
}
static struct usb_device_id lnp_driver_table[] = {
{ USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_LIGHTNING_NODE_PRO) },
{} /* Entrée de terminaison */
};
MODULE_DEVICE_TABLE(usb, lnp_driver_table);
static struct usb_driver lnp_driver = {
.name = "lightning-node-pro",
.id_table = lnp_driver_table,
.probe = lnp_driver_probe,
};
static int __init lnp_usb_driver_init(void)
{
int ret;
ret = usb_register(&lnp_driver);
if (ret < 0) {
pr_err("lnp_usb_driver: Impossible d'enregistrer le pilote pour %s. Code d'erreur: %d\n",
lnp_driver.name, ret);
return -1;
}
return 0;
}
static void __exit lnp_usb_driver_exit(void)
{
usb_deregister(&lnp_driver);
}
module_init(lnp_usb_driver_init);
module_exit(lnp_usb_driver_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau pour utiliser le Lightning Node Pro LED");
MODULE_VERSION("1.0");

View file

@ -18,7 +18,14 @@ On other distros:
2. With nix only, use `nix develop .#other`
3. Otherwise, you need to setup LINUX_MODULES_FOLDER to linux modules folder of your distro (ex: `/lib/modules/$(uname -r)`) in your shell (ex: .bashrc)
3. Otherwise, you need `kernel-devel` to compile C code and `rust rust-src bindgen-cli rustfmt clippy` to compile rust
And also to setup LINUX_MODULES_FOLDER to linux modules folder of your distro (ex: `/lib/modules/$(uname -r)`) in your shell (ex: .bashrc)
### Note for Rust
`cat /boot/config-$(uname -r) | grep CONFIG_RUST`
Must contains CONFIG_RUST=y
## make : targets list
@ -55,6 +62,7 @@ sudo rmmod [module_name].ko
- https://elixir.bootlin.com/linux/v6.13/source/
- https://static.lwn.net/images/pdf/LDD3/ch01.pdf
- https://sysprog21.github.io/lkmpg
- https://github.com/Rust-for-Linux/rust-out-of-tree-module
## Notes

4
flake.lock generated
View file

@ -21,8 +21,8 @@
"nixpkgs": {
"locked": {
"lastModified": 0,
"narHash": "sha256-+/bYK3DbPxMIvSL4zArkMX0LQvS7rzBKXnDXLfKyRVc=",
"path": "/nix/store/brjzz8wv5k09bq0yrvhc1j4hd8677k21-source",
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
"path": "/nix/store/593xvgv994xlkm5mb7w4p1xxnzrs9wv6-source",
"type": "path"
},
"original": {

View file

@ -17,6 +17,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau qui affiche un message");
MODULE_VERSION("1.0");

View file

@ -50,6 +50,6 @@ module_init(module_params_init);
module_exit(module_params_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau avec paramètre déchargé.");
MODULE_VERSION("1.0");

View file

@ -87,6 +87,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau avec un périphérique de caractère");
MODULE_VERSION("1.0");

View file

@ -33,6 +33,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau qui affiche les processus en cours");
MODULE_VERSION("1.0");

View file

@ -44,6 +44,6 @@ module_init(packet_filter_init);
module_exit(packet_filter_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau pour filtrer les paquets réseau");
MODULE_VERSION("1.0");

View file

@ -53,6 +53,6 @@ module_init(virtual_led_init);
module_exit(virtual_led_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau qui ajoute une LED virtuelle");
MODULE_VERSION("1.0");

View file

@ -93,6 +93,6 @@ module_init(virtual_led_init);
module_exit(virtual_led_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Florian RICHER");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau qui ajoute des LEDs virtuelles");
MODULE_VERSION("1.0");

View file

@ -5,3 +5,6 @@ all:
clean:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) clean
rust-analyzer:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) rust-analyzer

View file

@ -0,0 +1,25 @@
use kernel::prelude::*;
module! {
type: RustOutOfTree,
name: "test_module",
author: "Florian RICHER <florian.richer@protonmail.com>",
description: "Un module noyau qui affiche un message",
license: "GPL",
}
struct RustOutOfTree;
impl kernel::Module for RustOutOfTree {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Bonjour! Le module est chargé.\n");
Ok(RustOutOfTree)
}
}
impl Drop for RustOutOfTree {
fn drop(&mut self) {
pr_info!("Au revoir! Le module est déchargé.\n");
}
}