源码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#define DEVICE_NAME "myfrisr_dev_hello"
#define HELLO_MAJOR 45
static int myfrist_dev_open(struct inode *inode,struct file *file)
{
printk("come here I am here \n");
printk("");
return 0;
}
static ssize_t myfrist_dev_write(struct file *file,const char __user *buf,size_t count, loff_t *ppos)
{
printk("i will go ,thank you \n");
return 0;
}
static struct file_operations myfrist_dev_fops={
.owner = THIS_MODULE,
.open = myfrist_dev_open,
.write = myfrist_dev_write,
};
static int __init myfrist_dev_hello_init(void)
{
int ret;
ret = register_chrdev(HELLO_MAJOR,DEVICE_NAME,&myfrist_dev_fops );
if(ret<0)
{
printk(DEVICE_NAME "canot register major number");
return ret;
}
printk(DEVICE_NAME"init yes \n");
return 0;
}
static void __exit myfrist_dev_hello_exit(void)
{
unregister_chrdev(HELLO_MAJOR,DEVICE_NAME);
}
module_init(myfrist_dev_hello_init);
module_exit(myfrist_dev_hello_exit);
MODULE_LICENSE("GPL");
自己写了一个Makefile
NEL_DIR=/home/a123/lx/linux-2.6.30.4/
all:
make -C $(NEL_DIR) M=$(pwd) modules
obj-m += frist_driver_hello.o
clean:
rm -rf *.bak *.mod* *or* *.sym* *.ko *.o
但make后
出现如下:
[email=root@a123-virtual-machine:/mnt/hgfs/Win/ARMEXP/frist_driver_hello]root@a123-virtual-machine:/mnt/hgfs/Win/ARMEXP/frist_driver_hello[/email]# make
make -C /home/a123/lx/linux-2.6.30.4/ M= modules
make[1]: Entering directory `/home/a123/lx/linux-2.6.30.4'
CHK include/linux/version.h
make[2]: `include/asm-arm/mach-types.h' is up to date.
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-arm
CALL scripts/checksyscalls.sh
<stdin>:1097:2: warning: #warning syscall fadvise64 not implemented
<stdin>:1265:2: warning: #warning syscall migrate_pages not implemented
<stdin>:1321:2: warning: #warning syscall pselect6 not implemented
<stdin>:1325:2: warning: #warning syscall ppoll not implemented
<stdin>:1365:2: warning: #warning syscall epoll_pwait not implemented
Building modules, stage 2.
MODPOST 413 modules
make[1]: Leaving directory `/home/a123/lx/linux-2.6.30.4'
[email=root@a123-virtual-machine:/mnt/hgfs/Win/ARMEXP/frist_driver_hello]root@a123-virtual-machine:/mnt/hgfs/Win/ARMEXP/frist_driver_hello[/email]#
并没有编译出想要的.ko文件,
然后我使用 make -C /home/a123/lx/linux-2.6.30.4/ M=$(pwd) modules却能编译出.ko文件,这是为什么,请大侠指点一下吧 我郁闷一天啦 |