《Linux设备驱动程序》 笔记2

驱动代码hello.c

#include <linux/init.h>
#include <linux/module.h>

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内容

文件名必须保存为Makefile,开头大写!

ifneq ($(KERNELRELEASE),) 
obj-m := hello.o

else
PWD  := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
	rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif  
posted @ 2015-02-19 21:05  catmelo  阅读(148)  评论(0编辑  收藏  举报