Driver code in kernel module doesn't execute?

后端 未结 1 1385
攒了一身酷
攒了一身酷 2020-12-10 18:20

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

#include 
#include 
#include 

        
相关标签:
1条回答
  • 2020-12-10 18:45

    If i use module_init and module_exit all works

    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.

    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.

    0 讨论(0)
提交回复
热议问题