主题 : LED驱动程序编译不能通过 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 57366
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
贡献值: 0 点
综合积分: 32 分
注册时间: 2011-10-23
最后登录: 2012-04-25
楼主  发表于: 2011-12-28 17:02

 LED驱动程序编译不能通过

我使用的是国嵌的LED驱动程序:
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.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 [] = {
    S3C2410_GPB5,
    S3C2410_GPB6,
    S3C2410_GPB7,
    S3C2410_GPB8,
};

static unsigned int led_cfg_table [] = {
    S3C2410_GPB5_OUTP,
    S3C2410_GPB6_OUTP,
    S3C2410_GPB7_OUTP,
    S3C2410_GPB8_OUTP,
};

static int sbc2440_leds_ioctl(
    struct inode *inode,
    struct file *file,
    unsigned int cmd,
    unsigned long arg)/*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++)
            s3c2410_gpio_setpin(led_table, cmd);
        return 0;
        
        
        
    case MEMDEV_IOCON:
        /*灯全亮*/
        for(i=0; i<4; i++)
            s3c2410_gpio_setpin(led_table, !cmd);
        return 0;
    default:
        return -EINVAL;
    }
}
/*文件操作结构体*/
static struct file_operations dev_fops = {
    .owner    =    THIS_MODULE,
    .ioctl    =    sbc2440_leds_ioctl,
};

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,/*在内核中为255,如果你不知道哪些被用了,使用它,内核为你分配*/
    .name = DEVICE_NAME,
    .fops = &dev_fops,
};

static int __init dev_init(void)
{
    int ret;

    int i;
    /*设置GPIO控制寄存器,GPIO设置为输出模式,默认下灯全灭*/
    for (i = 0; i < 4; i++) {
        s3c2410_gpio_cfgpin(led_table, led_cfg_table);/*板级支持包实现的:/arch/arm*/
        s3c2410_gpio_setpin(led_table, 1);/*设置相应GPIO口的值*/
    }
    /*注册混杂型字符设备驱动*/
    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");

make的时候错误提示为:
[root@localhost 5-3-2]# make
make -C /root/Desktop/kernel/linux-2.6.38 M=/mnt/hgfs/share/guoqian2/5-3-2 modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/root/Desktop/kernel/linux-2.6.38'
  CC [M]  /mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.o
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:33:2: error: 'S3C2410_GPB5' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:34:2: error: 'S3C2410_GPB6' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:35:2: error: 'S3C2410_GPB7' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:36:2: error: 'S3C2410_GPB8' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: 'S3C2410_GPB5_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: (near initialization for 'led_cfg_table[0]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: 'S3C2410_GPB6_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: (near initialization for 'led_cfg_table[1]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: 'S3C2410_GPB7_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: (near initialization for 'led_cfg_table[2]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: 'S3C2410_GPB8_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: (near initialization for 'led_cfg_table[3]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: In function 'sbc2440_leds_ioctl':
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:65:4: error: implicit declaration of function 's3c2410_gpio_setpin'
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: At top level:
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: error: unknown field 'ioctl' specified in initializer
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: warning: initialization from incompatible pointer type
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: In function 'dev_init':
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:96:3: error: implicit declaration of function 's3c2410_gpio_cfgpin'
make[2]: *** [/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.o] Error 1
make[1]: *** [_module_/mnt/hgfs/share/guoqian2/5-3-2] Error 2
make[1]: Leaving directory `/root/Desktop/kernel/linux-2.6.38'
make: *** [all] Error 2
我的内核版本是2.6.38.
我觉得应该是是头文件的问题:
我用souce insight查了一下,'S3C2410_GPB5、6、7、8以及'S3C2410_GPB5_OUTP在内核中的arch/arm/mach-s3c2410/include/mach/regs-gpio.h头文件中定义。
s3c2410_gpio_setpin在内核中的头文件arch/arm/mach-s3c2410/include/mach/hardware.h中定义。
不知道怎么回事,请大家帮帮忙啊!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2011-12-28 17:36
在编译模块之前,确保你正确配置了内核源代码,比如make ARCH=arm CROSS_COMPILE=arm-linux- mini2440_defconfig
"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: 57366
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
贡献值: 0 点
综合积分: 32 分
注册时间: 2011-10-23
最后登录: 2012-04-25
2楼  发表于: 2011-12-28 18:48

 回 1楼(kasim) 的帖子

我已经从新配置了并编译了内核,在.config文件可以看出:# CONFIG_MINI6410_LEDS is not set
但问题依然没有解决,希望版主帮忙分析一下啊!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2011-12-28 21:11
你用的是mini6410?从源代码看,这个驱动程序是针对mini2440写的。
"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: 57366
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
贡献值: 0 点
综合积分: 32 分
注册时间: 2011-10-23
最后登录: 2012-04-25
4楼  发表于: 2011-12-28 21:19

 回 3楼(kasim) 的帖子

我也发现了,那我是不是要对代码做一些改动呢?
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2011-12-28 22:04

 回 4楼(thefutureis) 的帖子

是的,你可以用s3c_gpio_cfgpin()和gpio_direction_output()来代替
"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: 57366
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
贡献值: 0 点
综合积分: 32 分
注册时间: 2011-10-23
最后登录: 2012-04-25
6楼  发表于: 2011-12-29 09:11

 回 5楼(kasim) 的帖子

能说具体一点么?用s3c_gpio_cfgpin()和gpio_direction_output()来代替哪几句?编译的时候总是对这几句代码报错:
static unsigned long led_table [] = {
    S3C2410_GPB5,
    S3C2410_GPB6,
    S3C2410_GPB7,
    S3C2410_GPB8,
};

static unsigned int led_cfg_table [] = {
    S3C2410_GPB5_OUTP,
    S3C2410_GPB6_OUTP,
    S3C2410_GPB7_OUTP,
    S3C2410_GPB8_OUTP,
};
而且2.6.29内核中没有gpio_direction_output()函数啊!
[ 此帖被thefutureis在2011-12-29 09:35重新编辑 ]
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2011-12-29 10:18
gpio_direction_output()在2.6.29版本的内核里有,至少我看到的是这样http://lxr.linux.no/linux+v2.6.29/include/asm-generic/gpio.h#L115。至于这两个接口用来干什么,你不会不知道吧。
"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: 73530
精华: 0
发帖: 44
金钱: 225 两
威望: 45 点
贡献值: 0 点
综合积分: 88 分
注册时间: 2012-07-10
最后登录: 2014-09-03
8楼  发表于: 2012-09-16 11:47
在这个错误中我还看到另外一个错误,调试的时候应该会遇到的。就是管与IOCTL函数的定义,在linux2.6.2..版本中file_operations结构中ioctl的函数定义发生了变化,所以按照《。。。第3版》上的说明是有些出入,所有在 make moduls的时候会有这样的事情发生mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: error: unknown field 'ioctl' specified in initializer
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: warning: initialization from incompatible pointer type,相关的东西可以“unknown field 'ioctl' specified in initializer”放到网上搜,就有人回答问题。