Linux嵌入式简单驱动设计

1、环境搭建

vmware+Fedora

2、创建一个Hello文件

mkdir Hello

 

3、在Hello里面创建 hello.c 和 Makefile 两个文本文件

(1):创建hello.c

vim hello.c

hello.c:

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

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{  
        printk(KERN_EMERG "hello module!\n");
        return 0;
}   

static void hello_exit(void)  
{  
        printk(KERN_EMERG "bye module!\n");
}  
module_init(hello_init);
module_exit(hello_exit);

 (2):创建Makefile

vim Makefile

Makefile:

obj-m := hello.o  
KERNEL_DIR := /lib/modules/$(shell uname -r)/build  
PWD := $(shell pwd)  
all:  
  make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules  
clean:  
  rm *.o *.ko *.mod.c  
       
.PHONY:clean

 

猜你喜欢

转载自www.cnblogs.com/chuijingjing/p/9218259.html