* mmap /dev/mem in python
@ 2009-10-20 22:06 Brett Graham
2009-10-20 22:17 ` Tony Lindgren
2009-10-20 23:18 ` Paul Walmsley
0 siblings, 2 replies; 8+ messages in thread
From: Brett Graham @ 2009-10-20 22:06 UTC (permalink / raw)
To: linux-omap
I'm trying to mmap /dev/mem in python to access various registers on a
gumstix overo (with an omap 3530 processor). Here is the code I'm
using (as a minimal example):
----------------------------
import os, mmap
MAP_MASK = mmap.PAGESIZE - 1
addr = (see below)
f = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
mmap.PROT_READ, offset=addr & ~MAP_MASK)
m.seek(addr & MAP_MASK)
c = m.read_byte()
print c
m.close()
os.close(f)
----------------------------
If I use: addr = 0x48002178 everything works swimmingly. However, if I
use: addr = 0x48088024 (or all the addresses I've tried > 0x48044000)
I get the following error
Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
Bus error
and python crashes. I'm basing the mmap flags and options off of
devmem2.c. If I remove the O_SYNC flag from the os.open command, I can
read and write to registers fine, but randomly I will get the
Unhandled fault error and things will not work correctly.
Am I using the right command to write to the omap registers? should I
be using the O_SYNC flag? Any ideas where these errors are coming
from?
Thanks in advance for your help.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: mmap /dev/mem in python
2009-10-20 22:06 mmap /dev/mem in python Brett Graham
@ 2009-10-20 22:17 ` Tony Lindgren
[not found] ` <47b23c40910201615l1b1ab25ewd1dcae6b27728397@mail.gmail.com>
2009-10-20 23:18 ` Paul Walmsley
1 sibling, 1 reply; 8+ messages in thread
From: Tony Lindgren @ 2009-10-20 22:17 UTC (permalink / raw)
To: Brett Graham; +Cc: linux-omap
* Brett Graham <graham@rowland.harvard.edu> [091020 15:06]:
> I'm trying to mmap /dev/mem in python to access various registers on a
> gumstix overo (with an omap 3530 processor). Here is the code I'm
> using (as a minimal example):
> ----------------------------
> import os, mmap
> MAP_MASK = mmap.PAGESIZE - 1
> addr = (see below)
>
> f = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
> m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
> mmap.PROT_READ, offset=addr & ~MAP_MASK)
> m.seek(addr & MAP_MASK)
> c = m.read_byte()
> print c
> m.close()
> os.close(f)
> ----------------------------
>
> If I use: addr = 0x48002178 everything works swimmingly. However, if I
> use: addr = 0x48088024 (or all the addresses I've tried > 0x48044000)
> I get the following error
>
> Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
> Bus error
>
> and python crashes. I'm basing the mmap flags and options off of
> devmem2.c. If I remove the O_SYNC flag from the os.open command, I can
> read and write to registers fine, but randomly I will get the
> Unhandled fault error and things will not work correctly.
>
> Am I using the right command to write to the omap registers? should I
> be using the O_SYNC flag? Any ideas where these errors are coming
> from?
Sounds like you need to enable ick and fck for the device you're trying
to read.
Tony
^ permalink raw reply [flat|nested] 8+ messages in thread
* Fwd: mmap /dev/mem in python
[not found] ` <47b23c40910201615l1b1ab25ewd1dcae6b27728397@mail.gmail.com>
@ 2009-10-20 23:16 ` Brett Graham
2009-10-20 23:26 ` Paul Walmsley
0 siblings, 1 reply; 8+ messages in thread
From: Brett Graham @ 2009-10-20 23:16 UTC (permalink / raw)
To: linux-omap
If I run the following commads:
devmem2 0x48004a40 w 0x0000038a # select 32kHz clock
devmem2 0x48004a10 w 0x03007052 # enable iclk for gpt11
devmem2 0x48004a00 w 0x03007000 # enable fclk for gpt11
which all run sensibly and alter the registers, then I try to previous
minimum example on address 0x48088024 (TCLK for gpt11) I get the
following error:
Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
Bus error
What puzzles me is that when I use devmem2 to read or write to the
same register, everything works fine.
On Tue, Oct 20, 2009 at 6:17 PM, Tony Lindgren <tony@atomide.com> wrote:
> * Brett Graham <graham@rowland.harvard.edu> [091020 15:06]:
>> I'm trying to mmap /dev/mem in python to access various registers on a
>> gumstix overo (with an omap 3530 processor). Here is the code I'm
>> using (as a minimal example):
>> ----------------------------
>> import os, mmap
>> MAP_MASK = mmap.PAGESIZE - 1
>> addr = (see below)
>>
>> f = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
>> m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
>> mmap.PROT_READ, offset=addr & ~MAP_MASK)
>> m.seek(addr & MAP_MASK)
>> c = m.read_byte()
>> print c
>> m.close()
>> os.close(f)
>> ----------------------------
>>
>> If I use: addr = 0x48002178 everything works swimmingly. However, if I
>> use: addr = 0x48088024 (or all the addresses I've tried > 0x48044000)
>> I get the following error
>>
>> Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
>> Bus error
>>
>> and python crashes. I'm basing the mmap flags and options off of
>> devmem2.c. If I remove the O_SYNC flag from the os.open command, I can
>> read and write to registers fine, but randomly I will get the
>> Unhandled fault error and things will not work correctly.
>>
>> Am I using the right command to write to the omap registers? should I
>> be using the O_SYNC flag? Any ideas where these errors are coming
>> from?
>
> Sounds like you need to enable ick and fck for the device you're trying
> to read.
>
> Tony
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: mmap /dev/mem in python
2009-10-20 22:06 mmap /dev/mem in python Brett Graham
2009-10-20 22:17 ` Tony Lindgren
@ 2009-10-20 23:18 ` Paul Walmsley
1 sibling, 0 replies; 8+ messages in thread
From: Paul Walmsley @ 2009-10-20 23:18 UTC (permalink / raw)
To: Brett Graham; +Cc: linux-omap
On Tue, 20 Oct 2009, Brett Graham wrote:
> If I use: addr = 0x48002178 everything works swimmingly. However, if I
> use: addr = 0x48088024 (or all the addresses I've tried > 0x48044000)
> I get the following error
>
> Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
> Bus error
0x40020024 != 0x48088024 ? That's probably not the kernel's fault.
- Paul
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Fwd: mmap /dev/mem in python
2009-10-20 23:16 ` Fwd: " Brett Graham
@ 2009-10-20 23:26 ` Paul Walmsley
2009-10-21 0:01 ` Brett Graham
0 siblings, 1 reply; 8+ messages in thread
From: Paul Walmsley @ 2009-10-20 23:26 UTC (permalink / raw)
To: Brett Graham; +Cc: linux-omap
On Tue, 20 Oct 2009, Brett Graham wrote:
> If I run the following commads:
> devmem2 0x48004a40 w 0x0000038a # select 32kHz clock
> devmem2 0x48004a10 w 0x03007052 # enable iclk for gpt11
> devmem2 0x48004a00 w 0x03007000 # enable fclk for gpt11
>
> which all run sensibly and alter the registers, then I try to previous
> minimum example on address 0x48088024 (TCLK for gpt11) I get the
> following error:
> Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
> Bus error
>
> What puzzles me is that when I use devmem2 to read or write to the
> same register, everything works fine.
Consider running strace on devmem2 and comparing it to the strace of your
Python code? That should show you any differences. If devmem2 works,
it's unlikely to be a kernel problem.
- Paul
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Fwd: mmap /dev/mem in python
2009-10-20 23:26 ` Paul Walmsley
@ 2009-10-21 0:01 ` Brett Graham
2009-10-21 0:27 ` Paul Walmsley
0 siblings, 1 reply; 8+ messages in thread
From: Brett Graham @ 2009-10-21 0:01 UTC (permalink / raw)
To: Paul Walmsley; +Cc: linux-omap
It's good to at least know that this doesn't seem to be a kernel
issue, and thanks for the strace advice (I am new to this level of
linux development). Here is the truncated output for devmem and the
minimal example:
--- devmem ---
open("/dev/mem", O_RDWR|O_SYNC) = 3
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x4001f000
write(1, "/dev/mem opened.\n", 17) = 17
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) = 0x40020000
write(1, "Memory mapped at address 0x40020"..., 37) = 37
write(1, "Value at address 0x48088024 (0x4"..., 46) = 46
munmap(0x40020000, 4096) = 0
close(3) = 0
io_submit(0, 0, 0xfbad2088 <unfinished ... exit status 0>
Process 1635 detached
--minimal python example--
open("/dev/mem", O_RDWR|O_SYNC|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFCHR|0640, st_rdev=makedev(1, 1), ...}) = 0
dup(3) = 4
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) = 0x40020000
--- SIGBUS (Bus error) @ 0 (0) ---
+++ killed by SIGBUS +++
Process 1633 detached
It looks like python decided to add a O_LARGEFILE and duplicate the
file descriptor. I'm still not sure what's going on here that's
causing the problem as both mmap2 calls are identical.
I don't mean to bombard this list with a problem that isn't related to
the kernel, so I'll post this to a python list somewhere. Thanks a
million for your help so far, this is driving me nutty! Also if any
more info would help just let me know.
On Tue, Oct 20, 2009 at 7:26 PM, Paul Walmsley <paul@pwsan.com> wrote:
> On Tue, 20 Oct 2009, Brett Graham wrote:
>
>> If I run the following commads:
>> devmem2 0x48004a40 w 0x0000038a # select 32kHz clock
>> devmem2 0x48004a10 w 0x03007052 # enable iclk for gpt11
>> devmem2 0x48004a00 w 0x03007000 # enable fclk for gpt11
>>
>> which all run sensibly and alter the registers, then I try to previous
>> minimum example on address 0x48088024 (TCLK for gpt11) I get the
>> following error:
>> Unhandled fault: external abort on non-linefetch (0x1018) at 0x40020024
>> Bus error
>>
>> What puzzles me is that when I use devmem2 to read or write to the
>> same register, everything works fine.
>
> Consider running strace on devmem2 and comparing it to the strace of your
> Python code? That should show you any differences. If devmem2 works,
> it's unlikely to be a kernel problem.
>
>
> - Paul
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Fwd: mmap /dev/mem in python
2009-10-21 0:01 ` Brett Graham
@ 2009-10-21 0:27 ` Paul Walmsley
2009-10-21 12:20 ` Brett Graham
0 siblings, 1 reply; 8+ messages in thread
From: Paul Walmsley @ 2009-10-21 0:27 UTC (permalink / raw)
To: Brett Graham; +Cc: linux-omap
On Tue, 20 Oct 2009, Brett Graham wrote:
> --minimal python example--
> open("/dev/mem", O_RDWR|O_SYNC|O_LARGEFILE) = 3
> fstat64(3, {st_mode=S_IFCHR|0640, st_rdev=makedev(1, 1), ...}) = 0
> dup(3) = 4
> mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) = 0x40020000
> --- SIGBUS (Bus error) @ 0 (0) ---
> +++ killed by SIGBUS +++
> Process 1633 detached
Your script:
>> m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
>> mmap.PROT_READ, offset=addr & ~MAP_MASK)
>> m.seek(addr & MAP_MASK)
So the mmap() is working fine, based on the output above...
>> c = m.read_byte()
... but the above line is going to fail. GPTIMER registers need 16-
or 32-bit accesses[1].
- Paul
1. OMAP34xx TRM 16.3.2:
"CAUTION
The GP timer registers are limited to 32-bit and 16-bit data accesses;
8-bit access is not allowed and can corrupt the register content."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Fwd: mmap /dev/mem in python
2009-10-21 0:27 ` Paul Walmsley
@ 2009-10-21 12:20 ` Brett Graham
0 siblings, 0 replies; 8+ messages in thread
From: Brett Graham @ 2009-10-21 12:20 UTC (permalink / raw)
To: Paul Walmsley; +Cc: linux-omap
Doh! Thank you! This looks to be the problem, I've made some changes
to the code (calling mmap.read(4) rather than mmap.read_bye()) and
everything seems to be working.
On Tue, Oct 20, 2009 at 8:27 PM, Paul Walmsley <paul@pwsan.com> wrote:
> On Tue, 20 Oct 2009, Brett Graham wrote:
>
>> --minimal python example--
>> open("/dev/mem", O_RDWR|O_SYNC|O_LARGEFILE) = 3
>> fstat64(3, {st_mode=S_IFCHR|0640, st_rdev=makedev(1, 1), ...}) = 0
>> dup(3) = 4
>> mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) = 0x40020000
>> --- SIGBUS (Bus error) @ 0 (0) ---
>> +++ killed by SIGBUS +++
>> Process 1633 detached
>
> Your script:
>
>>> m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
>>> mmap.PROT_READ, offset=addr & ~MAP_MASK)
>>> m.seek(addr & MAP_MASK)
>
> So the mmap() is working fine, based on the output above...
>
>>> c = m.read_byte()
>
> ... but the above line is going to fail. GPTIMER registers need 16-
> or 32-bit accesses[1].
>
>
> - Paul
>
> 1. OMAP34xx TRM 16.3.2:
>
> "CAUTION
> The GP timer registers are limited to 32-bit and 16-bit data accesses;
> 8-bit access is not allowed and can corrupt the register content."
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-10-21 12:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-20 22:06 mmap /dev/mem in python Brett Graham
2009-10-20 22:17 ` Tony Lindgren
[not found] ` <47b23c40910201615l1b1ab25ewd1dcae6b27728397@mail.gmail.com>
2009-10-20 23:16 ` Fwd: " Brett Graham
2009-10-20 23:26 ` Paul Walmsley
2009-10-21 0:01 ` Brett Graham
2009-10-21 0:27 ` Paul Walmsley
2009-10-21 12:20 ` Brett Graham
2009-10-20 23:18 ` Paul Walmsley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox