10

For context, programming a driver to interact with an FPGA IP core on an embedded Linux (Yocto: krogoth) on a Xilinx board.

For debugging purposes I would like to read out specific memory addresses from physical memory. /dev/mem looks promising. I wanted to ask how I can read out the value of a specific physical memory address from the command line. I was hoping for something along the lines of cat /dev/mem 0x2000000 to read the byte at 0x2000000.

Brendan
  • 908
  • 2
  • 15
  • 30
Moritz
  • 2,987
  • 3
  • 21
  • 34
  • 2
    Search the web for the source code of J.D.Bakker's **devmem2** utility, and build it. It might even already be built in your Yocto RFS. – sawdust Dec 09 '17 at 00:53
  • Thanks for pointing me to devmem2. Found it as a recipe https://layers.openembedded.org/layerindex/recipe/1069/. So I'd just add that to my local.conf file and compile yocto again – Moritz Dec 10 '17 at 10:13
  • @sawdust What would be the correct procedure to adding my own comprehensive answer if the provided ones only partially cover my use case? – Moritz Dec 10 '17 at 10:17

2 Answers2

13

Usually you should already have devmem tool installed in your Linux image:

$ devmem 0x2000000

If you don't however, you can go to Busybox menu and tweak it to make sure it gets compiled and installed:

$ bitbake busybox -c menuconfig

(search for devmem)

J. In
  • 415
  • 5
  • 10
  • At the time of posting the question I did not distinguish the types of memory, physical, io and registers. I posted a more comprehensive question + answer [here](https://unix.stackexchange.com/a/416520/269755) that answers my use case – Moritz Jan 12 '18 at 07:35
9

Hexdump is often installed in embedded systems. Then you can do

hexdump -C --skip 0x2000000 /dev/mem | head

in order to read more than a single word, and see it decoded in various ways. (The busybox hexdump is a little more limited, but still very useful.)

Popup
  • 341
  • 2
  • 11
  • 1
    Note that busybox hexdump may not support --skip, but has -s instead. – Shawn Aug 19 '20 at 15:45
  • AFAIK, with hexdump we can only read flash memory. It cannot read I/O peripheral registers. – HarshaD Sep 24 '20 at 18:04
  • 2
    @HarshaD Hexdump can only read _files_. To it, `/dev/mem` looks like a file. The beauty (or one of them) of unix-like operating systems is that most things can be represented as files. If you have something (anything, really), that is presented by the OS as a file, hexdump will be able to read it. – Popup Sep 25 '20 at 07:25
  • Neither `devmem` nor `hexdump` installed on the Red Pitaya Ubuntu 16 embedded Linux I am using. Tried `dd` piping to `xxd` but could not get it to skip to `0x4020_0000` where my registers are located. `xxd /dev/mem` could have worked if I had the patience to wait 1/2 day for it to scroll to `0x4020_0000` – Axel Bregnsbo Sep 22 '22 at 14:15