主题 : 6410加载LED驱动程序报错,cannot create duplicate filename 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 51637
精华: 0
发帖: 40
金钱: 205 两
威望: 41 点
贡献值: 0 点
综合积分: 80 分
注册时间: 2011-07-05
最后登录: 2015-10-08
楼主  发表于: 2012-01-16 15:21

 6410加载LED驱动程序报错,cannot create duplicate filename

板子是6410,用NFS挂载的根文件系统,可是不知道为什么终端上都没有写权限,我就把根目录和dev目录都改成777了,不知道这个有关系没。。。大家来看看

驱动程序:
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/gpio.h>
#include <mach/gpio-bank-k.h>
#include <plat/gpio-cfg.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>

#include "memdev.h"

#define DEVICE_NAME "leds"

static unsigned long led_table [] = {
    S3C64XX_GPK(4),
    S3C64XX_GPK(5),
    S3C64XX_GPK(6),
    S3C64XX_GPK(7)
};

static unsigned int led_cfg_table [] = {
    S3C64XX_GPK_OUTPUT(4),
    S3C64XX_GPK_OUTPUT(5),
    S3C64XX_GPK_OUTPUT(6),
    S3C64XX_GPK_OUTPUT(7)
};

static int sbc2440_leds_ioctl(
    struct file *file,
    unsigned int cmd,
    unsigned long arg)
{
    int i = 0;
        /* 检测命令的有效性 */
  if (_IOC_TYPE(cmd) != MEMDEV_IOC_MAGIC)
      return -EINVAL;
  if (_IOC_NR(cmd) > MEMDEV_IOC_MAXNR)
      return -EINVAL;
      
  /* 根据命令,执行相应的操作 */
    switch(cmd) {
    case MEMDEV_IOCOFF:
        /*灯全灭*/
        cmd = 1;
        for(i=0; i<4; i++)
            gpio_set_value(led_table, cmd);
        return 0;
        
    case MEMDEV_IOCON:
        /*灯全亮*/
        for(i=0; i<4; i++)
            gpio_set_value(led_table, cmd);
        return 0;
    default:
        return -EINVAL;
    }
}
/*文件操作结构体*/
static struct file_operations dev_fops = {
    .owner    =    THIS_MODULE,
    .unlocked_ioctl    =    sbc2440_leds_ioctl,
};

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICE_NAME,
    .fops = &dev_fops,
};

static int __init dev_init(void)
{
    int ret;

    int i;
    /*设置GPIO控制寄存器,GPIO设置为输出模式,默认下灯全灭*/
    for (i = 0; i < 4; i++) {
        s3c_gpio_cfgpin(led_table, led_cfg_table);
        gpio_set_value(led_table, 1);
    }
    /*注册混杂型字符设备驱动*/
    ret = misc_register(&misc);

    printk (DEVICE_NAME"\tinitialized\n");

    return ret;
}

static void __exit dev_exit(void)
{
    /*注销混杂型字符设备驱动*/
    misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);

MODULE_AUTHOR("David Xie");
MODULE_LICENSE("GPL");

驱动加载后出错信息:
/ # insmod leds_misc.ko
------------[ cut here ]------------
WARNING: at fs/sysfs/dir.c:455 sysfs_add_one+0x74/0x9c()
sysfs: cannot create duplicate filename '/devices/virtual/misc/leds'
Modules linked in: leds_misc(+)
[<c003a570>] (unwind_backtrace+0x0/0xec) from [<c00498b4>] (warn_slowpath_commo)
[<c00498b4>] (warn_slowpath_common+0x4c/0x64) from [<c004994c>] (warn_slowpath_)
[<c004994c>] (warn_slowpath_fmt+0x2c/0x3c) from [<c00edd0c>] (sysfs_add_one+0x7)
one_wire_status: 2
[<c00edd0c>] (sysfs_add_one+0x74/0x9c) from [<c00ee714>] (create_dir+0x5c/0xac)
[<c00ee714>] (create_dir+0x5c/0xac) from [<c00ee828>] (sysfs_create_dir+0xc4/0x)
one_wire_status: 2
[<c00ee828>] (sysfs_create_dir+0xc4/0xec) from [<c0194064>] (kobject_add_intern)
[<c0194064>] (kobject_add_internal+0xd0/0x1a4) from [<c01942b0>] (kobject_add+0)
one_wire_status: 3
[<c01942b0>] (kobject_add+0x4c/0x5c) from [<c01d5b98>] (device_add+0xa0/0x500)
[<c01d5b98>] (device_add+0xa0/0x500) from [<c01d6098>] (device_create_vargs+0x8)
[<c01d6098>] (device_create_vargs+0x88/0xbc) from [<c01d60e4>] (device_create+0)
one_wire_status: 4
[<c01d60e4>] (device_create+0x18/0x20) from [<c01d3fe4>] (misc_register+0xb8/0x)
[<c01d3fe4>] (misc_register+0xb8/0x128) from [<bf003040>] (dev_init+0x40/0x60 [)
one_wire_status: 4
[<bf003040>] (dev_init+0x40/0x60 [leds_misc]) from [<c002a40c>] (do_one_initcal)
[<c002a40c>] (do_one_initcall+0xc8/0x19c) from [<c0071624>] (sys_init_module+0x)
[<c0071624>] (sys_init_module+0x12b4/0x1454) from [<c0034de0>] (ret_fast_syscal)
one_wire_status: 4
---[ end trace 9d6931ccd5e8f11c ]---
kobject_add_internal failed for leds with -EEXIST, don't try to register things.
one_wire_status: 4
[<c003a570>] (unwind_backtrace+0x0/0xec) from [<c01940f0>] (kobject_add_interna)
[<c01940f0>] (kobject_add_internal+0x15c/0x1a4) from [<c01942b0>] (kobject_add+)
one_wire_status: 4
[<c01942b0>] (kobject_add+0x4c/0x5c) from [<c01d5b98>] (device_add+0xa0/0x500)
[<c01d5b98>] (device_add+0xa0/0x500) from [<c01d6098>] (device_create_vargs+0x8)
[<c01d6098>] (device_create_vargs+0x88/0xbc) from [<c01d60e4>] (device_create+0)
one_wire_status: 4
[<c01d60e4>] (device_create+0x18/0x20) from [<c01d3fe4>] (misc_register+0xb8/0x)
[<c01d3fe4>] (misc_register+0xb8/0x128) from [<bf003040>] (dev_init+0x40/0x60 [)
one_wire_status: 4
[<bf003040>] (dev_init+0x40/0x60 [leds_misc]) from [<c002a40c>] (do_one_initcal)
[<c002a40c>] (do_one_initcall+0xc8/0x19c) from [<c0071624>] (sys_init_module+0x)
one_wire_status: 4
[<c0071624>] (sys_init_module+0x12b4/0x1454) from [<c0034de0>] (ret_fast_syscal)
leds    initialized
insmod: can't insert 'leds_misc.ko': File exists
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2012-01-16 16:25
看起来你用的内核镜像里已经包含了一个led驱动了。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 51637
精华: 0
发帖: 40
金钱: 205 两
威望: 41 点
贡献值: 0 点
综合积分: 80 分
注册时间: 2011-07-05
最后登录: 2015-10-08
2楼  发表于: 2012-01-16 16:43
谢谢斑竹~这个我也刚发现了,我是用的友善的2.6.38内核编译的,里面自带的~但是现在又遇到了一个问题,我想调用内核自带的这个驱动点亮LED,

我看了一下,这个驱动的次设备号是MISC_DYNAMIC_MINOR,应该是内核动态分配的,可是我用的NFS挂载的根文件系统,/dev里面没有leds这个文件,只有手工创建了,但是次设备号应该是多少呢?
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2012-01-16 17:55
你可以通过在命令行上执行“cat /proc/misc”看到内核为Led模块分配的minor号。
另外,你用的是光盘上的rootfs_qtopia_qt4的文件系统吗?它里面包含busybox的mdev, 可以动态创建设备节点的。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 51637
精华: 0
发帖: 40
金钱: 205 两
威望: 41 点
贡献值: 0 点
综合积分: 80 分
注册时间: 2011-07-05
最后登录: 2015-10-08
4楼  发表于: 2012-01-16 21:35
谢谢大大,刚吃完年饭回来~

文件系统我是网上找的个文章,自己跟着创建了一个文件系统,busybox貌似也是用的最新版本编译安装的