Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame^] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | Devicetree in QEMU |
| 4 | ================== |
| 5 | |
| 6 | For QEMU on ARM, RISC-V and one PPC target, the devicetree is created on-the-fly |
| 7 | by QEMU. It is intended for use in Linux but can be used by U-Boot also, so long |
| 8 | as any nodes/properties needed by U-Boot are merged in. |
| 9 | |
| 10 | When `CONFIG_OF_BOARD` is enabled |
| 11 | |
| 12 | |
| 13 | Obtaining the QEMU devicetree |
| 14 | ----------------------------- |
| 15 | |
| 16 | Where QEMU generates its own devicetree to pass to U-Boot tou can use |
| 17 | `-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version. |
| 18 | |
| 19 | To obtain the devicetree that qemu generates, add `-machine dumpdtb=qemu.dtb`, |
| 20 | e.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 | |
| 29 | Merging in U-Boot nodes/properties |
| 30 | ---------------------------------- |
| 31 | |
| 32 | Various U-Boot features require nodes and properties in the U-Boot devicetree |
| 33 | and at present QEMU is unaware of these. To use these you must manually merge |
| 34 | in the appropriate pieces. |
| 35 | |
| 36 | One way to do this is with dtc. This command runs dtc on each .dtb file in turn, |
| 37 | to produce a text file. It drops the duplicate header on the qemu one. Then it |
| 38 | joins 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 | |
| 43 | You 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 | |
| 47 | Note that there seems to be a bug in some versions of qemu where the output of |
| 48 | dumpdtb does not quite match what is provided to U-Boot. |