Linux kernel 内核模块中的驱动程序代码不';不执行?

Linux kernel 内核模块中的驱动程序代码不';不执行?,linux-kernel,linux-device-driver,kernel-module,device-tree,insmod,Linux Kernel,Linux Device Driver,Kernel Module,Device Tree,Insmod,为什么这个内核模块在我加载时什么都不做 #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 p

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

#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);
但是,无论是在控制台中还是在
dmesg
中都不会打印任何内容

如果我使用
module\u init
module\u exit
都可以,但我需要指向设备的指针
platform\u 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);
#包括
#包括
静态int hello_init(void){
printk(KERN_警报“你好,世界”\n);
返回0;
}
静态void hello_退出(void){
printk(KERN_ALERT“再见,残酷的世界”);
}
模块_init(hello_init);
模块退出(你好退出);
在我的设备树blob中存在以下条目:

hello {
    compatible = "dglnt,hello-1.00.a";
    reg = <0x41220000 0x10000>;
};
你好{ compatible=“dglnt,hello-1.00.a”; reg=; }; 如果我使用module_init和module_退出所有工作

简短的“原始”代码只包含模块框架。保证在加载模块时调用init例程,在卸载之前调用exit例程。“原始”代码不是驱动程序

较长的内核模块是一个驱动程序,正在加载,但由于它有默认的init和exit代码(由扩展模块\u平台\u driver()宏生成),因此没有消息。当内核使用设备树时,不保证调用可加载模块中的驱动程序代码

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

#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);
驱动程序的探测功能(将输出消息)可能未被调用,因为设备树中没有任何内容指示需要此设备驱动程序

电路板设备树的片段已被删除

    compatible = "dglnt,hello-1.00.a";
但是驱动程序声明它应该指定为

#define DEVICE_NAME "hello-1.00.a"
...   
    {.compatible = DEVICE_NAME},
这些字符串应该匹配,以便驱动程序可以与设备树节点中的引用设备绑定

此外,还应将设备节点声明为

    status = "okay";
覆盖可能禁用设备的任何默认状态


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

“如果我使用module_init和module_exit all works”-该代码是什么样子的?这个内核是否使用设备树blob?是的,它使用了dtb,我的问题是,当我添加原始源代码时,没有打印任何内容。module_init和module_exit基本上通知内核在插入和删除模块时要执行什么方法。这就是为什么dmesg中没有打印任何内容的原因。尝试保持整个代码不变,只需在代码末尾插入module_init和module_exit。不能在同一模块中使用module_platform_驱动程序和module_init/exit,它们是互斥的。