blob: b452e2a997ad42a20e2eedd681f1684d67895f9b [file] [log] [blame]
Simon Glasseb284942021-12-16 20:59:09 -07001.. 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
Yu Chien Peter Lin2df8ea82023-02-12 15:09:51 +080016Where QEMU generates its own devicetree to pass to U-Boot you can use
Simon Glasseb284942021-12-16 20:59:09 -070017`-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version.
18
Heinrich Schuchardt6c910f42025-04-16 08:44:29 +020019To obtain the devicetree that QEMU generates, add `dumpdtb=qemu.dtb` to the
20`-machine` argument, e.g.
Simon Glasseb284942021-12-16 20:59:09 -070021
Heinrich Schuchardt6c910f42025-04-16 08:44:29 +020022.. code-block:: bash
Simon Glasseb284942021-12-16 20:59:09 -070023
Heinrich Schuchardt6c910f42025-04-16 08:44:29 +020024 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 Glasseb284942021-12-16 20:59:09 -070032
Heinrich Schuchardt6c910f42025-04-16 08:44:29 +020033Except for the dumpdtb=qemu.dtb sub-parameter use the same qemu-system-<arch>
34invocation that you would use to start U-Boot to to get a complete device-tree.
Simon Glasseb284942021-12-16 20:59:09 -070035
36Merging in U-Boot nodes/properties
37----------------------------------
38
39Various U-Boot features require nodes and properties in the U-Boot devicetree
40and at present QEMU is unaware of these. To use these you must manually merge
41in the appropriate pieces.
42
43One way to do this is with dtc. This command runs dtc on each .dtb file in turn,
44to produce a text file. It drops the duplicate header on the qemu one. Then it
45joins 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 Lin2df8ea82023-02-12 15:09:51 +080048 cat <(dtc -I dtb qemu.dtb) <(dtc -I dtb u-boot.dtb | grep -v /dts-v1/) | dtc - -o merged.dtb
Simon Glasseb284942021-12-16 20:59:09 -070049
50You 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
54Note that there seems to be a bug in some versions of qemu where the output of
55dumpdtb does not quite match what is provided to U-Boot.