Driver code in kernel module not executing?

Why does this kernel module do nothing when I load it?

#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); 

It should print Hello, world\n , if I do lsmod , the module loads:

 lsmod hello_world 1538 0 - Live 0xbf000000 (O) 

but nothing is printed either on the console or in dmesg .

If I use module_init and module_exit everything works, but I need to point the platform_device *pdev to the device, what can I do?

EDIT:

The source module is as follows:

 #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); 

This entry is present in my blob device tree:

 hello { compatible = "dglnt,hello-1.00.a"; reg = <0x41220000 0x10000>; }; 
+5
source share
1 answer

If I use module_init and module_exit everything works

This short "original" code consists only of a modular structure. The init procedure will be called when the module is loaded, and the exit procedure is called before unloading. This "original" code is not a driver.

The longer a kernel module is loaded, and the driver, but because it has a default initialization code and end, which does nothing (generated by the expansion of module_platform_driver () macro), there are no posts. The driver code in the loadable module cannot be called when the kernel uses the device tree.

Why does this kernel module do nothing when I load it?

The driver probe function (which displays messages) will probably not be called because there is nothing in your device tree that indicates the need to use this device driver.

A fragment of the device tree board has

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

but the driver will declare that it should be indicated as

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

These lines must match so that the driver can communicate with this referenced device in the node device tree.

Also, the node device must be declared as

  status = "okay"; 

to override any default status that might disable the device.

A properly configured node in the device tree should receive the driver check function as expected.

+5
source

Source: https://habr.com/ru/post/1206550/


All Articles