驱动程序 hello.c
##################################
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello,world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye,cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
##########################################
makefile
#######################################
obj-m := hello.o
KERNELDIR := /lib/modules/$(shell uname -r)/build
default:
make -C $(KERNELDIR) M=$(shell pwd) modules
clean:
make -C $(KERNELDIR) M=$(shell pwd) clean
install:
insmod hello.ko
uninstall:
rmmod hello.ko
clean:
make -C $(KERNELDIR) M=$(shell pwd) clean
###############################################
编译后insmod hello.ko 安装没有出错,但看不到”Hello,world“,用命令dmesg查看,可以看到,安装成功了
但rmmod hello时出错“ERROR: Removing 'hello': Device or resource busy”。。查看网上的,最大可能就是系统没有编译御载功能???(像不可能)。解答目前无果。重启后用命令 lsmod |grep hello 查看,hello驱动不存在了。动态加载驱动程序就这样,复位后就不存在。。。。