OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2594|回复: 2

字符驱动发生错误:modprobe: can't load module chrdevbase.ko (chrdevbase.ko): invalid module format

[复制链接]

0

主题

2

帖子

0

精华

新手上路

积分
31
金钱
31
注册时间
2022-10-11
在线时间
6 小时
发表于 2023-3-22 22:00:27 | 显示全部楼层 |阅读模式
13金钱
本帖最后由 susuquxuexi 于 2023-3-22 22:09 编辑

能成功的的代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#define CHRDEVBASE_MAJOR 4000
#define CHRDEVBASE_NAME "chardevbase"
/*
    模块入出口
*/
static int __init chrdevbase_init(void)
{
        return 0;
}
static void __exit chrdevbase_exit(void)
{
}
module_init(chrdevbase_init);  //模块入口
module_exit(chrdevbase_exit);  //模块出口
MODULE_AUTHOR("zyh");
MODULE_LICENSE("GPL");

报错的代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>

#define CHRDEVBASE_MAJOR 4000
#define CHRDEVBASE_NAME "chardevbase"

static int chrdevbase_open(struct inode *inode, struct file *file)
{
    printk("chrdevbase_open\r\n");
    return 0;
}

static int chrdevbase_release(struct inode *inode, struct file *file)
{
    printk("chrdevbase_release\r\n");
    return 0;
}

static ssize_t chrdevbase_write(struct file *file,
                const char __user *user_buf, size_t count, loff_t *ppos)
{
    printk("chrdevbase_write\r\n");
    return 0;
}

static ssize_t chrdevbase_read(struct file *file, char __user *user_buf,
                                   size_t count, loff_t *ppos)
{
    printk("chrdevbase_read\r\n");
    return 0;
}

static const struct file_operations chrdevbase =
{
    .owner = THIS_MODULE,
    .open = chrdevbase_open,
    .write = chrdevbase_write,
    .read = chrdevbase_read ,
    .release = chrdevbase_release,
};



/*
    模块入出口
*/
static int __init chrdevbase_init(void)
{
    int ret;
    printk("chrdevbase_init");
    ret = register_chrdev(CHRDEVBASE_MAJOR, CHRDEVBASE_NAME, &chrdevbase);
    if(ret < 0){
        printk("chrdevbase init error\r\n");
    }
        return 0;
}

static void __exit chrdevbase_exit(void)
{
        printk("chrdevbase_exit");
    unregister_chrdev(CHRDEVBASE_MAJOR, CHRDEVBASE_NAME);
}


module_init(chrdevbase_init);  //模块入口
module_exit(chrdevbase_exit);  //模块出口

MODULE_AUTHOR("zyh");
MODULE_LICENSE("GPL");



最佳答案

查看完整内容[请看2#楼]

已解决:降低gcc的版本
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

0

主题

2

帖子

0

精华

新手上路

积分
31
金钱
31
注册时间
2022-10-11
在线时间
6 小时
 楼主| 发表于 2023-3-22 22:00:28 | 显示全部楼层
已解决:降低gcc的版本
回复

使用道具 举报

0

主题

2

帖子

0

精华

新手上路

积分
31
金钱
31
注册时间
2022-10-11
在线时间
6 小时
 楼主| 发表于 2023-3-22 22:04:55 | 显示全部楼层
/lib/modules/4.1.15 # modprobe chrdevbase.ko
chrdevbase: unknown relocation: 3
chrdevbase: unknown relocation: 3
modprobe: can't load module chrdevbase.ko (chrdevbase.ko): invalid module format
/lib/modules/4.1.15 # modprobe chrdevbase.ko

ko文件中调用了任何别的函数比如prink、register_chrdev、unregister_chrdev就会报错,把这些都屏蔽掉就没有错误。

uname -a命令显示的是:
Linux 192.168.10.50 4.1.15 #1 SMP PREEMPT Wed Mar 22 06:14:48 PDT 2023 armv7l GNU/Linux

modinfo chrdevbase.ko 命令显示的是
vermagic:       4.1.15 SMP preempt mod_unload modversions ARMv7 p2v8
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-19 07:49

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表