正在使用linux的ramoops驱动器模块,当编译完成加载。查找驱动程序加载失败。显然,直接用内核代码,为什么会出现这种情况?

第一眼ramoops初始化代码:

180 static int __init ramoops_init(void)
181 {
182 return platform_driver_probe(&ramoops_driver, ramoops_probe);
183 }
184
185 static void __exit ramoops_exit(void)
186 {
187 platform_driver_unregister(&ramoops_driver);
188 }
189
190 module_init(ramoops_init);

180行開始的ramoops_init函数是不是有点奇怪?直接就调用了probe函数。标准的platform驱动程序的流程是这种:

怎么看起来好像缺少platform_device的定义和注冊。究竟是不是由于这个呢?我们来看一下Document/ramoops.txt的相关说明:

 38 2. Setting the parameters
39
40 Setting the ramoops parameters can be done in 2 different manners:
41 1. Use the module parameters (which have the names of the variables described
42 as before).
43 For quick debugging, you can also reserve parts of memory during boot
44 and then use the reserved memory for ramoops. For example, assuming a machine
45 with > 128 MB of memory, the following kernel command line will tell the
46 kernel to use only the first 128 MB of memory, and place ECC-protected ramoops
47 region at 128 MB boundary:
48 "mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1"
49 2. Use a platform device and set the platform data. The parameters can then
50 be set through that platform data. An example of doing that is:
51
52 #include <linux/pstore_ram.h>
53 [...]
54
55 static struct ramoops_platform_data ramoops_data = {
56 .mem_size = <...>,
57 .mem_address = <...>,
58 .record_size = <...>,
59 .dump_oops = <...>,
60 .ecc = <...>,
61 };
62
63 static struct platform_device ramoops_dev = {
64 .name = "ramoops",
65 .dev = {
66 .platform_data = &ramoops_data,
67 },
68 };
69
70 [... inside a function ...]
71 int ret;
72
73 ret = platform_device_register(&ramoops_dev);
74 if (ret) {
75 printk(KERN_ERR "unable to register platform device\n");
76 return ret;
77 }

原来真的是由于少了platform_device的缘故,赶紧加上。

追加platform_device的操作比較简单,依照Document上的来就能够了。

有一点须要主要。就是ramoops_dev的name这个成员。这个成员的值必须是"ramoops"。为什么呢?这是由于platform总线在调用自身的match函数,将driver与device进行匹配时,就是推断两个结构体中的name成员是否相等。

而platform_driver结构体中的name成员的值,从以下的代码中能够看出,已经写定为"ramoops"。假设platform_device中的值不同,则驱动相同无法载入。

172 static struct platform_driver ramoops_driver = {
173 .remove = __exit_p(ramoops_remove),
174 .driver = {
175 .name = "ramoops",
176 .owner = THIS_MODULE,
177 },
178 };

有没有想过,为什么没注冊platform_device,ramoops的驱动代码就不能载入呢?再回过头来看一下ramoops的初始化代码:

180 static int __init ramoops_init(void)
181 {
182 return platform_driver_probe(&ramoops_driver, ramoops_probe);
183 }

之前说过,一般init函数中会调用register函数,还说这是标准流程了呢。看一下platform_driver_probe函数的定义:

 477 int __init_or_module platform_driver_probe(struct platform_driver *drv,
478 int (*probe)(struct platform_device *))
479 {
480 int retval, code;
481
482 /* make sure driver won't have bind/unbind attributes */
483 drv->driver.suppress_bind_attrs = true;
484
485 /* temporary section violation during probe() */
486 drv->probe = probe;
487 retval = code = platform_driver_register(drv);
488
。 。 。 }

看到platform_driver_register函数没?原来是将register函数封装了一层。

看到这里应该明确了,为什么没有注冊platform_device。驱动会载入失败了吧。

什么,还是不知道?那你一定没看我之前写的关于linux设备驱动程序的注冊流程。假设看完了还没明确,那就是我的问题。链接在此:http://blog.csdn.net/tuzhutuzhu/article/details/34847619

版权声明:本文博主原创文章,博客,未经同意不得转载。

最新文章

  1. 6.SpringMVC注解启用
  2. UVA-11297 Census(线段树套线段树)
  3. SU supef命令学习
  4. JAVA开发--游戏24点
  5. jni.h头文件详解一
  6. struts2总结【转载】
  7. IDEA第一章----下载安装idea,设置背景字体编码,配置JDK/Maven
  8. public/private/protected的具体区别
  9. leetcode 678. Valid Parenthesis String
  10. 简化版的AXI-LITE4和配合使用的RTL
  11. 自己动手,丰衣足食!Python3网络爬虫实战案例
  12. centos7 Firewalld操作集合
  13. windows下mysql5.7 root密码重置
  14. NC入门笔记
  15. php各种主流框架的优缺点
  16. IE6下面的css调试工具
  17. Maven 逆向工程
  18. 反编译apk + eclipse中调试smali
  19. [Python 3.X]python练习笔记[2]-----用python实现七段数码管显示年月日
  20. [转] LINUX 三种网络连接模式

热门文章

  1. PPTP和L2TP的区别
  2. centos6搭建本地openstack软件源
  3. [ACM] POJ 3259 Wormholes (bellman-ford最短路径,推断是否存在负权回路)
  4. Android于fragment_main.xml文件问题组件收购
  5. 每日算法之三十三:Trapping Rain Water
  6. android client随机验证码生成函数
  7. [Unity3D]Unity4全新的动画系统Mecanim
  8. Ubuntu Linux 永山(mount)分
  9. 王立平--android发育,转让eclipse可选颜色
  10. JAVA程序生成XML标准化的文件格式,缩进,美化。