Hello,
I am fairly new to linux and new to device driver programming. I have a fresh install of ubuntu 6.0.6 and decided to start off with a small program that dosent do nothing, but i cant even get that to work
I havent done anything to the system yet besides install GNU make. When i call make, i get the following error.
make: Nothing to be done for `default'.
Could someone please head me onto the right track? I added the source code and the makefile after the message. And please try make it dummy proof :/ , I know the basics of linux but nothing really advanced.
Thanks in advances
My source code is.
=========================================================================
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/cdev.h>
MODULE_AUTHOR("none");
MODULE_DESCRIPTION("driver_lab1");
MODULE_SUPPORTED_DEVICE("none");
MODULE_LICENSE("none");
MODULE_PARM_DESC(major, "major number");
static int major = 240;
module_param(major, int, 0);
static ssize_t my_read_function(struct file *file, char *buf, size_t count, loff_t *ppos)
{
printk(KERN_DEBUG "read()\n");
return 0;
}
static ssize_t my_write_function(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
printk(KERN_DEBUG "write()\n");
return 0;
}
static int my_open_function(struct inode *inode, struct file *file)
{
printk(KERN_DEBUG "open()\n");
return 0;
}
static int my_release_function(struct inode *inode, struct file *file)
{
printk(KERN_DEBUG "close()\n");
return 0;
}
static struct file_operations fops =
{
.owner = THIS_MODULE,
.read = my_read_function,
.write = my_write_function,
.open = my_open_function,
.release = my_release_function /* correspond a close */
};
static struct cdev ccdev;
static void cdevinit (struct cdev *dev, struct file_operations *fops)
{
int err, devno = MKDEV(major,0);
cdev_init(dev, fops);
dev->owner = THIS_MODULE;
dev->ops = fops;
err = cdev_add(dev, devno, 1);
if (err)
printk (KERN_DEBUG "erreur dans cdevinit");
}
static int __init mon_module_init(void)
{
int result = register_chrdev_region(major ,1,"driver_lab1");
if(result)
printk(KERN_DEBUG "driver_lab1 non chargé\n");
else
printk(KERN_DEBUG "driver_lab1 chargé avec succès\n");
cdevinit(&ccdev, &fops);
return 0;
}
static void __exit mon_module_cleanup(void)
{
unregister_chrdev_region(major, 1);
printk(KERN_DEBUG "driver_lab1 déchargé avec succès\n");
}
module_init(mon_module_init);
module_exit(mon_module_cleanup);
========================================================================
My makefile is
========================================================================
ifneq ($(KERNELRELEASE),)
obj-m := lab1.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
========================================================================