Hello Everybody, I am having issues in compiling my kernel module please help me in this. I am attaching my sampledrv.c and Makefile.
Error I am getting:
make -C /lib/modules/2.6.28-11-generic/build M=/home/vipul/linux/ucsc/ldd
modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
CC [M] /home/vipul/linux/ucsc/ldd/sampledrv.o
In file included from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/vipul/linux/ucsc/ldd/sampledrv.c:8:
include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or
directory
include/linux/mmzone.h:256:5: warning: "MAX_NR_ZONES" is not defined
In file included from include/linux/gfp.h:4,
from include/linux/kmod.h:22,
from include/linux/module.h:13,
from /home/vipul/linux/ucsc/ldd/sampledrv.c:8:
include/linux/mmzone.h:277: error: ‘MAX_NR_ZONES’ undeclared here (not in a
function)
make[2]: *** [/home/vipul/linux/ucsc/ldd/sampledrv.o] Error 1
make[1]: *** [_module_/home/vipul/linux/ucsc/ldd] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-11-generic'
make: *** [all] Error 2
Regards,
Vipul.
/*
* 1. create MAJOR/MINOR number using alloc_chrdev_region.
* 2. initialize cdev structure.
* 3. add cdev structure cdev_add();
*/
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/fs.h>
#include<linux/cdev.h>
#include<linux/uaccess.h>
MODULE_LICENSE("GPL");
#define SAMPLEDRV_MINOR 0
#define SAMPLEDRV_DEVCOUNTS 1
#define SAMPLEDRV_NAME "SampleDriver"
static dev_t devno; //Dynamically allocated device number
static unsigned int Major; //Major device number
struct cdev cdev;
static unsigned int counter = 0;
static char CDD_storage[132];
/*
* define prototypes for read, write, open and close file_operations functions
*/
static int sampledrv_open(struct inode *, struct file *);
static int sampledrv_release(struct inode *, struct file *);
static ssize_t sampledrv_read(struct file *, char *, size_t, loff_t *);
static ssize_t sampledrv_write(struct file *, const char *, size_t, loff_t *);
/*
* define file_operations structure
*/
struct file_operations sampledrv_fops = {
.open = sampledrv_open,
.release = sampledrv_release,
.read = sampledrv_read,
.write = sampledrv_write,
};
int sampledrv_init(void)
{
int result;
result = alloc_chrdev_region( &devno, SAMPLEDRV_MINOR, SAMPLEDRV_DEVCOUNTS, SAMPLEDRV_NAME);
if( result < 0 )
{
printk(KERN_ALERT "Failed to get Dynamic device number Error: (%d)\n", result);
return result;
}
Major = MAJOR(devno);
printk(KERN_ALERT "Major device number: %d \n", Major);
//Now initialize the cdev structure
cdev.owner = THIS_MODULE ;
cdev_init(&cdev, &sampledrv_fops);
cdev_add(&cdev, devno, SAMPLEDRV_DEVCOUNTS);
}
void sampledrv_exit(void)
{
cdev_del(&cdev);
unregister_chrdev_region(devno, SAMPLEDRV_DEVCOUNTS);
}
static int sampledrv_open (struct inode *inode, struct file *file)
{
// MOD_INC_USE_COUNT;
return 0;
}
static int sampledrv_release (struct inode *inode, struct file *file)
{
// MOD_DEC_USE_COUNT;
return 0;
}
static ssize_t sampledrv_read (struct file *file, char *buf,
size_t count, loff_t *ppos)
{
int len, err;
if( counter <= 0 ) return 0;
err = copy_to_user(buf,CDD_storage,counter);
if (err != 0) return -EFAULT;
len = counter;
counter = 0;
return len;
}
static ssize_t sampledrv_write (struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
int err;
err = copy_from_user(CDD_storage,buf,count);
if (err != 0) return -EFAULT;
counter += count;
return count;
}
module_init(sampledrv_init);
module_exit(sampledrv_exit);
Makefile
Description: Binary data
