Skip to content

Commit 398f587

Browse files
committed
Add first version of the hello world module.
Signed-off-by: Matthias Brugger <[email protected]>
1 parent 43fb760 commit 398f587

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
obj-m := hello-world.o
2+
3+
PWD := $(shell pwd)
4+
5+
all:
6+
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
7+
8+
clean:
9+
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is a small hello world kernel modules.
2+
3+
You will need to download the kernel source code to compile the module against. Beware that if you want to load the module on your local machine, you will need to compile it against the kernel source of your installed kernel. In openSUSE you can do that by installing the kernel-devel package:
4+
5+
sudo zypper in kernel-devel
6+
7+
You must export the KERNELDIR accordingly to be able to compile the module against it.
8+
9+
Good luck!

hello-world.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* hello_world demonstration.
3+
*
4+
* Copyright (C) 2019 Matthias Brugger
5+
*
6+
* The source code in this file can be freely used, adapted,
7+
* and redistributed in source or binary form, so long as an
8+
* acknowledgment appears in derived source files. The citation
9+
* should list that the code comes from the book "Linux Device
10+
* Drivers" by Alessandro Rubini and Jonathan Corbet, published
11+
* by O'Reilly & Associates. No warranty is attached;
12+
* we cannot take responsibility for errors or fitness for use.
13+
*/
14+
15+
#include <linux/module.h>
16+
//#include <linux/moduleparam.h>
17+
//#include <linux/init.h>
18+
19+
#include <linux/kernel.h> /* printk() */
20+
21+
MODULE_AUTHOR("Matthias Brugger");
22+
MODULE_LICENSE("GPL2");
23+
24+
25+
/*
26+
* Module housekeeping.
27+
*/
28+
static int hello_world_init(void)
29+
{
30+
printk(KERN_WARNING "hello_world\n");
31+
return 0;
32+
}
33+
34+
35+
static void hello_world_cleanup(void)
36+
{
37+
}
38+
39+
module_init(hello_world_init);
40+
module_exit(hello_world_cleanup);

0 commit comments

Comments
 (0)