为什么在加载时此内核模块不执行任何操作?
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#define DEVICE_NAME "hello-1.00.a"
#define DRIVER_NAME "hello"
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(struct platform_device *pdev){
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static int hello_exit(struct platform_device *pdev){
printk(KERN_ALERT "Goodbye, cruel world\n");
return 0;
}
static const struct of_device_id myled_of_match[] =
{
{.compatible = DEVICE_NAME},
{},
};
MODULE_DEVICE_TABLE(of, myled_of_match);
static struct platform_driver hello_driver =
{
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = myled_of_match
},
.probe = hello_init,
.remove = hello_exit
};
module_platform_driver(hello_driver);
它必须print Hello, world\n
,如果我这样做lsmod
该模块似乎已加载:
lsmod
hello_world 1538 0 - Live 0xbf000000 (O)
但是在控制台和dmesg
。
如果我使用module_init
并且module_exit
一切正常,但是我需要指向platform_device *pdev
设备的指针,该怎么办?
编辑:
原始模块如下所示:
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void){
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
在我的设备树blob中显示以下条目:
hello {
compatible = "dglnt,hello-1.00.a";
reg = <0x41220000 0x10000>;
};
如果我使用module_init和module_exit都可以
简短的“原始”代码仅包含模块框架。确保在加载模块时调用init例程,并在卸载前调用exit例程。该“原始”代码不是驱动程序。
较长的内核模块是驱动程序,正在加载,但是由于它具有不执行任何操作的默认初始化和退出代码(由module_platform_driver()宏的扩展生成),因此没有消息。当内核使用设备树时,不能保证可加载模块中的驱动程序代码被调用。
为什么在加载时此内核模块不执行任何操作?
驱动程序的探测功能(将输出消息)可能未得到调用,因为设备树中没有任何内容指示需要此设备驱动程序。
开发板的“设备树”的代码段包含
compatible = "dglnt,hello-1.00.a";
但驱动程序声明应将其指定为
#define DEVICE_NAME "hello-1.00.a"
...
{.compatible = DEVICE_NAME},
这些字符串应匹配,以便驱动程序可以与“设备树”节点中的此引用设备绑定。
此外,设备节点应声明为
status = "okay";
覆盖任何可能禁用设备的默认状态。
设备树中正确配置的节点应可以按预期执行驱动程序的探测功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句