|
我在编译一个驱动的时候出现一些问题,驱动是我参照书和网上的资料写的一个很基本的驱动,但是编译一直没法通过,恳请高手帮忙看看啊~~
驱动代码如下:
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef __NO_VERSION_
#define __NO_VERSION_
#endif
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL_SYSCALLS__
#define __KERNEL_SYSCALLS__
#endif
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/config.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#include <asm/segment.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <unistd.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A SIMPLE CHAR DRIVER");
MODULE_AUTHOR("PLIKE<[email protected]>");
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?*/
char kbuf[10];
static int device_open(struct inode *inode, struct file *file)
{
if (Device_Open)
return -EBUSY;
Device_Open++;
printf("device is opened~");
try_module_get(THIS_MODULE);
return SUCCESS;
}
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
module_put(THIS_MODULE);
return 0;
}
static ssize_t device_read(struct file *filp,char *buffer,size_t length,loff_t
* offset)
//static int device_read(struct inode *inode,struct file *file, char *buf,int
//count)
{
if (verify_area(VERIFY_WRITE,buffer,length) == -EFAULT )
return -EFAULT;
//copy_to_user(buffer, kbuf, length);
//_constant_copy_to_user(1,1,1);
_copy_to_user(1, 1, 1);
printf("111111111111");
return length;
}
static ssize_t device_write(struct file *filp, const char *buff, size_t len,
loff_t * off)
{
int retval = len;
//extern unsigned char kbuf[10];
_constant_copy_from_user(1, 1, 1);
return retval;
}
struct file_operations fops = {
read: device_read,
write: device_write,
open: device_open,
release: device_release
};
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printf("Registering the character device failed with %d\n",Major);
return Major;
}
printf("<1>I was assigned major number %d. To talk to\n", Major);
printf("<1>the driver, create a dev file with\n");
printf("'mknod /dev/hello c %d 0'.\n", Major);
printf("<1>Try various minor numbers. Try to cat and echo to\n");
printf("the device file.\n");
printf("<1>Remove the device file and module when done.\n");
return 0;
}
void cleanup_module(void)
{
int ret;
ret=unregister_chrdev(Major, DEVICE_NAME);
//if (ret < 0)
//printf("Error in unregister_chrdev: %d\n", ret);
}
//module_init(init_module);
//module_exit(cleanup_module);
我使用的是 redhat linux 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
编译参数设置如下:
gcc -c copydriver.c -D_KERNEL_ -DMODULE -O2 -I /usr/src/linux-2.4/include/ -o copydriver.o
编译后报错信息如下:
copydriver.c: In function `cleanup_module':
copydriver.c:176: `c192d491' undeclared (first use in this function)
copydriver.c:176: (Each undeclared identifier is reported only once
copydriver.c:176: for each function it appears in.)
copydriver.c:176: called object is not a function
有没有高手曾经遇到过这个问题啊,请指教,万分感激~~ |
|