Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linux-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
linux-elphel
Commits
c859c41c
Commit
c859c41c
authored
Apr 09, 2014
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python script to read/write physical address (depends on python-mmap)
parent
bdbc90e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
mem.py
other/mem.py
+53
-0
No files found.
other/mem.py
0 → 100644
View file @
c859c41c
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013, Elphel.inc.
# configuration of the DDR-related registers
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__author__
=
"Andrey Filippov"
__copyright__
=
"Copyright 2014, Elphel, Inc."
__license__
=
"GPL"
__version__
=
"3.0+"
__maintainer__
=
"Andrey Filippov"
__email__
=
"andrey@elphel.com"
__status__
=
"Development"
import
mmap
import
sys
import
struct
PAGE_SIZE
=
4096
endian
=
"<"
# little, ">" for big
if
len
(
sys
.
argv
)
<
1
:
print
"Usage: "
,
sys
.
argv
[
0
]
+
" address [data]"
exit
(
0
)
addr
=
int
(
sys
.
argv
[
1
],
16
)
&
0xfffffffc
data
=
0
writeMode
=
len
(
sys
.
argv
)
>
2
if
(
writeMode
):
data
=
int
(
sys
.
argv
[
2
],
16
)
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
page_addr
=
addr
&
(
~
(
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
PAGE_SIZE
,
offset
=
page_addr
)
if
writeMode
:
packedData
=
struct
.
pack
(
endian
+
"L"
,
data
)
d
=
struct
.
unpack
(
endian
+
"L"
,
packedData
)[
0
]
mm
[
page_offs
:
page_offs
+
4
]
=
packedData
print
(
"0x
%08
x <== 0x
%08
x (
%
d)"
%
(
addr
,
d
,
d
))
else
:
data
=
struct
.
unpack
(
endian
+
"L"
,
mm
[
page_offs
:
page_offs
+
4
])
d
=
data
[
0
]
print
(
"0x
%08
x ==> 0x
%08
x (
%
d)"
%
(
addr
,
d
,
d
))
mm
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment