Linux驱动错误码,编写Linux驱动常见错误(不断更新)!

工作中遇到的编写Linux驱动的常见错误和注意事项整理,将不断更新。

问题1、驱动的init函数声明错误

出错:

[root@localhost]# insmod phyinfo.ko

insmod: error inserting 'phyinfo.ko': -159951552 Success

原因:

驱动实现不对:

static void phyinfo_init(void)

{

......

......

}

module_init(phyinfo_init);

解决:

phyinfo_init函数必须有返回值!如可以实现定义如下:

static int phyinfo_init(void)

{

......

......

return 0;

}

问题2、linux/config.h头文件问题

出错:

/root/source/my-drivers/chartest/chartest.c:1:26: error: linux/config.h: No such file or directory

make[2]: *** [/root/source/my-drivers/chartest/chartest.o] Error 1

make[1]: *** [_module_/root/source/my-drivers/chartest] Error 2

make[1]: Leaving directory `/root/source/linux-2.6.30.5'

make: *** [modules] Error 2

原因:

The file include/linux/config.h has been removed from 2.6.19 kernel.

解决:

1、把#include 修改为如下:

#ifndef _LINUX_CONFIG_H

#define _LINUX_CONFIG_H

#include #endif

2、直接删掉#include 3、touch一个空的linux/config.h

问题3、错误现象:

/home/neil/source/my-drivers/char-simple/char-simple.c:158: error: invalid storage class for function ?._inittest?

/home/neil/source/my-drivers/char-simple/char-simple.c:158: warning: ?.lias?.attribute ignored

原因:

源码的一个函数实现时,少了一个“}”!!

问题4、模块调用内核中函数时的编译

如果模块A要用内核中自定义的一个函数,要如下来做:

1)函数实现时,EXPORT_SYMBOL

2)模块中include此函数的头文件

3)模块编译指向的内核源码,必须编译过带此函数的内核(kernel config中有此函数),不然出错如下:

[root@localhost r8168-8.014.00-2840]# make

......

ERROR: Kernel configuration is invalid.

include/linux/autoconf.h or include/config/auto.conf are missing.

Run 'make oldconfig && make prepare' on kernel src to fix it.

WARNING: Symbol version dump /work/zhaoweixing/linux-2.6.30-kdm201s/Module.symvers

is missing; modules will have no dependencies and modversions.

4)如果编译过的内核中,没有把调用的函数编译进去,会出如下信息(我调用的函数是set_eth_link_led):

WARNING: "set_eth_link_led" [/work/zhaoweixing/new-r8168/e2prom-less/r8168-8.014.00-2840/src/r8168.ko] undefined!

问题5、出错现象,运行测试程序出错如下:

[root@localhost my-drivers]# ./test

open: No such device or address

分析:

驱动写好并编译后的操作:

1)insmod mydriver.ko

2)mknod /dev/chartest c 249 0

3)编写测试程序

$cat test-user.c

#define DEVICE "/dev/chartest"

int main()

{

int fd=0;

fd=open(DEVICE,O_RDWR);

if(fd<0)

perror("open");

close(fd);

return 0;

}

解决:在驱动的初始化函数中:

cdev_add(my_cdev, 0, CDEV_NUM); 中间参数不对,修改为如下:

dev_t devno=MKDEV(chartest_major,chartest_minor+0);

result = cdev_add(my_cdev, devno, CDEV_NUM);

/*

*By Neil Chiao ()

*

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值