二、测试LED驱动的APP程序
/*******************************app_leds.c***************************************
*
*
**********************************************************************************/
ifneq ($(KERNELRELEASE),)
obj-m := mini2440_leds.o
else
KDIR:=/home/kernel/linux-2.6.32.2
all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul*
endif
三、遇到的问题
1、
[root@localhost LED]# make
make -C /home/kernel/linux-2.6.32.2 M=/home/nfsshare/root_qtopia/Drive/LED modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/home/kernel/linux-2.6.32.2'
CC [M] /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:29: error: 'S3C2410_GPB5' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:30: error: 'S3C2410_GPB6' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:31: error: 'S3C2410_GPB7' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:32: error: 'S3C2410_GPB8' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: 'S3C2410_GPB5_OUTP' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: initializer element is not constant
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:36: error: (near initialization for 'led_cfg_table[0]')
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: 'S3C2410_GPB6_OUTP' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: initializer element is not constant
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:37: error: (near initialization for 'led_cfg_table[1]')
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: 'S3C2410_GPB7_OUTP' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: initializer element is not constant
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:38: error: (near initialization for 'led_cfg_table[2]')
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: 'S3C2410_GPB8_OUTP' undeclared here (not in a function)
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: initializer element is not constant
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:39: error: (near initialization for 'led_cfg_table[3]')
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'sbc2440_leds_ioctl':
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:54: error: implicit declaration of function 's3c2410_gpio_setpin'
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'dev_init':
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:80: error: implicit declaration of function 's3c2410_gpio_cfgpin'
make[2]: *** [/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o] 错误 1
make[1]: *** [_module_/home/nfsshare/root_qtopia/Drive/LED] 错误 2
make[1]: Leaving directory `/home/kernel/linux-2.6.32.2'
make: *** [all] 错误 2
错误原因:内核版本不对,没有S3C2410_GPB5的类型定义 需要修改为S3C2410_GPB(5)
内核版本定义如下:
/* arch/arm/mach-s3c2410/include/mach/gpio-nrs.h
*
* Copyright (c) 2008 Simtec Electronics
* http://armlinux.simtec.co.uk/
* Ben Dooks <ben@simtec.co.uk>
*
* S3C2410 - GPIO bank numbering
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __MACH_GPIONRS_H
#define __MACH_GPIONRS_H
#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
#define S3C2410_GPIO_BANKA (32*0)
#define S3C2410_GPIO_BANKB (32*1)
#define S3C2410_GPIO_BANKC (32*2)
#define S3C2410_GPIO_BANKD (32*3)
#define S3C2410_GPIO_BANKE (32*4)
#define S3C2410_GPIO_BANKF (32*5)
#define S3C2410_GPIO_BANKG (32*6)
#define S3C2410_GPIO_BANKH (32*7)
/* GPIO bank sizes */A
#define S3C2410_GPIO_A_NR (32)
#define S3C2410_GPIO_B_NR (32)
#define S3C2410_GPIO_C_NR (32)
#define S3C2410_GPIO_D_NR (32)
#define S3C2410_GPIO_E_NR (32)
#define S3C2410_GPIO_F_NR (32)
#define S3C2410_GPIO_G_NR (32)
#define S3C2410_GPIO_H_NR (32)
#if CONFIG_S3C_GPIO_SPACE != 0
#error CONFIG_S3C_GPIO_SPACE cannot be zero at the moment
#endif
#define S3C2410_GPIO_NEXT(__gpio) \
((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 0)
#ifndef __ASSEMBLY__
enum s3c_gpio_number {
S3C2410_GPIO_A_START = 0,
S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A),
S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),
S3C2410_GPIO_D_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_C),
S3C2410_GPIO_E_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_D),
S3C2410_GPIO_F_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_E),
S3C2410_GPIO_G_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_F),
S3C2410_GPIO_H_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_G),
};
#endif /* __ASSEMBLY__ */
/* S3C2410 GPIO number definitions. */
#define S3C2410_GPA(_nr) (S3C2410_GPIO_A_START + (_nr))
#define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))
#define S3C2410_GPC(_nr) (S3C2410_GPIO_C_START + (_nr))
#define S3C2410_GPD(_nr) (S3C2410_GPIO_D_START + (_nr))
#define S3C2410_GPE(_nr) (S3C2410_GPIO_E_START + (_nr))
#define S3C2410_GPF(_nr) (S3C2410_GPIO_F_START + (_nr))
#define S3C2410_GPG(_nr) (S3C2410_GPIO_G_START + (_nr))
#define S3C2410_GPH(_nr) (S3C2410_GPIO_H_START + (_nr))
/* compatibility until drivers can be modified */
//宏定义了GPA和GPE
#define S3C2410_GPA0 S3C2410_GPA(0)
#define S3C2410_GPA1 S3C2410_GPA(1)
#define S3C2410_GPA3 S3C2410_GPA(3)
#define S3C2410_GPA7 S3C2410_GPA(7)
#define S3C2410_GPE0 S3C2410_GPE(0)
#define S3C2410_GPE1 S3C2410_GPE(1)
#define S3C2410_GPE2 S3C2410_GPE(2)
#define S3C2410_GPE3 S3C2410_GPE(3)
#define S3C2410_GPE4 S3C2410_GPE(4)
#define S3C2410_GPE5 S3C2410_GPE(5)
#define S3C2410_GPE6 S3C2410_GPE(6)
#define S3C2410_GPE7 S3C2410_GPE(7)
#define S3C2410_GPE8 S3C2410_GPE(8)
#define S3C2410_GPE9 S3C2410_GPE(9)
#define S3C2410_GPE10 S3C2410_GPE(10)
#define S3C2410_GPH10 S3C2410_GPH(10)
#endif /* __MACH_GPIONRS_H */
2、问题二
[root@localhost LED]# make
make -C /home/kernel/linux-2.6.32.2 M=/home/nfsshare/root_qtopia/Drive/LED modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/home/kernel/linux-2.6.32.2'
CC [M] /home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'sbc2440_leds_ioctl':
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:54: error: implicit declaration of function 's3c2410_gpio_setpin'
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c: In function 'dev_init':
/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.c:80: error: implicit declaration of function 's3c2410_gpio_cfgpin'
make[2]: *** [/home/nfsshare/root_qtopia/Drive/LED/mini2440_leds.o] 错误 1
make[1]: *** [_module_/home/nfsshare/root_qtopia/Drive/LED] 错误 2
make[1]: Leaving directory `/home/kernel/linux-2.6.32.2'
原因:没有声明s3c2410_gpio_setpin和s3c2410_gpio_cfpin
j解决方法:调价头文件#include<linux/gpio.h>
3、问题三
在securecat中加载mini2440.ko文件,出现File existed
原因:使用的内核已经编译了led驱动模块,因此报错
解决:重新编译内核模块,在make menuconfig中不选择led选项
三、测设驱动程序
驱动设备的名字为:leds
看驱动设备:cat /proc/devices ls /dev/leds
测试结果:insmod mini2440_leds.ko
rmmod mini2440_leds
lsmod 显示动态加载的
