【shell】从文件中读取参数传给驱动模块
来源:互联网 发布:申根签证截止日期 知乎 编辑:程序博客网 时间:2024/05/16 17:41
1.1 Shell脚本从文件中读取参数传给驱动模块
问题描述:insmod驱动模块需要几个参数,不过这几个参数需要从配置文件中读取,为了开机时自动化处理还需要把这些操作都放在一个脚本中。
下面是一个helloworld驱动的demo,这个demo需要两个参数: char * people 和 int num
1.2 hello.c
- root@ubuntu:~/test/shreadf# cat hello.c
- #include
- #include
- MODULE_LICENSE("Dual BSD/GPL");
- static char * people= "wang";
- static int num= 1;
- static int hello_init(void)
- {
- printk(KERN_ALERT"num=%d people=%s\n", num, people);
- return 0;
- }
- static void hello_exit(void)
- {
- printk(KERN_ALERT"Hello world exit\n");
- }
- module_init(hello_init);
- module_exit(hello_exit);
- module_param(num, int, S_IRUGO);
- module_param(people, charp, S_IRUGO);
- EXPORT_SYMBOL(num);
- EXPORT_SYMBOL(people);
1.3 Makefile
- root@ubuntu:~/test/shreadf# cat Makefile
- ifneq ($(KERNELRELEASE),)
- obj-m:=hello.o
- else
- KDIR =/lib/modules/$(shell uname -r)/build
- PWD:=$(shell pwd)
- default:
- $(MAKE) -C $(KDIR) M=$(PWD) modules
这个驱动需要的参数在 text.txt中,
root@ubuntu:~/test/shreadf# cat test.txt
1234
abcdefg
第一行是参数num, 第二行是参数people
1.4 测试
编写好后测试一下驱动有没有问题:
root@ubuntu:~/test/shreadf# insmod hello.ko num=1 people=" zhangsan"
root@ubuntu:~/test/shreadf# dmesg | tail
[34398.230034] num=1 people=zhangsan
shell脚本中读取参数用sed 就好了。
但是在给int 型的num传参数时直接用 num=$num时会报错,但是加expr就成功了。
虽然这个脚本可以用了,但是还不是特别理解,个人感觉这个表达表就跟shell中做四则运算时都要加expr一样,这个地方为了类型匹配也需要加expr。
1.5 脚本
- root@ubuntu:~/test/shreadf# cat shread.sh
- #!/bin/sh
- num=$( sed -n '1p' test.txt )
- people=$( sed -n '2p' test.txt )
- echo "num=$num"
- echo "people=$people"
- #insmod hello.ko num=1 people=" zhangsan"
- insmod hello.ko num=`expr $num` people=$people
0 0
- 【shell】从文件中读取参数传给驱动模块
- shell 从文件中一行一行地读取
- C++ sstream 从文件中读取参数
- shell之用while从文件中读取数据
- 驱动中读取文件
- 用java程序从propeties文件中读取参数值
- Jmeter 从csv文件中读取参数化数据
- MYSQL FOR循环逐行从文件中读取参数
- jmeter从文件中读取参数,并实现循环
- 从TensorFlow的.ckpt文件中读取网络的参数
- 从配置文件中读取参数
- 在Shell中读取文件
- shell从管道读取命令行并解析,双引号中有空格计算为一个参数
- JDBC | 从配置文件中读取驱动
- JDBC | 从配置文件中读取驱动 Ⅱ
- 从数据库中读取文件
- 从文件中读取矩阵
- 从文件中读取Bitmap
- H5项目常见问题及注意事项
- 文本比较工具 Beyond Compare
- RelativeLayout
- python 解析excel
- Hibernate读书笔记-----SQL查询 addScalar()或addEntity()
- 【shell】从文件中读取参数传给驱动模块
- The special grammar for PHP
- Python学习笔记2
- 在154个元素组成有序表进行二分法查找,可能的比较次数为()
- 视图合并、hash join连接列数据分布不均匀引发的惨案
- Java中使用ResponseCache类构建本地缓存
- Java中继承abstract class和interface以及继承abstract class和普通class的应用比较
- ecshop二次开发--节日关怀
- JSONArray JSONObjec