简单字符设备驱动编写,可传参,在内核之外编译
2014-09-16 18:51
295 查看
驱动程序:hello.c
Makefile:Makefile
make之后把hello.ko 通过网线tftp下载到开发板上,通过下面命令运行(带参数):
insmod hello.ko whom=Students howmany=5
#include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Hanson He"); static char *whom = "world"; static int howmany = 5; static int hello_init(void) { int i; for(i=0;i<howmany;i++) { printk(KERN_ALERT "Hello %s\n",whom); } return 0; } static void hello_exit(void) { printk(KERN_ALERT " Hello world exit\n"); } module_init(hello_init); module_exit(hello_exit); module_param(howmany, int, S_IRUGO);//参数名,参数类型,参数读/写权限 module_param(whom, charp, S_IRUGO); EXPORT_SYMBOL(howmany); EXPORT_SYMBOL(whom);
Makefile:Makefile
ifeq ($(KERNELRELEASE),) KERNELDIR ?=/home/user/kernel #内核所在目录 #当前Makefile所在目录 PWD := $(shell pwd) # -C $(KERNELDIR)指明跳转到内核源码目录下读取那里的Makefile # M=$(PWD) 表明然后返回到当前目录继续读入、执行当前的Makefile modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions .PHONY: modules modules_install clean else obj-m := hello.o endifMakefile相关解释,点击打开链接
make之后把hello.ko 通过网线tftp下载到开发板上,通过下面命令运行(带参数):
insmod hello.ko whom=Students howmany=5
相关文章推荐
- 简单的LINUX字符设备驱动及编译进Linux内核…
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- Linux内核开发之简单字符设备驱动(下)
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- Linux2.6内核下简单的字符设备驱动及测试
- tony之linux driver_LDD3_scull字符设备驱动编译在新内核编译问题
- 利用linux 内核所提供的input子系统编写字符设备驱动的步骤
- Linux内核开发之简单字符设备驱动(下)
- 编写字符设备驱动实现内核态与用户态通信
- 代码:编写一个简单的字符设备驱动
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- 简单的LINUX字符设备驱动及编译进Linux内核
- Linux 字符设备驱动开发基础(一)—— 编写简单 LED 设备驱动
- [linux设备驱动程序]scull字符设备驱动编译在新内核编译问题解决方案
- __register_chrdev_region分析(简单字符设备驱动在内核的工作原理)
- 简单字符设备驱动的编写
- 在编写最简单的linux 内核驱动, 编译后出现的问题以及解决方法。
- [设备驱动] 最简单的内核设备驱动--字符驱动
- Linux 字符设备驱动开发基础(一)—— 编写简单 LED 设备驱动
- Linux 字符设备驱动开发基础(一)—— 编写简单 LED 设备驱动