While I was experimenting with the BananaPi M2 Zero board, I soon needed to adopt its device tree file (dtb).
Fortunately, the friendly members of the openSUSE:Factory:ARM community quickly hinted me at the grub2 "devicetree" command which can be specified similar to "linux" or "initrd" to name a file that's loaded as device tree.
Unfortunately, there is no way to make this really persistent, short of editing the grub generator scripts which will get lost on every grub2 update.
The other option would be to decompile the board's DTB file ("/boot/dtb/sun8i-h2-plus-bananapi-m2-zero.dtb" in my case), change and then recompile it, replacing the original file. This has two downsides: first, it will get overwritten with every update of the "dtb-sun8i" package (no idea how often this will be the case) and second, you might want to have the original file as fallback ready. In general, editing package managed files is not a good idea in my book, if it can be avoided it should be.
So I looked into the "who loads which device tree file" and found out that actually the dtb is loaded by u-boot, even before grub starts. U-boot has the name of the board built-in and thus the file name it is looking for. Additionally it has a search list of directories that it searches to find the dtb file. So the simplest way to apply your own dtb file would probably be to put it, with the original file name into the search path after the original file. I tried this approach at first, but then went for explicitly specifying a different filename, which is just not as subtle in case you need to debug this years later ;-)
So the method is relatively easy:
- put your modified dtb file into /boot, I named it custom.dtb.
- boot into u-boot, interrupt booting on the serial console
- in u-boot console, enter setenv fdtfile custom.dtb
- in u-boot console, enter saveenv