-
Notifications
You must be signed in to change notification settings - Fork 14
xxx deleted1
**** Will be rewritten, don't use this branch
Rev. 1.0x-TC
In this version, the addresses are rebased by parameters set in the environment.
So the ADDRESS parameters below is not the real physical address.
Examples:
export DEVMEMREBASE=0xC0000000
export DEVMEMREBASEEND=0xC02FFFFF
export DEVMEMBASE=0xA0020000
devmem 0xC0123456 h
The address 0xC0123456 in the above command will be rebased to 0xA0143456.
If the given address is less than DEVMEMREBASE or greater than DEVMEMREBASEEND, it will not be rebased.
export DEVMEMREBASE=0xD0000000
export DEVMEMBASE=0xA0020000
devmem 0xC0123456 h
In the above example the address will not be rebased; access will be made at 0xC0123456.
Use the debug switch (-d) to print out the final address after rebasing.
devmem [-sw] ADDRESS [w|b|h] -- read memory and print
devmem [-sw] ADDRESS w|b|h VALUE -- write VALUE into ADDRESS
ADDRESS is a physical address: a number, like 0x12345678
VALUE is a number like 0x1234 or 42 or 0123 (octal!)
The w|b|h designate the size of the value to read or write. W is 4-bytes (int32), H is two bytes (int16), B means one byte (int8).
For reads, the size is W if not specified. For writes, the size must be specified. Letters W,B,H are not case sensitive.
In the ADDRESS and VALUE numbers, prefix 0x is recognized for hex and numbers that begin with 0 are octal (the numbers are parsed with strtoul).
The size parameter can also be moved to the 1st place:
devmem [-sw] w|b|h ADDRESS -- read memory and print
devmem [-sw] w|b|h ADDRESS VALUE -- write VALUE into ADDRESS
NOTE: It is not guaranteed that any physical address can be accessed by this program. Validity of the ADDRESS is checked by the OS. See the source of the driver of the /dev/mem device for details.
Some physical addresses are hardware registers; writing or even reading them can cause your computer/device crash or melt down or explode. You've been warned!
Reads and writes are performed as single operation - though not precisely "atomic" in thread-safety sense.
-r
- read back after write, and print
-a
- do not require correct alignment
-A
- Absolute addresses. This turns off using environment parameters to rebase the address
-d
- debug. Use this to test rebasing addresses.
-V, --version
- show version
--help
- show usage and the environment parameters used by the program
NOTE: The original devmem program does not have switches. Giving it "--help" will read from address 0.
To check whether you have this or the original version, add some bogus 2nd parameter. For example: "devmem -V -".
See examples here - except that the specified addresses will be re-based, as explained above.
TBD. Please experiment or see the source.
0 - success
Other value - parameter or runtime error (TBD)
NOTE: accessing "wrong" memory address can cause immediate exit without any error message.
Exit status needs to be checked. Use set -e
to make shell check exit status.
The utility is a single file, it does not need special installation.
Creating copies or links with different names (ex. "mem" instead of "devmem") to the executable file is ok.
The following environment variables must be set:
- DEVMEMREBASE - the value to subtract from the ADDRESS parameter, if it is greater or equal to DEVMEMREBASE value and less than DEVMEMREBASEEND.
- DEVMEMBASE - the value to add to the ADDRESS parameter after subtraction
If both DEVMEMBASE and DEVMEMREBASE are 0, the ADDRESS parameter will be used as is (no rebase will occur).
These environment variables must be set for this devmem version, unless switch -A is specified. This is to block old scripts, that must not be rebased (or not ported yet), from working with this version.
Of course, you can also pass these variables on the shell command line, or define them locally in scripts.
Runtime dependencies: only the C library (libc.so, etc.) unless built statically.
This program needs that access to /dev/mem file is enabled in the kernel. If it does not work, check the kernel config file (CONFIG_DEVMEM must be defined, etc.).
To access physical addresses > 32 bits: use mmap2 instead of mmap (or maybe build the program in 64-bit mode).