No description
Find a file
2025-02-25 21:31:17 +01:00
.vscode vscode: Add recommended extensions + add autoformat on save 2025-02-25 13:41:42 +01:00
01_basic_module Run clang-format 2025-02-25 13:32:53 +01:00
02_module_params Run clang-format 2025-02-25 13:32:53 +01:00
03_character_device Run clang-format 2025-02-25 13:32:53 +01:00
04_process_monitor Run clang-format 2025-02-25 13:32:53 +01:00
05_packet_filter Run clang-format 2025-02-25 13:32:53 +01:00
06_virtual_led_basic Run clang-format 2025-02-25 13:32:53 +01:00
07_virtual_leds_more_complex Run clang-format 2025-02-25 13:32:53 +01:00
08_gpio_pin_rpi3 Run clang-format 2025-02-25 13:32:53 +01:00
09_gpio_led_rpi3 Run clang-format 2025-02-25 13:32:53 +01:00
10_lnp_usb_driver Begin add usb driver 2025-02-25 21:31:17 +01:00
.clang-format Run clang-format 2025-02-25 13:32:53 +01:00
.envrc fix bad shell 2025-02-23 12:42:11 +01:00
.gitignore Begin add usb driver 2025-02-25 21:31:17 +01:00
flake.lock [Can be unstable] Try use nixpkgs of the systems 2025-02-17 21:09:57 +01:00
flake.nix Run clang-format 2025-02-25 13:32:53 +01:00
README.md Run clang-format 2025-02-25 13:32:53 +01:00

Setup env

On NixOS:

  • Ensure Linux Kernel is the same as you configuration. Use this command to update nix inputs
nix flake update --override-input nixpkgs "github:NixOS/nixpkgs/$(nixos-version --revision)"
  • Use direnv allow or nix develop to setup shell.

On other distros:

  1. With direnv, in .envrc, change line by use flake .#other

  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)

make : targets list

  • all : Compiling kernel (by default)
  • clean : Cleaning build folder

All subfolder is configured to use LINUX_MODULES_FOLDER env variable set by flake develop

How test module

Step 1: Load module

sudo insmod [module_name].ko

Warning: Can fail if secure boot is enabled (see notes about secure boot in below)

Step 2: Check logs

sudo dmesg | tail

Step 3: Unload module

sudo rmmod [module_name].ko

Notes

Find required headers files

nix shell nixpkgs#bear
cd 01_basic_module/
bear --append --output ../.vscode/compile_commands.json -- make -C $LINUX_MODULES_FOLDER/build M=$PWD modules

Search -I args and -D args

Sign kernel module for testing with secure boot enabled

Prerequisites: Own secure boot keys configured.

Secure boot keys can be found in :

  • Fedora : /etc/pki/akmods
  • With sbctl : /var/lib/sbctl
sign-file sha256 $SECUREBOOT_KEYS_PATH/private_key.priv $SECUREBOOT_KEYS_PATH/public_key.der <module_file>.ko

sign-file executable is in /usr/src/kernels/$(uname -r)/scripts

Full example (run as root):

  1. Fedora
/usr/src/kernels/$(uname -r)/scripts/sign-file sha256 /etc/pki/akmods/private/private_key.priv /etc/pki/akmods/certs/public_key.der <module_file>.ko

Format

  1. .clang-format

How update .clang-format

curl https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/.clang-format -o .clang-format

Format files

clang-format -i **/*.c