RT,小弟菜鸟一个,今天刚接触驱动,照着实验书写了代码,编译问题一堆,附上代码和问题,希望大虾能够帮帮忙!
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/module.h>
#include <asm/hardware.h>
//HELLO DEVICE MAJOR
#define SIMPLE_HELLO_MAJOR 96
#define OURS_HELLO_DEBUG
#define VERSION "PXA2700EP-hello-V1.00-06053"
void showversion(void)
{
printk("********************************\n");
printk("\t %s \t\n",VERSION);
printk("********************************\n\n");
}
//-----------READ-----------------
ssize_t SIMPLE_HELLO_read(struct file * file,char * buf,size_t count,loff_t * f_ops)
{
#ifdef OURS_HELLO_DEBUG
printk("SIMPLE_HELLO_read[ --kernel--]\n");
#endif
return count;
}
//-----------WRITE----------------
ssize_t SIMPLE_HELLO_write(struct file *file,const char *buf,size_t count,loff_t *f_ops)
{
#ifdef OURS_HELLO_DEBUG
printk("SIMPLE_HELLO_write[ --kernel--]\n");
#endif
return count;
}
//----------IOCTL-----------------
ssize_t SIMPLE_HELLO_ioctl(struct inode *inode,struct file *file,unsigned int cmd,long data)
{
#ifdef OURS_HELLO_DEBUG
printk("SIMPLE_HELLO_ioctl[ --kernel--]\n");
#endif
return 0;
}
//---------OPEN--------------------
ssize_t SIMPLE_HELLO_open(struct inode *inode,struct file *file)
{
#ifdef OURS_HELLO_DEBUG
printk("SIMPLE_HELLO_open[ --kernel--]\n");
#endif
MOD_INC_USE_COUNT;
return 0;
}
//--------RELEASE/CLOSE-------------
ssize_t SIMPLE_HELLO_release(struct inode *inode,struct file * file)
{
#ifdef OURS_HELLO_DEBUG
printk("SIMPLE_HELLO_release[ --kernel--]\n");
#endif
MOD_DEC_USE_COUNT;
return 0;
}
//------------------------------------
struct file_operations HELLO_ctl_ops={
open: SIMPLE_HELLO_open,
read: SIMPLE_HELLO_read,
write: SIMPLE_HELLO_write,
ioctl: SIMPLE_HELLO_ioctl,
release:SIMPLE_HELLO_release,
};
//--------------INIT------------------
static int __init HW_HELLO_CTL_init(void)
{
int ret = -ENODEV;
ret = devfs_register_chrdev(SIMPLE_HELLO_MAJOR,"hello_ctl",&HELLO_ctl_ops);
showversion();
if(ret < 0)
{
printk("pxa270 init_module failed with %d\n [ --kernel--]",ret);
return ret;
}
else
{
printk("pxa270 hello_driver register success!!![ --kernel--]\n");
}
return ret;
}
static int __init pxa270_HELLO_CTL_init(void)
{
int ret = -ENODEV;
#ifdef OURS_HELLO_DEBUG
printk("pxa270_HELLO_CTL_init[ --kernel--]\n");
#endif
ret = HW_HELLO_CTL_init();
if(ret)
return ret;
return 0;
}
static void __exit cleanup_HELLO_ctl(void)
{
#ifdef OURS_HELLO_DEBUG
printk("cleanup_HELLO_ctl[ --kernel--]\n");
#endif
devfs_unregister_chrdev(SIMPLE_HELLO_MAJOR,"hello_ctl");
}
MODULE_DESCRIPTION("simple hello driver module");
MODULE_AUTHOR("spirits");
MODULE_LICENSE("GPL");
module_init(pxa270_HELLO_CTL_init);
module_exit(cleanup_HELLO_ctl);
问题:
arm-linux-gcc -c -I.. -Wall -O -D__KERNEL__ -DMODULE -I/pxa270_linux/linux/include pxa270_hello_drv.c -o pxa270_hello_drv.o
pxa270_hello_drv.c:18: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:18: warning: its scope is only this definition or declaration, which is probably not what you want
pxa270_hello_drv.c:26: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:34: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:34: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:42: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:42: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:51: warning: `struct file' declared inside parameter list
pxa270_hello_drv.c:51: warning: `struct inode' declared inside parameter list
pxa270_hello_drv.c:60: error: variable `HELLO_ctl_ops' has initializer but incomplete type
pxa270_hello_drv.c:61: error: unknown field `open' specified in initializer
pxa270_hello_drv.c:61: warning: excess elements in struct initializer
pxa270_hello_drv.c:61: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:62: error: unknown field `read' specified in initializer
pxa270_hello_drv.c:62: warning: excess elements in struct initializer
pxa270_hello_drv.c:62: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:63: error: unknown field `write' specified in initializer
pxa270_hello_drv.c:63: warning: excess elements in struct initializer
pxa270_hello_drv.c:63: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:64: error: unknown field `ioctl' specified in initializer
pxa270_hello_drv.c:64: warning: excess elements in struct initializer
pxa270_hello_drv.c:64: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c:65: error: unknown field `release' specified in initializer
pxa270_hello_drv.c:65: warning: excess elements in struct initializer
pxa270_hello_drv.c:65: warning: (near initialization for `HELLO_ctl_ops')
pxa270_hello_drv.c: In function `HW_HELLO_CTL_init':
pxa270_hello_drv.c:70: error: `ENODEV' undeclared (first use in this function)
pxa270_hello_drv.c:70: error: (Each undeclared identifier is reported only once
pxa270_hello_drv.c:70: error: for each function it appears in.)
pxa270_hello_drv.c:71: warning: implicit declaration of function `devfs_register_chrdev'
pxa270_hello_drv.c: In function `pxa270_HELLO_CTL_init':
pxa270_hello_drv.c:86: error: `ENODEV' undeclared (first use in this function)
pxa270_hello_drv.c: In function `cleanup_HELLO_ctl':
pxa270_hello_drv.c:100: warning: implicit declaration of function `devfs_unregister_chrdev'
pxa270_hello_drv.c: At top level:
pxa270_hello_drv.c:60: error: storage size of `HELLO_ctl_ops' isn't known
make: *** [pxa270_hello_drv.o] Error 1 |