驱动编译错误
驱动源码: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