且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

内核模块中的驱动程序代码无法执行?

更新时间:2022-12-01 18:27:42

如果我使用module_init和module_exit都能正常工作

If i use module_init and module_exit all works

简短的原始"代码仅由模块框架组成.确保在加载模块时调用init例程,并在卸载前调用exit例程.该原始"代码不是驱动程序.

That short "original" code only consists of the module framework. The init routine is guaranteed to be called when the module is loaded, and the exit routine is called prior to unloading. That "original" code is not a driver.

较长的内核模块是驱动程序,正在加载,但是由于它具有默认的初始化和退出代码,该代码不执行任何操作(由 module_platform_driver()宏的扩展生成),因此没有消息.当内核使用设备树时,不能保证可加载模块中的驱动程序代码被调用.

The longer kernel module is a driver and getting loaded, but since it has the default init and exit code that does nothing (as generated by the expansion of the module_platform_driver() macro), there are no messages. The driver code in the loadable module is not guaranteed to be called when the kernel uses a Device Tree.

为什么这个内核模块在加载时什么都不做?

Why this kernel module doesn't do anything when i load it?

驱动程序的探测功能(将输出消息)可能没有被调用,因为您的设备树中没有任何内容指示需要此设备驱动程序.

The probe function of the driver (which would output messages) is probably not getting called because there is nothing in your Device Tree that indicates that this device driver is needed.

开发板的设备树的代码段具有

The snippet of the board's Device Tree has

    compatible = "dglnt,hello-1.00.a";

但驱动程序声明应将其指定为

but the driver declares that it should specified as

#define DEVICE_NAME "hello-1.00.a"
...   
    {.compatible = DEVICE_NAME},

这些字符串应该匹配,以便驱动程序可以在设备树"节点中与此引用的设备绑定.

These strings should match so that the driver can bind with this referenced device in the Device Tree node.

此外,设备节点应声明为

Also the device node should be declared as

    status = "okay";

覆盖任何可能禁用设备的默认状态.

to override any default status that could disable the device.

在设备树"中正确配置的节点应使驱动程序的探测功能能够按预期执行.

A properly configured node in the Device Tree should get the driver's probe function to be executed as expected.