Some information you might find useful…
The device tree can be built with the kernel source, but doing so is not building a kernel at all. The device tree is essentially a set of arguments you can pass to various drivers as they load (arguments to the function call). Technically, the device tree is not part of the kernel. The reason you can build this from the kernel is that arguments to different drivers only apply if that driver is used, and when you configure a kernel, then it makes sense to use that configuration to build a device tree. Consider building a device tree with the kernel source to simply be sharing of the Kconfig mechanism to pick possible arguments which apply only to selected drivers. The actual kernel is not built.
Aside from building a device tree via kernel source there are many other ways to work with this. The tool “dtc
” (device tree compiler) can take a source (“.dts
”) tree and convert back and forth with an object file (“.dtb
” files). This tool can also use a directory tree to create a source or binary file.
As an example, the kernel will show a reflection of the device tree it sees at the time of loading using pseudo files (they aren’t really on the hard drive, they are in RAM, and pretending to be files). To create a human readable (and editable) source file from the running system:
dtc -I fs -O dts -o extracted.dts /proc/device-tree
(if you don’t have “dtc
”, then “sudo apt-get install device-tree-compiler
”…the kernel comes with this in its own source as well)
In the above the “input” type is “filesystem”, or “fs
”, the output is type device tree source (“-O dts
”), the name of the file output is “extracted.dts
”, and the data which creates this extracted.dts
is “/proc/device-tree
”. You might want to even cd
to “/proc/device-tree
” and see what is in it and how it compares to a tree.
To convert an existing binary to source:
dtc -I dtb -O dts -o reverse_compiled.dts /boot/some_tree.dtb
You could then edit reverse_compiled.dts
, and turn it into a new custom .dtb
(try to not overwrite a new file onto an old file…it is better to leave the old one in place and edit extlinux.conf
to point at the new tree):
dtc -I dts -O dtb -o edited_new_tree.dtb reverse_compiled.dts
Just for trivia’s sake, note that kernel builds use a “device tree include file”, or “.dtsi
”. These are not complete source, but are a subset of tree used with a particular driver when Kconfig says to build that driver. Many .dtsi
files are combined, which becomes a master source “.dts
” file. Then this is built with dtc
like in the above examples. The files chosen for this creation probably depend (at least in the case of a Jetson) on the carrier board model, the module model on the carrier board, and the configured drivers.
FYI, “plug-n-play” devices don’t need a device tree, they self-report and the kernel can figure them out. Device tree is used when hardware needs to be found somewhere and given arguments which the device itself cannot self-report. An example would be a serial UART. If you run this command you’ll see the specification of some serial UARTs, along with their physical address in memory:
find /proc/device-tree/ -name 'serial@*'
(you could then cd
to that location and examine files which would correspond to the section of the “.dtb
” file loaded if the file is reverse compiled…the number in the “serial@number
” is the hex base address)