驱动编译错误

DwyaneCV 2018-03-28 08:14:06
驱动源码:My_Dev_2410Prj.c
#include <linux/module.h>//
#include <linux/kernel.h>//
#include <linux/fs.h>//
#include <linux/init.h>//
#include <linux/delay.h>//
#include <asm/uaccess.h>
#include <asm/irq.h>//
#include <asm/io.h>//
#include <asm/hardware.h>
#include <linux/platform_device.h>/*驱动注册的头文件,包含驱动的结构体和注册和卸载的函数*/
#include <linux/fs.h>/*注册设备节点的文件结构体*/
#define DRIVER_NAME "hello_ctl" //驱动名称
#define DEVICE_NAME "hello_ctl" //设备名称
static int major;
static struct class *cls;
static struct device *dev;
static long hello_ioctl( struct file *files, unsigned int cmd, unsigned long arg){
printk("first_drv_ioctl\n");return 0;
}
static int hello_release(struct inode *inode, struct file *file){
printk("hello release\n");return 0;
}
static int hello_open(struct inode *inode, struct file *file){
printk("hello open\n");return 0;
}
static struct file_operations hello_ops = {
.owner = THIS_MODULE,
.open = hello_open,
.release = hello_release,
.unlocked_ioctl = hello_ioctl,
};
static int hello_probe(struct platform_device *pdv)
{
printk("\tinitialized\n");
major = register_chrdev(0, "My2410Prj", &hello_ops); // 注册设备驱动 创建设备节点
cls = class_create(THIS_MODULE, "My2410Prj"); // 创建类
dev = device_create(cls, NULL, MKDEV(major, 0), NULL, "My_Dev_2410Prj"); // 创建设备节点
return 0;
}
static int hello_remove(struct platform_device *pdv){
printk("\tremove\n");
misc_deregister(&hello_dev);
return 0;
}
static void hello_shutdown(struct platform_device *pdv){return 0;}
static int hello_suspend(struct platform_device *pdv,pm_message_t pmt){return 0;}
static int hello_resume(struct platform_device *pdv){return 0;}
struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
}
};
static int hello_init(void)
{
int DriverState;
printk("HELLO WORLD enter!\n");
DriverState = platform_driver_register(&hello_driver);

printk(KERN_EMERG "\tDriverState is %d\n",DriverState);
return 0;
}
static void hello_exit(void)
{
printk("HELLO WORLD exit!\n");
platform_driver_unregister(&hello_driver);
}
module_init(hello_init);
module_exit(hello_exit);


Makefile:
KERN_DIR = /usr/ARM/Linux_Kernel/linux-2.6.22.6

all:
make -C $(KERN_DIR) M=`pwd` modules

clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order

obj-m += My_Dev_2410Prj.o

但make后错误:

root@mk-virtual-machine:/usr/ARM/ARM_Driver/My2410Prj# make
make -C /usr/ARM/Linux_Kernel/linux-2.6.22.6 M=`pwd` modules
make[1]: Entering directory '/usr/ARM/Linux_Kernel/linux-2.6.22.6'
CC [M] /usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.o
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c:25:24: linux/gpio.h: No such file or directory
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c: In function `hello_probe':
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c:72: warning: too many arguments for format
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c:63: warning: unused variable `ret'
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c: In function `hello_shutdown':
/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.c:87: warning: `return' with a value, in function returning void
scripts/Makefile.build:208: recipe for target '/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.o' failed
make[2]: *** [/usr/ARM/ARM_Driver/My2410Prj/Myled2410Prj.o] Error 1
Makefile:1204: recipe for target '_module_/usr/ARM/ARM_Driver/My2410Prj' failed
make[1]: *** [_module_/usr/ARM/ARM_Driver/My2410Prj] Error 2
make[1]: Leaving directory '/usr/ARM/Linux_Kernel/linux-2.6.22.6'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
...全文
316 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DwyaneCV 2018-03-28
  • 打赏
  • 举报
回复
引用 3 楼 jklinux 的回复:
那应该不用,而且你的代码里根本没用到linux/gpio.h里的内容,也不需要包含这个头文件。 难道linux-2.6还没有gpio子系统不成?
去掉那个头文件后就可以了
DwyaneCV 2018-03-28
  • 打赏
  • 举报
回复
引用 1 楼 jklinux 的回复:
好奇怪啊,linux/gpio.h是常用的头文件,没理由不存在的。 你的内核源码有编译过了吗?编译驱动模块前一般先把内核源码编译的
还真是那个头文件的问题,我一直以为这只是个警告,无所谓。
jklinux 2018-03-28
  • 打赏
  • 举报
回复
那应该不用,而且你的代码里根本没用到linux/gpio.h里的内容,也不需要包含这个头文件。 难道linux-2.6还没有gpio子系统不成?
DwyaneCV 2018-03-28
  • 打赏
  • 举报
回复
引用 1 楼 jklinux 的回复:
好奇怪啊,linux/gpio.h是常用的头文件,没理由不存在的。 你的内核源码有编译过了吗?编译驱动模块前一般先把内核源码编译的
编译过的,之前没有用platform_driver/platform_device进行注册,而用下面的代码,编译是可以的,难道用platform_driver/platform_device方法还得重新配置内核?? #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/delay.h> #include <asm/uaccess.h> #include <asm/irq.h> #include <asm/io.h> #include <asm/arch/regs-gpio.h> #include <asm/hardware.h> static struct class *firstdrv_class; static struct class_device *firstdrv_class_dev; volatile unsigned long *gpfcon = NULL; volatile unsigned long *gpfdat = NULL; static int first_drv_open(struct inode *inode, struct file *file) { printk("first_drv_open\n"); return 0; } static ssize_t first_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos) { printk("first_drv_write\n"); return 0; } static struct file_operations first_drv_fops = { .owner = THIS_MODULE, /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */ .open = first_drv_open, .write = first_drv_write, }; int major; static int first_drv_init(void) { major = register_chrdev(111, "first_drv", &first_drv_fops); // 注册, 告诉内核 return 0; } static void first_drv_exit(void) { unregister_chrdev(111, "first_drv"); // 卸载 } module_init(first_drv_init); module_exit(first_drv_exit);
jklinux 2018-03-28
  • 打赏
  • 举报
回复
好奇怪啊,linux/gpio.h是常用的头文件,没理由不存在的。 你的内核源码有编译过了吗?编译驱动模块前一般先把内核源码编译的

1,317

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧