[Linux]编写Linux驱动常见陷阱及解决办法

来源:互联网 发布:素材网站 知乎 编辑:程序博客网 时间:2024/06/05 20:53
问题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
 
 


原创粉丝点击