#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
內(nèi)核模塊構建命令模式類似于如下: 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? ? 可以參考!