A memo about building and loading the kernel module
You can get a stacktrace with dump_stack ()
.
testmod.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
MODULE_LICENSE("MIT");
static int testmod_init(void)
{
printk(KERN_INFO "driver loaded\n");
dump_stack();
return 0;
}
static void testmod_exit(void)
{
printk(KERN_INFO "driver unloaded\n");
}
module_init(testmod_init);
module_exit(testmod_exit);
Makefile
KERNELSRCDIR = /lib/modules/$(shell uname -r)/build
ARCH=x86
#ARCH=arm
#CROSS_COMPILE=arm-none-linux-gnueabi-
VERBOSE = 0
obj-m := testmod.o
all:
make -C $(KERNELSRCDIR) \
M=$(PWD) \
KBUILD_VERBOSE=$(VERBOSE) \
ARCH=$(ARCH) \
CROSS_COMPILE=$(CROSS_COMPILE) \
modules
clean:
make -C $(KERNELSRCDIR) M=$(PWD) KBUILD_VERBOSE=$(VERBOSE) ARCH=$(ARCH) clean
important point:
Makefile
instead of makefile
Check the operation by insmod
$ make
$ sudo insmod testmod.ko
$ sudo rmmod testmod
$ dmesg
[20487.308696] testmod: module license 'MIT' taints kernel.
[20487.308709] Disabling lock debugging due to kernel taint
[20487.310110] driver loaded
[20487.310116] Pid: 32263, comm: insmod Tainted: P O XXXXX.x86_64 #1
[20487.310121] Call Trace:
[20487.310130] [<ffffffffa00f8000>] ? 0xffffffffa00f7fff
[20487.310138] [<ffffffffa00f801c>] testmod_init+0x1c/0x20 [testmod]
[20487.310146] [<ffffffff8100212a>] do_one_initcall+0x12a/0x180
[20487.310213] [<ffffffff810b60a6>] sys_init_module+0x10f6/0x20b0
[20487.310220] [<ffffffff815f38e9>] system_call_fastpath+0x16/0x1b
[20487.383930] driver unloaded
Summary of how to check kernel module information --Qiita [Linux] [kernel module] How to pass parameters as arguments when loading a loadable kernel module --Qiita [Linux] [kernel module] Create kthread in kernel module --Qiita
Compiling Kernel Modules Creating a Linux kernel module for ARM-seriously makefile - Cross compiling a kernel module - Stack Overflow
Recommended Posts