18.15 驱动程序
18.15.1 Makefile错误
ERROR 01:
make -C $(KERN_DIR) M=`pwd` modules
ANSWER 01:
上面的M=`pwd`,其中“`”为英文状态下的1前面的键,不是单引号’。
18.15.2 调试同步互斥阻塞问题
ERROR 02:
int fcntl(int fd, int cmd, ... /* arg */ );
其中fd的类型是整型,由于开始定义为unsigned int fd;导致不能实现原子操作。
ANSWER 02:
将fd定义为int fd;
18.15.3 中断函数未写return
ERROR 01:
中断函数后一定得写返回值return IRQ_HANDLED;,否则会出现如下错误
irq event 79: bogus return value a
[<c002ede8>] (dump_stack+0x0/0x14) from [<c0067844>] (__report_bad_irq+0x38/0x94)
[<c006780c>] (__report_bad_irq+0x0/0x94) from [<c00678f0>] (note_interrupt+0x50/0x240)
r4:c0364308
[<c00678a0>] (note_interrupt+0x0/0x240) from [<c006862c>] (handle_edge_irq+0x120/0x144)
……
ANSWER 01:
在中断函数后增加 return IRQ_HANDLED;
static irqreturn_t pen_down_up_irq(int irq, void *dev_id)
{ if(s3c_ts_regs->ADCDAT0 & (1<<15)){/*ADCDAT0=1 stylus up*/
printk("pen up\n");
enter_wait_pen_down_mode();
}else{
printk("pen down\n");
enter_wait_pen_up_mode();
}
return IRQ_HANDLED;}
18.15.4 增加mkdosfs命令
做块设备驱动程序实验时,使用格式化命令mkdosfs时,系统内没有安装,在嵌入式设备内增加该命令步骤如下:
首先在http://manpages.ubuntu.com/manpages/precise/man8/mkdosfs.8.html下载dosfstools压缩包;
$ tar xzf dosfstools_2.11.orig.tar.gz
.../dosfstools-2.11$ make CC=arm-linux-gcc
.../dosfstools-2.11$ cd mkdosfs/
.../mkdosfs$ ls
.../mkdosfs$ cp mkdosfs /work/nfs_root/first_fs/usr/sbin/
通过以上步骤,即可完成嵌入式设备命令的增加。
18.15.5 入口函数未写return 0
ERROR 01:
入口函数未写返回值:make后警告如下
/work/3.4.2_driver_test/fifth_drv/fifth_drv.c:152: warning: control reaches end of non-void function
在开发板装载驱动显示如下错误:
/ # insmod fifth_drv.ko
insmod: can't insert 'fifth_drv.ko': Success
ANSWER 01:
在入口函数增加返回值
return 0;
即可解决
18.15.6 出口函数卸载顺序出错
ERROR 02:
出口函数卸载顺序出错
class_destroy(fifth_class);
device_destroy(fifth_class,MKDEV(major, 0));
如果是上述顺序的话会出错,因为device_destroy对fifth_class有依赖关系,先释放的话后面会出错。
开发板卸载驱动时错误信息:
/ # insmod fifth_drv.ko
/ # rmmod fifth_drv
Unable to handle kernel NULL pointer dereference at virtual address 00000034
pgd = c3a68000
[00000034] *pgd=33a55831, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1] ARM
Modules linked in: fifth_drv(O-) [last unloaded: fifth_drv]
CPU: 0 Tainted: G O (3.4.2 #3)
PC is at sysfs_delete_link+0x18/0x2c
LR is at device_del+0x70/0x1b0
…
[<c00df43c>] (sysfs_delete_link+0x18/0x2c) from [<c01bf73c>] (device_del+0x70/0x1b0)
[<c01bf73c>] (device_del+0x70/0x1b0) from [<c01bf888>] (device_unregister+0xc/0x18)
[<c01bf888>] (device_unregister+0xc/0x18) from [<c01bf8c4>] (device_destroy+0x30/0x3c)
[<c01bf8c4>] (device_destroy+0x30/0x3c) from [<c005770c>] (sys_delete_module+0x1f0/0x250)
[<c005770c>] (sys_delete_module+0x1f0/0x250) from [<c00152a0>] (ret_fast_syscall+0x0/0x2c)
Code: 05900018 01a0100c 0a000004 e5900018 (e1d033b4)
---[ end trace 0b10d0445267ba1e ]---
Segmentation fault
ANSWER 02:
在出口函数改变顺序如下:
device_destroy(fifth_class,MKDEV(major, 0));
class_destroy(fifth_class);
按上述顺序即可解决
-------------------------------------------
文中所用软件在试用期内。若涉及商业用途或想有更好的用户体验,建议购买正版!
如果觉得这篇文章对您有小小帮助的话,记得在右下角点个“推荐”哦,博主在此万分感谢!
打赏请您扫下面二维码!谢谢!