9. Compilation of device tree

There are device tree files in the source code of U-boot and kernel. According to U-Boot’s native architecture, one board must correspond to one U-Boot dts. And the dtb generated by U-Boot dts is packaged into U-Boot’s own image. In this way, it will appear that on each SoC platform, N boards require N copies of U-Boot images.

It is not difficult to find that in fact, the main differences between different boards of a SoC platform are peripherals, while the core part of the SoC is the same. In order to implement a SoC platform, the RK platform only requires one U-Boot image, so a kernel DTB mechanism is added. The essence is to switch to the kernel DTB at an earlier stage and use its configuration information to initialize peripherals.

The RK platform can achieve compatible board differences by supporting kernel DTB, such as: display, pmic/regulator, pinctrl, clk, etc.

We can simply understand that some basic universal peripherals are initialized using U-Boot’s device tree, while non-universal parts are initialized by loading the kernel’s device tree in the U-Boot stage. So when we modify the device tree, we mainly modify the kernel device tree. For example, during the development process of the LubanCat-RK series, the device tree of U-Boot was not modified and the device tree of the rk3568-evb board was directly used.

9.1. Compile device tree file

With the help of the compilation environment provided by LubanCat-SDK, when we compile the kernel image, we will also compile the corresponding device tree.

Run the following command in the LubanCat-SDK root directory to compile the kernel:

1
2
3
4
5
# Compile kerneldeb file
./build.sh kerneldeb

# Compile extboot partition
./build.sh extboot

The device tree file generated by compilation and the device tree source file are in the same directory, such as LubanCat-2 board, The device tree source file is arch/arm64/boot/dts/rockchip/rk3568-lubancat-2.dts, and the device tree file generated after compilation is arch/arm64/boot/dts/rockchip/rk3568-lubancat-2.dtb.

9.2. Replace the device tree file with the same board

9.2.1. Extboot partition replacement device tree file

For images using extboot partitions, all device trees specified in the Makefile are already packaged when generating the extboot image. The board uses a basic device tree when it is first started, and automatically switches to the device tree of the corresponding board based on the board hardware ID after the first system startup.

The system’s boot partition is mounted in the /boot directory by default. If we want to switch the display device, we can use the configuration tool or directly modify the file address of the actual device tree to which the /boot/rk-kernel.dtb soft link is linked.

For specific switching methods, please see: “Device Tree and Device Tree Plug-in”

If you want to add a device tree yourself, you can follow the following process:

  1. Create a new device tree source file under kernel/arch/arm64/boot/dts/rockchip, assuming the name is rk3568-lubancat-2-xxx.dts.

  2. Modify the Makefile in the same directory and add rk3568-lubancat-2-xxx.dtb \ after dtb-$(CONFIG_CPU_RK3568) +=.

  3. Use the ./build.sh kerneldeb command to build the kernel deb package.

  4. Use the ./build.sh extboot command to build the extboot partition.

  5. Use the ./mkfirmware.sh command to repackage the firmware.

  6. View the boot.img partition image file in the rockdev directory.

  7. Use partition burning tool to burn.