How to do it...

A device tree is defined in a human-readable device tree syntax (.dts) text file. Every board has one or several DTS files that correspond to different hardware configurations.

These DTS files are compiled into Device Tree Binary (DTB) blobs, which have the following properties:

  • They are relocatable, so pointers are never used internally
  • They allow for dynamic node insertion and removal
  • They are small in size

Device tree blobs can either be attached to the kernel binary (for legacy compatibility) or, as is more commonly done, passed to the kernel by a bootloader such as U-Boot.

To compile them, we use a Device Tree Compiler (DTC), which is included in the following:

  • The kernel source inside scripts/dtc and is compiled along with the kernel itself
  • The host sysroot in the Yocto SDK
  • Or you could alternatively install it as part of your distribution

It is recommended to use the DTC compiler included in the kernel tree or the Yocto SDK.

Device trees can be compiled independently or with the Linux kernel kbuild system, as we saw previously. However, when compiling independently, modern device trees will need to be preprocessed by the C preprocessor first.

It's important to note that the DTC currently performs syntax checking but no binding checking, so invalid DTS files may be compiled, and the resulting DTB file may result in a non-booting kernel. Invalid DTB files usually hang the Linux kernel very early on so there will be no serial output.

The bootloader might also modify the device tree before passing it to the kernel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset