linux device driver Makfile
来源:互联网 发布:golang 1.9 java比较 编辑:程序博客网 时间:2024/06/05 17:59
在PC机上编译适合本PC机kernel的单个模块的Makefile很容易写,在PC机上编译android内核的某个模块却有些不同:主要是指定内核和交叉编译工具的路径。具体如下:
Makefile 内容
ifneq ($(KERNELRELEASE), ) mymodule-objs := helloworld.o obj-m := helloworld.oelse PWD:=$(shell pwd) KERNEL_DIR ?=$(ANDROID_PRODUCT_OUT)/obj/KERNEL_OBJ/ CROSS_COMPILE=$(ARM_EABI_TOOLCHAIN) PWD:=$(shell pwd)all: make ARCH=arm $(CROSS_COMPILE) -C $(KERNEL_DIR) M=$(PWD) modulesclean: rm -rf *.o modules.order *.ko Module.symversendif
对应的helloworld.c 如下
helloworld.c
#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>static int __init hellokernel_init(void){ printk(KERN_INFO "Hello, kernel!\n"); return 0;}static void __exit hellokernel_exit(void){ printk(KERN_INFO "Goodbye, kernel!\n");}module_init(hellokernel_init);module_exit(hellokernel_exit);MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR("XXX");MODULE_DESCRIPTION("Test only");
运行时先在项目文件目录下运行
$ source build/envsetup.sh
和
$ lunch
选择编译项目选项 导入一些符号定义,最后即可运行mak执行本Makefile
$ make
生成的helloworld.ko 即是适合android 内核的文件,即可用insmod rmmod 将模块加入目标板的内核或从内去除。
另:如果将Makefile中的符号替换成对应的内容,即直接指定KERNEL_DIR和CROSS_COMPILE在android代码中的路径,则无需执行source 和lunch命令即可在任意标签页直接运行make 命令生成目标文件,对应的Makfile文件如下:
Makefile 内容:
mymodule-objs := helloworld.oobj-m := helloworld.oPWD:=$(shell pwd)KERNEL_DIR=android_src_path/out/target/product/T37lchaudi/obj/KERNEL_OBJ/CROSS_COMPILE=android_src_path/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/binPWD:=$(shell pwd)all: make ARCH=arm $(CROSS_COMPILE) -C $(KERNEL_DIR) M=$(PWD) modulesclean: rm -rf *.o modules.order *.ko Module.symvers
其中android_src_path为anroid项目所在的目录。
PC OS verison:Ubuntu 12.04.2 LTS, kernel version:3.5.0-27-generic
目标板kernel version:3.0.50
- linux device driver Makfile
- Linux Device Driver: char device
- linux device driver
- Linux device driver
- Linux device driver
- Linux Device Driver
- Linux Device Driver Summarization
- Linux device driver
- linux device driver
- Linux Device Driver ---USB
- Linux Audio Device Driver
- linux bus driver device
- Linux I2C device driver
- Linux Audio Device Driver
- Linux makfile
- Writing a Linux device driver
- Writing a Linux device driver
- Linux Platform Device and Driver
- 利用超链接调用javascript函数
- CodeRush使用教程十四:Target Picker
- cannot exec `cpp0': No such file or directory
- 让你提升命令行效率的Bash 快捷键
- 求助
- linux device driver Makfile
- pthread_exit(void *retval)
- CodeRush使用教程十五:代码修复提示
- 使用不同用户名启动husdon时出现的问题
- Menu由两种形式
- MongoDB数据库和集合的状态信息
- JAVA序列化在IO中读写对象的使用
- CodeRush使用教程十六:解码器(Decompiler)
- 字符串处理转换