1.. SPDX-License-Identifier: GPL-2.0+ 2 3Devicetree in QEMU 4================== 5 6For QEMU on ARM, RISC-V and one PPC target, the devicetree is created on-the-fly 7by QEMU. It is intended for use in Linux but can be used by U-Boot also, so long 8as any nodes/properties needed by U-Boot are merged in. 9 10When `CONFIG_OF_BOARD` is enabled 11 12 13Obtaining the QEMU devicetree 14----------------------------- 15 16Where QEMU generates its own devicetree to pass to U-Boot you can use 17`-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version. 18 19To obtain the devicetree that qemu generates, add `-machine dumpdtb=qemu.dtb`, 20e.g.:: 21 22 qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb 23 24 qemu-system-aarch64 -machine virt -machine dumpdtb=qemu.dtb 25 26 qemu-system-riscv64 -machine virt -machine dumpdtb=qemu.dtb 27 28 29Merging in U-Boot nodes/properties 30---------------------------------- 31 32Various U-Boot features require nodes and properties in the U-Boot devicetree 33and at present QEMU is unaware of these. To use these you must manually merge 34in the appropriate pieces. 35 36One way to do this is with dtc. This command runs dtc on each .dtb file in turn, 37to produce a text file. It drops the duplicate header on the qemu one. Then it 38joins them up and runs them through dtc to compile the output:: 39 40 qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb 41 cat <(dtc -I dtb qemu.dtb) <(dtc -I dtb u-boot.dtb | grep -v /dts-v1/) | dtc - -o merged.dtb 42 43You can then run qemu with the merged devicetree, e.g.:: 44 45 qemu-system-arm -machine virt -nographic -bios u-boot.bin -dtb merged.dtb 46 47Note that there seems to be a bug in some versions of qemu where the output of 48dumpdtb does not quite match what is provided to U-Boot. 49