Linux kernel: Difference between revisions
imported>Makefu Created page with "== Configuring the Linux Kernel == see [https://nixos.org/nixos/manual/index.html#sec-kernel-config NixOS Manual "Linux Kernel"]. == Developing Kernel Modules == see [https:/..." |
imported>Mic92 out-of-tree kernel modules |
||
Line 4: | Line 4: | ||
== Developing Kernel Modules == | == Developing Kernel Modules == | ||
see [https://nixos.org/nixos/manual/index.html#idm140737316413584 NixOS Manual "Developing kernel modules"] | see [https://nixos.org/nixos/manual/index.html#idm140737316413584 NixOS Manual "Developing kernel modules"] | ||
If you work on an out-of-tree kernel module the workflow could look as follow: | |||
<syntaxHighlight lang="C"> | |||
#include <linux/module.h> | |||
#define MODULE_NAME "hello" | |||
static int __init hello_init(void) | |||
{ | |||
printk(KERN_INFO "hello world!"); | |||
return 0; | |||
} | |||
static void __exit hello_cleanup(void) {} | |||
module_init(hello_init); | |||
module_exit(hello_cleanup); | |||
</syntaxHighlight> | |||
<syntaxHighlight lang="console> | |||
$ nix-shell '<nixpkgs>' -A linux.dev | |||
$ make -C $(nix-build -E '(import <nixpkgs> {}).linux.dev' --no-out-link)/lib/modules/*/build M=$(pwd) modules | |||
$ insmod ./hello.ko | |||
$ dmesg | grep hello | |||
[ 82.027229] hello world! | |||
</syntaxHighlight> | |||
== make menuconfig == | == make menuconfig == |