Skip to content

Device Tree

Accessing device tree information in user space

The current device tree, including any loaded overlay, is available at /sys/firmware/devicetree/base.

Reading the whole device tree from /sys

Source

dtc -I fs -O dts /sys/firmware/devicetree/base

Getting memory addresses from device tree symbols

Anything in /sys/firmware/devicetree/base/__symbols__/ can be catted to get the memory address that the device occupies, or other information on the interface if it doesn't have an address:

# Note: this does not require su privilege
cat /sys/firmware/devicetree/base/__symbols__/pmu_region
/reserved-memory/pmu@7ff00000

Reading data from device tree addresses

Programs like devmem, devmem2, and pydevmem can read arbitrary memory addresses by interacting with the /dev/mem file.

devmem

docs

Note

devmem is a busybox program and is unavailable on Ubuntu.

devmem2

pkgs.org

Usage:  devmem2 { address } [ type [ data ] ]
        address : memory address to act upon
        type    : access operation type : [b]yte, [h]alfword, [w]ord
        data    : data to be written

Warning

I do not recommend devmem2; it never seems to do what I expect it to, and often results in bus errors on addresses that I believe should be accessible.

The same addresses accessed using pydevmem do not result in these errors.

pydevmem

PyPi

Usage: pydevmem [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

Overlays

Installing an overlay

  • Ensure that the .dtbo file and any required drivers are in the appropriate place in /lib/firmware.
  • Create an overlay directory and echo over the path:

    sudo -i
    mkdir /sys/kernel/config/device-tree/overlays/my_overlay
    echo my_overlay.dtbo > /sys/kernel/config/device-tree/overlays/my_overlay/path
    

Removing an overlay

For an already installed overlay called my_overlay:

sudo -i
rmdir /sys/kernel/config/device-tree/overlays/my_overlay