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 | |
Yu Chien Peter Lin | 2df8ea8 | 2023-02-12 15:09:51 +0800 | [diff] [blame] | 16 | Where QEMU generates its own devicetree to pass to U-Boot you can use |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 17 | `-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version. |
| 18 | |
Heinrich Schuchardt | 6c910f4 | 2025-04-16 08:44:29 +0200 | [diff] [blame] | 19 | To obtain the devicetree that QEMU generates, add `dumpdtb=qemu.dtb` to the |
| 20 | `-machine` argument, e.g. |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 21 | |
Heinrich Schuchardt | 6c910f4 | 2025-04-16 08:44:29 +0200 | [diff] [blame] | 22 | .. code-block:: bash |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 23 | |
Heinrich Schuchardt | 6c910f4 | 2025-04-16 08:44:29 +0200 | [diff] [blame] | 24 | qemu-system-aarch64 \ |
| 25 | -machine virt,gic-version=3,dumpdtb=qemu.dtb \ |
| 26 | -cpu cortex-a57 \ |
| 27 | -smp 4 \ |
| 28 | -memory 8G \ |
| 29 | -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ |
| 30 | -tpmdev emulator,id=tpm0,chardev=chrtpm \ |
| 31 | -device tpm-tis-device,tpmdev=tpm0 |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 32 | |
Heinrich Schuchardt | 6c910f4 | 2025-04-16 08:44:29 +0200 | [diff] [blame] | 33 | Except for the dumpdtb=qemu.dtb sub-parameter use the same qemu-system-<arch> |
| 34 | invocation that you would use to start U-Boot to to get a complete device-tree. |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 35 | |
| 36 | Merging in U-Boot nodes/properties |
| 37 | ---------------------------------- |
| 38 | |
| 39 | Various U-Boot features require nodes and properties in the U-Boot devicetree |
| 40 | and at present QEMU is unaware of these. To use these you must manually merge |
| 41 | in the appropriate pieces. |
| 42 | |
| 43 | One way to do this is with dtc. This command runs dtc on each .dtb file in turn, |
| 44 | to produce a text file. It drops the duplicate header on the qemu one. Then it |
| 45 | joins them up and runs them through dtc to compile the output:: |
| 46 | |
| 47 | qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb |
Yu Chien Peter Lin | 2df8ea8 | 2023-02-12 15:09:51 +0800 | [diff] [blame] | 48 | cat <(dtc -I dtb qemu.dtb) <(dtc -I dtb u-boot.dtb | grep -v /dts-v1/) | dtc - -o merged.dtb |
Simon Glass | eb28494 | 2021-12-16 20:59:09 -0700 | [diff] [blame] | 49 | |
| 50 | You can then run qemu with the merged devicetree, e.g.:: |
| 51 | |
| 52 | qemu-system-arm -machine virt -nographic -bios u-boot.bin -dtb merged.dtb |
| 53 | |
| 54 | Note that there seems to be a bug in some versions of qemu where the output of |
| 55 | dumpdtb does not quite match what is provided to U-Boot. |