Kernel Modul erstellen: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „=Module Quellcode hello.c= <pre> #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> static int __init hello_init(void) { printk(K…“)
 
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
=Vorbereitung=
 +
*Linux Header installieren
 +
*apt install gcc make linux-headers-$(uname -r)
 +
 
=Module Quellcode hello.c=
 
=Module Quellcode hello.c=
 
<pre>
 
<pre>
Zeile 17: Zeile 21:
 
module_exit(hello_exit);
 
module_exit(hello_exit);
  
MODULE_LICE/NSE("GPL");
+
MODULE_LICENSE("GPL");
 
MODULE_DESCRIPTION("A simple Hello World module");
 
MODULE_DESCRIPTION("A simple Hello World module");
 
MODULE_AUTHOR("Your Name");
 
MODULE_AUTHOR("Your Name");
 
</pre>
 
</pre>
 +
 
=Makefile=
 
=Makefile=
 
<pre>
 
<pre>

Aktuelle Version vom 18. Juli 2024, 13:34 Uhr

Vorbereitung

  • Linux Header installieren
  • apt install gcc make linux-headers-$(uname -r)

Module Quellcode hello.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int __init hello_init(void) {
    printk(KERN_INFO "Hello, World!\n");
    return 0;
}

static void __exit hello_exit(void) {
    printk(KERN_INFO "Goodbye, World!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A simple Hello World module");
MODULE_AUTHOR("Your Name");

Makefile

obj-m += hello.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Kompilierung

  • make

Laden

  • insmod hello

Entladen

  • rmmod hello