driver makefile
2016-06-09 22:42
176 查看
1、单模块单文件
//*********************************************
obj-m := hello.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
all:
make -C $(KDIR) SUBDIRS=$(PWD) mudules
.PHONY:clean
clean:
-rm -rf *.o *.ko *~ *.mod.*
//*********************************************
2、单模块多文件
//*********************************************
obj-m := myhello.o
myhello-objs := hello.o goo.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
(其他同上)
//*********************************************
hello.c可直接调用goo.c中的函数,只需在hello.c中声明即可。
3、多模块
//*********************************************
obj-m := hello.o goo.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
(其他同上)
//*********************************************
注:其中,goo.c需要导出符号表,EXPORT_SYMBOL(goo),
供hello.c调用。
注:在编译模块前,linux源码包(或头文件包)必须经过正确编译,可提供导出符号表。
安装头文件包:
sudo apt-get install linux-headers-2.6.32-21-generic
sudo apt-get install linux-source-2.6.32
===================================================================
//*********************************************
obj-m := hello.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
all:
make -C $(KDIR) SUBDIRS=$(PWD) mudules
.PHONY:clean
clean:
-rm -rf *.o *.ko *~ *.mod.*
//*********************************************
2、单模块多文件
//*********************************************
obj-m := myhello.o
myhello-objs := hello.o goo.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
(其他同上)
//*********************************************
hello.c可直接调用goo.c中的函数,只需在hello.c中声明即可。
3、多模块
//*********************************************
obj-m := hello.o goo.o
KDIR := /home/akaedu/kernel/linux-2.6.35.7
(其他同上)
//*********************************************
注:其中,goo.c需要导出符号表,EXPORT_SYMBOL(goo),
供hello.c调用。
注:在编译模块前,linux源码包(或头文件包)必须经过正确编译,可提供导出符号表。
安装头文件包:
sudo apt-get install linux-headers-2.6.32-21-generic
sudo apt-get install linux-source-2.6.32
===================================================================
#include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); char *who = “world”; static int hello_init ( void ) { printk(KERN_ALERT “Hello, %s!\n”, who); return 0; } static void hello_exit ( void ) { printk(KERN_ALERT “Goodbye, %s!\n”, who); } module_init(hello_init); module_exit(heool_exit); //makefile ifeq ($(KERNELRELEASE), ) obj-m :=hello.o else KERNELDIR ?= /home/mike/linux-2.6.20 PWD := $(shell pwd) default: $(MAKE) –C $(KERNELDIR) M=$(PWD) modules clean: rm –rf *.o *~ core.depend .*.cmd *.ko *.mod.c endif //注意核对目标平台和交叉编译器: ARCH ?= arm CROSS_COMPILE ?= arm-linux-
相关文章推荐
- NYOJ 1070 诡异的电梯【Ⅰ】
- 百度贴吧_爬虫
- 入门java script
- 安装RedHat教程
- 113. Path Sum II
- 使用RAII来管理对象资源
- 设计模式——设计模式之禅的阅读笔记
- Docker import error:Error: open /tmp/docker-import-123456789/repo/bin/json: no such file or directory
- 大型网站架构系列:分布式消息队列
- leetcode 17. Letter Combinations of a Phone Number
- String类部分函数详解
- ubuntu16LTS下现代五笔的使用
- C++ const
- 112. Path Sum
- 文件压缩与解压
- jQuery实现<textarea>高度自适应,适用于td中的textarea
- iOS 限制输入字数完美解决方案
- 111. Minimum Depth of Binary Tree
- Java序列化与反序列化
- 深入理解CSS中的定位(position)