我写了一个很简单的字符驱动,在用open系统调用打开设设备文件时出错
驱动安装#insmod uart.ko //字装之后在/proc/devices下面能看到252 uart 字符设备。
用#mknod /dev/uart c 252 0 在/dev/下面创建了设备节点。
我的程序就出错在open系统调用:fd = open("/dev/uart",O_RDONLY); //我试过把这行给注释掉,这样就没有错了;我不能理解:为什么我创建了设备节点却还是在open时出错了,请高手们指点下!
下面是在运行应用程序后打印出的oops消息:
[root@FriendlyARM app]# ./hello
open start!Unable to handle kernel NULL pointer dereference at virtual address 1
pgd = cd610000
[00000001] *pgd=5d60c831, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1] PREEMPT
last sysfs file: /sys/block/mmcblk0/dev
Modules linked in: uart fa_cpu_pfn(P)
CPU: 0 Tainted: P (2.6.38-FriendlyARM #13)
PC is at chrdev_open+0xe0/0x190
LR is at chrdev_open+0xc8/0x190
pc : [<c01e4e88>] lr : [<c01e4e70>] psr: 20000013
sp : ccfcbe58 ip : 22222222 fp : cd575000
r10: cd15ea80 r9 : c01e4da8 r8 : 00000000
r7 : 00000000 r6 : cd65de88 r5 : cd60bdc0 r4 : cd15ea80
r3 : 00000001 r2 : ccfcbe50 r1 : c0193cd8 r0 : 00000000
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 00c5387d Table: 5d610008 DAC: 00000015
Process hello (pid: 1122, stack limit = 0xccfca268)
Stack: (0xccfcbe58 to 0xccfcc000)
be40: cd15ea80 00000000
be60: c051c634 00000000 cd6b0280 cd20cbd0 cd60bdc0 c01e031c ccfcbee4 00000000
be80: 00000000 00000000 00000024 ccfca000 40247220 c01ed194 ccfcbee4 00000000
bea0: 00000000 00000101 ccfcbee4 00000024 00000000 c01ed610 00000001 00000001
bec0: c07334e0 00000000 ccfcbee0 ffffff9c 00000000 00000001 ccfcbeec c0183194
bee0: c0787e58 cd6b0280 cd20cbd0 c01a1548 00000002 00000000 00000000 cd019900
bf00: 00000000 cd15ea80 00000101 00000004 00000001 00000000 0000000c 00000000
bf20: cd47d6e8 00000000 00000001 00000000 cd67c624 00000000 00000001 00000001
bf40: 00000000 00000000 cd67c608 cd67c600 befefcf4 c0517474 cd67c608 00000003
bf60: ffffff9c cd575000 00000000 00000000 ccfca000 40247220 befefcf4 c01e1144
bf80: 00000000 00008618 00000000 00000000 00000000 00000005 c0172788 ccfca000
bfa0: 00000000 c01725e0 00000000 00000000 00008618 00000000 40247220 000084d0
bfc0: 00000000 00000000 00000000 00000005 00000000 00000000 40040000 befefcf4
bfe0: 00000000 befefce8 000084f0 401cf43c 60000010 00008618 00000000 00000000
[<c01e4e88>] (chrdev_open+0xe0/0x190) from [<c01e031c>] (__dentry_open.clone.12)
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_ope)
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x5)
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe)
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x)
Code: e5963028 e3530000 01a08007 0a000018 (e5938000)
one_wire_status: 4
---[ end trace 865c88d55446bd44 ]---
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = c0004000
[00000000] *pgd=00000000
Internal error: Oops: 80000007 [#2] PREEMPT
last sysfs file: /sys/block/mmcblk0/dev
Modules linked in: uart fa_cpu_pfn(P)
CPU: 0 Tainted: P D (2.6.38-FriendlyARM #13)
PC is at 0x0
LR is at _raw_spin_unlock_irqrestore+0x18/0x38
pc : [<00000000>] lr : [<c0517444>] psr: 600001b3
sp : ccfcbc5c ip : cd459c20 fp : 00000001
r10: 0000000b r9 : cd459c18 r8 : 00000000
r7 : 00000462 r6 : 00040002 r5 : 00000000 r4 : 00000011
r3 : 00000000 r2 : ccfcbc38 r1 : 20000193 r0 : 00000011
Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA Thumb Segment user
Control: 00c5387d Table: 5d610008 DAC: 00000015
Process hello (pid: 1122, stack limit = 0xccfca268)
Stack: (0xccfcbc5c to 0xccfcc000)
bc40: 00000002
bc60: cd459c50 00000000 ccfcbc94 c0180264 c0180208 cd459c20 c07242f0 00000000
bc80: 00000001 00000017 00000001 00000001 ccfcbca4 c0183194 20000113 c07242f0
bca0: cd459e80 00000001 00000001 00000001 ccfcbcc4 c0183194 00000001 00000001
bcc0: ccfcbcd4 cd459c20 00000011 ccfcbce0 00000000 cd459d18 cd459d18 c018a2cc
bce0: ccfcbce0 ccfcbce0 ccfcbd10 ccfcbe10 cd459c20 ccfca268 00000000 00000017
bd00: 00010000 cd6198f4 cd575000 c0176284 ccfca268 0000000b 00000001 00000017
bd20: cd6198c0 ccfcbe10 00000000 c0178bc8 cd459c20 00000001 ccfcbe10 cd6198c0
bd40: 00000017 c0178dc0 00000001 00000017 00000017 00000007 00000001 ccfcbe10
bd60: c071f50c 20000113 cd15ea80 c0168218 00000004 00000000 20000193 00000000
bd80: cd459c20 00000000 ccfcbdac c018343c c074c33c 20000193 ccef2144 ccef2150
bda0: 00000001 00000000 ccfcbdd4 c017e2fc 00000000 ccef2140 60000113 00000001
bdc0: 00000001 00000004 00000001 00000001 ccfcbde4 c0183194 c072f0e8 60000013
bde0: ffffffff c051637c 22222222 22222222 00000001 00000001 ffffffff ccfcbe44
be00: cd65de88 00000000 00000000 c01721cc 00000000 c0193cd8 ccfcbe50 00000001
be20: cd15ea80 cd60bdc0 cd65de88 00000000 00000000 c01e4da8 cd15ea80 cd575000
be40: 22222222 ccfcbe58 c01e4e70 c01e4e88 20000013 ffffffff cd15ea80 00000000
be60: c051c634 00000000 cd6b0280 cd20cbd0 cd60bdc0 c01e031c ccfcbee4 00000000
be80: 00000000 00000000 00000024 ccfca000 40247220 c01ed194 ccfcbee4 00000000
bea0: 00000000 00000101 ccfcbee4 00000024 00000000 c01ed610 00000001 00000001
bec0: c07334e0 00000000 ccfcbee0 ffffff9c 00000000 00000001 ccfcbeec c0183194
bee0: c0787e58 cd6b0280 cd20cbd0 c01a1548 00000002 00000000 00000000 cd019900
bf00: 00000000 cd15ea80 00000101 00000004 00000001 00000000 0000000c 00000000
bf20: cd47d6e8 00000000 00000001 00000000 cd67c624 00000000 00000001 00000001
bf40: 00000000 00000000 cd67c608 cd67c600 befefcf4 c0517474 cd67c608 00000003
bf60: ffffff9c cd575000 00000000 00000000 ccfca000 40247220 befefcf4 c01e1144
bf80: 00000000 00008618 00000000 00000000 00000000 00000005 c0172788 ccfca000
bfa0: 00000000 c01725e0 00000000 00000000 00008618 00000000 40247220 000084d0
bfc0: 00000000 00000000 00000000 00000005 00000000 00000000 40040000 befefcf4
bfe0: 00000000 befefce8 000084f0 401cf43c 60000010 00008618 00000000 00000000
[<c0517444>] (_raw_spin_unlock_irqrestore+0x18/0x38) from [<cd459c50>] (0xcd459)
Code: bad PC value
---[ end trace 865c88d55446bd45 ]---
Fixing recursive fault but reboot is needed!
one_wire_status: 4
BUG: scheduling while atomic: hello/1122/0x00000002
Modules linked in: uart fa_cpu_pfn(P)
[<c0177c44>] (unwind_backtrace+0x0/0xe4) from [<c0514da0>] (schedule+0x68/0x370)
[<c0514da0>] (schedule+0x68/0x370) from [<c0189ea8>] (do_exit+0xc8/0x5e4)
[<c0189ea8>] (do_exit+0xc8/0x5e4) from [<c0176284>] (die+0x190/0x1c0)
[<c0176284>] (die+0x190/0x1c0) from [<c0178bc8>] (__do_kernel_fault+0x64/0x84)
[<c0178bc8>] (__do_kernel_fault+0x64/0x84) from [<c0178dc0>] (do_page_fault+0x1)
one_wire_status: 2
[<c0178dc0>] (do_page_fault+0x1d8/0x1f4) from [<c01682b4>] (do_PrefetchAbort+0x)
[<c01682b4>] (do_PrefetchAbort+0x34/0x98) from [<c0172350>] (__pabt_svc+0x50/0x)
one_wire_status: 2
Exception stack(0xccfcbc10 to 0xccfcbc58)
bc00: 00000011 20000193 ccfcbc38 00000000
bc20: 00000011 00000000 00040002 00000462 00000000 cd459c18 0000000b 00000001
one_wire_status: 2
bc40: cd459c20 ccfcbc5c c0517444 00000000 600001b3 ffffffff
[<c0172350>] (__pabt_svc+0x50/0xa0) from [<c0517444>] (_raw_spin_unlock_irqrest)
[<c0517444>] (_raw_spin_unlock_irqrestore+0x18/0x38) from [<cd459c50>] (0xcd459)
one_wire_status: 3
[解决办法]
跟到chrdev_open里面查是什么地方出错的
[解决办法]
你可以把源码提出来,初步看来是内核运行遇到了空指针的错误,但具体还是要看代码
[解决办法]
看看你驱动程序里的open函数,基本可以肯定是空指针引用造成的
[解决办法]
是怎么解决的?
[解决办法]
贴代码
[解决办法]
难道没有返回值 还是return 1 当成了 return 0?
[解决办法]
应该是你静态指定的设备号有问题,你试试动态申请设备号看行不行?
[解决办法]
问个题外话。为什么Makefile里面要用obj-m?
[解决办法]
我试过了
static int uart_open(struct inode * inode, struct file *filp)
{
rGPFCON = (rGPFCON & ~(0x0fU<<28))
[解决办法]
(0x5U<<28);
rGPFPUD = (rGPFPUD & ~(0x0fU<<28))
[解决办法]
(0xaU<<28);
return 0;
}
代码里面的内容有问题 我也不知道你想干嘛 但是把内容屏蔽掉就可以了
[解决办法]
换个设备号试试 看看是不是设备号重了
[解决办法]
同意14楼. 先把uart_open函数里面的内容去掉,加一个printk打印。 如果该函数执行正常,
那么应用层的open就是正确的。 (因为你uart_open里面那几句有可能有错~~)
这样先排除一个问题。
我也注意到你是动态申请设备号的,dev_t dev = MKDEV(uart_major,0);
我以前写的都比较偷懒,使用的旧版本的注册方式,新的还没用过,你可以试下旧的。
我空间里GPIO模拟MDC/MDIO的那个帖子里,应该有注册部分的。
[解决办法]
访问物理地址或者物理端口是有固定的操作方式的。参考
Communicating with Hardware
[解决办法]
if(result<0)
return result;
}
这是LDD3中的流程
[解决办法]