1.我在做字符设备驱动程序(此章讲的是按键点亮led),在编译内核模块时,遇到了如下问题:
CC
[M] drivers/char/s3c24xx_leds.o
drivers/char/s3c24xx_leds.c:7:32: error: asm/arch/regs-gpio.h: No
such file or directory
drivers/char/s3c24xx_leds.c:8:26: error: asm/hardware.h: No such
file or directory
drivers/char/s3c24xx_leds.c:19: error: 'S3C2410_GPB5' undeclared
here (not in a function)
drivers/char/s3c24xx_leds.c:20: error: 'S3C2410_GPB6' undeclared
here (not in a function)
drivers/char/s3c24xx_leds.c:21: error: 'S3C2410_GPB7' undeclared
here (not in a function)
drivers/char/s3c24xx_leds.c:22: error: 'S3C2410_GPB8' undeclared
here (not in a function)
解决方法:头文件的路径不对,asm/arch/regs-gpio.h改为mach/regs-gpio
asm/hardware.h改为mach/hardware.h
2.继续编译又遇问题:
/home/pyf/linux/test/botton.c: In function
`tope_buttons_init':
/home/pyf/linux/test/botton.c:170: error: implicit declaration of
function `class_device_create'
/home/pyf/linux/test/botton.c: In function
`tope_buttons_exit':
/home/pyf/linux/test/botton.c:178: error: implicit declaration of
function `class_device_destroy'
方法: 经过查阅资料,发现创建设备节点使用了两个函数 class_create(),class_device_create(),当然在__exit()函数里,要使用class_destory()和class_device_desotry()注销创建的设备节点!
问题来了,编译了之后,发现报错error:
implicit declaration of function
'class_device_create'等几个错误。经过分析,应该是Linux内核版本不同的原因!早期的版本,使用的是上面说的两个函数,但是在2.6.29以后(我用的是2.6.32的),使用的函数则变成了
class_create()和device_create(),并且要在声明中加入#include
,因为定义这些函数是在Linux2.6.32/include/linux/device.h里面!
所以修改class_device_create
为device_create。class_device_destroy改为device_destroy经过这些修改后,驱动编译成功,就能够自动创建设备节点了!