GithubHelp home page GithubHelp logo

pydevmem's Introduction

Python DevMem

This is designed primarily for use with accessing /dev/mem on OMAP platforms. It should work on other platforms and work to mmap() files rather then just /dev/mem, but these use cases aren't well tested.

All file accesses are aligned to DevMem.word bytes, which is 4 bytes on ARM platforms to avoid data abort faults when accessing peripheral registers.

Usage

Usage: devmem.py [options]

Options:
  -h, --help            show this help message and exit
  -r ADDR, --read=ADDR  read a value
  -w ADDR VALUE, --write=ADDR VALUE
						write a value
  -n NUM, --num=NUM     number of words to read
  -s WORD_SIZE, --word-size=WORD_SIZE
						size of word when displayed
  -m FILE, --mmap=FILE  file to open with mmap()
  -v                    provide more information regarding operation
  -d                    provide debugging information

Speed

Initial testing on a BeagleBoard-xM (Cortex-A8 in a TI DM3730) shows that starting up the python interpreter is pretty slow:

# time (echo | python)

real    0m0.859s
user    0m0.750s
sys     0m0.102s

# time python ./pydevmem.py -r 0x4830a204 -n 8
0x4830a204:   1b89102f  00000000  00000000  000000f0
0x4830a214:   cafeb891  0c030016  015739eb  1ff00000

real    0m1.109s
user    0m0.977s
sys     0m0.133s

# time python -S ./pydevmem.py -r 0x4830a204 -n 8
0x4830a204:   1b89102f  00000000  00000000  000000f0
0x4830a214:   cafeb891  0c030016  015739eb  1ff00000

real    0m0.659s
user    0m0.602s
sys     0m0.047s

# time python -S ./pydevmem.pyc -r 0x4830a204 -n 8
0x4830a204:   1b89102f  00000000  00000000  000000f0
0x4830a214:   cafeb891  0c030016  015739eb  1ff00000

real    0m0.647s
user    0m0.508s
sys     0m0.133s

System information for those tests:

Linux omap 3.0.6-x3 #1 SMP Wed Oct 5 07:19:24 UTC 2011 armv7l GNU/Linux

python              2.7.2-7ubuntu2
python-configobj    4.7.2+ds-3
python-minimal      2.7.2-7ubuntu2
python2.7           2.7.2-5ubuntu1
python2.7-minimal   2.7.2-5ubuntu1

Something needs to be sped up to make python start-up in a reasonable amount of time.

pydevmem's People

Contributors

bnewbold avatar kylemanna avatar lechuck42 avatar t-firefly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydevmem's Issues

Lack of support for 64bit addresses.

In most modern systems nowadays, wether intel or ARM based, the physical and kernel virtual addresses are 64 bits, and mostly towards the top 4GB half.
When trying any such address in devmem.py, the following happens:

$ sudo python -S ./devmem.py -r 0xffffe00000000000 -n 1
Traceback (most recent call last):
  File "./devmem.py", line 279, in <module>
    sys.exit(main())
  File "./devmem.py", line 257, in main
    debug=options.debug)
  File "./devmem.py", line 123, in __init__
    offset=self.base_addr)
OverflowError: Python int too large to convert to C long

The C type long long, or the more standardized C99 type [u]int64_t should be fine.

I am getting ValueError: seek out of range with devmem.py.

for am437x soc i am using pydevmem in my custom script to write registers with base address 0x44df8800 and offset 540h.

code:
**object1=devmem.DevMem(0x44df8800,0x100,"/dev/mem",0)
object1.write(0x540,[0x02])

I am getting below error.
File "counter_register.py", line 85, in
counter_write()
File "counter_register.py", line 29, in counter_write
object1.write(0x540,[0x02])
File "/home/root/devmem.py", line 175, in write
mem.seek(virt_base_addr + offset)
ValueError: seek out of range

First i used devmem.py for am335x soc and using the same script to write register with base address 0x44e00000 and offset 0x88, my custom script works fine with out any error.

working code:
object1=devmem.DevMem(0x44e00000,0x100,"/dev/mem",0)
object1.write(0x88,[0x02])

write() seeks offset twice

If I try to work with address 0x40, due to page alignment we end up mmapping the data starting at 0x0 and then base_addr_offset is calculated to be 0x40.

Reading seems to be working OK, but I think there is a bug in the write path. The 0x40 offset is accounted for twice and the seek ends up going to the wrong place.

The code flow is:

        # Compensate for the base_address not being what the user requested
        offset += self.base_addr_offset

So offset has now accounted for this.

Then:

        # Seek to the aligned offset
        virt_base_addr = self.base_addr_offset & self.mask

So virt_base_addr has also accounted for this.

Then:

        mem.seek(virt_base_addr + offset)

Both are added together, we have accounted for the 0x40 offset twice...

read performs 2 access cycles

I tested this code on a FPGA board and observed 2 access cycles on the system bus.
The two access cycles are very close one after another, from which i would deduce, they are executed by the same C code.
If the two accesses were requested by separate lines of Python code, I would expect to see a longer pause between the two.

Create setup.py

Could you provide a proper setup.py in order to create the installer for pydevmem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.