【问题标题】:Init not called during modprobe在 modprobe 期间未调用初始化
【发布时间】:2015-11-24 19:41:52
【问题描述】:

我知道驱动程序和设备必须具有相同的名称,并且我已经确定我已经这样做了。但是,当 modprobe'ing 我的驱动程序时,即使我在 init 函数中执行了许多 printk,也没有任何反应。

当 modprobing 时,我得到:

root@localhost:~# dmesg --clear
root@localhost:~# modprobe mcp3202
root@localhost:~# dmesg

[   41.828678] kobject: 'mcp3202' (bf03968c): kobject_add_internal: parent: 'module', set: 'module'
[   41.828747] kobject: 'holders' (ded9d980): kobject_add_internal: parent: 'mcp3202', set: '<NULL>'
[   41.828890] kobject: 'notes' (dd1947c0): kobject_add_internal: parent: 'mcp3202', set: '<NULL>'
[   41.829028] kobject: 'mcp3202' (bf03968c): kobject_uevent_env
[   41.829053] kobject: 'mcp3202' (bf03968c): fill_kobj_path: path = '/module/mcp3202'

root@localhost:~# 

没有 printk 出现。

我的设备和驱动结构是:

static struct platform_device mcp3202_device = {
    .name = "mcp3202",
    .id = 0,
    .num_resources = 0,
};

static strict of_device_id mcp3202_id[] = {
    { .compatible = "microchip,mcp3202", },
    { }
};

MODULE_DEVICE_TABLE(of,mcp3202_id);

static struct platform_driver mcp3202_driver = {
   .driver = {
            .name = "mcp3202",
            .owner = THIS_MODULE,
            .of_match_table = mcp3202_id,
    },
    .probe = mcp3202_probe,
    .remove = mcp3202_remove,
};

module_init(mcp3202_init);
module_exit(mcp3202_exit);

...最后,我的 init 函数(部分)...

static int __init mcp3202_init(void)
{
    int init_result;
    struct device *dev;

    printk(KERN_WARNING "mcp3202: reg driver\n");
    .
    .
    .
}

我的理解是,只要名称匹配 (dev/drv),mcp3202_init 就会被调用,而不管该设备的 .dts 中定义了什么。

有人知道我错过了什么吗?

谢谢!

【问题讨论】:

  • 所以情节变厚了。事实证明,代码是正确的——据我所知,问题在于 Linux Makefile 系统。

标签: driver linux-device-driver device platform


【解决方案1】:

@Bryan,内核制作系统没有问题。你使用的Makefile有BUG,试试下面的Makefile编译mcp3202驱动和反馈。

有两种方法可以解决这个问题,

1) 将模块名称更改为 mcp3202_mod.o 如下,Makefile 将是,

obj-$(CONFIG_MCP3202) += mcp3202_mod.o
mcp3202_mod-objs := mcp3202.o mcp3202_pru.o

                   (or)

2) 将源文件 mcp3202.c 更改为mcp3202_&lt;meaningful-name&gt;.c,Makefile 将是,

obj-$(CONFIG_MCP3202) += mcp3202.o
mcp3202-objs := mcp3202_<name_provided>.o mcp3202_pru.o

模块名和源文件名不应该相同,如果是这样,那么初始化信息将不会出现在&lt;module_name.mod.c&gt; 中并且不会被调用。也可以通过下面的链接,

Building a kernel module from several source files which one of them has the same name as the module

【讨论】:

    猜你喜欢
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2015-08-19
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 2019-07-17
    相关资源
    最近更新 更多