Device Tree Blob (DTB) 在内核启动的时候,bootloader将其地址通过寄存器传递给内核。
Device Tree Source (DTS) 是纯文本文件,可以编译为二进制 Device Tree Blob 文件,使用 Device Tree Compiler (DTC) 工具。
内核自带了DTC,位于scripts/dtc,可以安装发行包:
1 2 | $ sudo apt-get update $ sudo apt-get install device-tree-compiler |
dtb可以无损的反编译为dts:
1 2 | $ dtc -I dts -O dtb juno.dts > juno.dtb $ dtc -I dtb -O dts juno.dtb > juno.dts |
arm64架构内核,编译dtb的规则定义在arch/arm64/Makefile中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | %.dtb: scripts $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@ %.dtbo: | scripts $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $(boot)/dts/$@ PHONY += dtbs dtbs_install dtbs: prepare scripts $(Q)$(MAKE) $(build)=$(boot)/dts dtbs_install: $(Q)$(MAKE) $(dtbinst)=$(boot)/dts |
执行dtbs将编译所有的dts,编译单个dts,只要使用dts相对与arm64/boot/dts/的路径,并把后缀替换为dtb即可,如编译arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts的目标为:broadcom/bcm2837-rpi-3-b.dts
1 | $ $(KERNEL_ENV) make broadcom/bcm2837-rpi-3-b.dtb |
dtbs_install目标将所有dtb安装到INSTALL_DTBS_PATH变量指定的路径:
1 | $(KERNEL_ENV) make INSTALL_DTBS_PATH=/work/dtbs dtbs_install |
参考资料
https://community.arm.com/dev-platforms/w/docs/268/device-tree
https://git.kernel.org/pub/scm/utils/dtc/dtc.git
https://www.raspberrypi.org/documentation/configuration/device-tree.md