Jump to content

Working with downstream DTBs/Device-Trees that contain overlays

From postmarketOS Wiki

When mainlining you often need to reference the downstream device trees but often they are not in a readable format. Samsung, for example, often works with overlays which makes getting useful information from the device tree difficult. Here's how to get a readable device-tree:

Extract the dtbs

First extract the dtbs using extract-dtb from a boot.img for your device. This should give you multiple files. If it doesn't, you can skip the next step and just work with a single file.

There should be one or multiple files for the SOC and one or multiple files for the device. You will now need to find out which ones are correct for your device.

First execute this:

$ mkdir out
$ for i in *.dtb; do dtc -I dtb -O dts -A -@ -s "$i" -o "out/$i.dts"; done

This will give you the text-version of the device trees, so that you can compare them.

For me there was a board-id in the model property that was different between the device DTBs. So I ran cat /proc/device-tree/model in the recovery of my device to get the correct one.

Applying the overlay

Once you have the correct device dtb you can apply the overlay like so:

$ fdtoverlay -i <soc_dtb> <device_dtb> -o full.dtb

Now you have a full dtb which can be converted into readable form like this:

$ dtc -I dtb -O dts -A -@ -s full.dtb -o full.dts

And there you go. The full.dts is now a readable representation of the downstream device-tree

Pro tip: There's https://gitlab.com/Mis012/dtc-with-pretty-decompile which will make the dtb even more readable if you apply it to full.dtb