#include <linux/module.h>
#include <linux/init.h>
static int __init helloworld_init(void) {
pr_info("Hello world initialization!\n");
return 0;
}
static void __exit helloworld_exit(void) {
pr_info("Hello world exit\n");
}
module_init(helloworld_init);
module_exit(helloworld_exit);
MODULE_LICENSE("GPL"); // GPL (General Public License)
MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
MODULE_DESCRIPTION("Linux kernel module skeleton");
模块骨架代码
模块加载:modprobe or insmod 卸载:rmmod or modprobe -r
MODULE_INFO(my_field_name, "What easy value");
kbuild Kconfig Makefile
内核模块构建命令模式类似于如下: make -C $KERNEL_SRC M=$(shellpwd)[目标]
Makefile:
# kbuild part of makefile
obj-m := helloworld.o
#the following is just an example
#ldflags-y := -T foo_sections.lds
# normal makefile
KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
all default: modules
install: modules_install
modules modules_install help clean:
$(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) $@
报错 Makefile:10: *** missing separator. Stop. 第十行命令必须以tab键开头,解决
Out-of-tree module cross-compiling
https://blog.csdn.net/Tdh5258/article/details/108501265 可以参考!