简单的内核驱动
helloworld.c-------------------------------------------------------------------------------------------------
#include #include MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_INFO " Hello World enter\n");//打印级别+打印信息 return 0; } static void hello_exit(void) { printk(KERN_INFO " Hello World exit\n");//打印级别+打印信息 } //安装模块做什么 module_init(hello_init); //卸载模块做什么 module_exit(hello_exit); //模块信息 MODULE_AUTHOR("ephraim"); MODULE_DESCRIPTION("A simple Hello World Module"); MODULE_ALIAS("a simplest module");-------------------------------------------------------------------------------------------------
Makefile-------------------------------------------------------------------------------------------------
ifneq ($(KERNELRELEASE),) #kbuild syntax. dependency relationshsip of files and target modules are listed here. obj-m := helloworld.o else PWD:= $(shell pwd) KDIR := /home/lzq/desktop/linux-5.10 all: $(MAKE) -C $(KDIR) M=$(PWD) modules clean: rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions endif-------------------------------------------------------------------------------------------------make一下生成helloworld.ko结果