blob: 1aae6e0de0ddd025e47d52d8d16ce6f2c8a4f708 [file] [log] [blame]
Joakim Bech8e5c5b32018-10-25 08:18:32 +02001On this page you will find device specific information for QEMU v7 (Armv7-A) and
2QEMU v8 (Armv8-A).
3
4.. _qemu_v7:
5
6#######
7QEMU v7
8#######
9The instructions here will tell how to run OP-TEE using QEMU for Armv7-A.
10
11Build instructions
12******************
13As long as you pick the v7 manifest, i.e., ``default.xml`` the
14":ref:`get_and_build_the_solution`" tells all you need to know to build and boot
15up QEMU v7.
16
Etienne Carrieref9869e12021-03-13 11:49:26 +010017A usual short shell sequence to fetch, build and run OP-TEE using QEMU
18for Armv7-A is like the one below:
19
20.. code-block:: bash
21
22 $ repo init -u https://github.com/OP-TEE/manifest.git
23 $ repo sync
24 $ cd build
25 $ make toolchains
26 $ make run
Joakim Bech8e5c5b32018-10-25 08:18:32 +020027
28Consoles
29********
30After running ``make run`` you will end up in the QEMU console and it will also
31spawn two UART consoles. One console containing the UART for secure world and
32one console containing the UART for normal world. You will see that it stops
33waiting for input on the QEMU console. To continue, do:
34
35.. code-block:: none
36
37 (qemu) c
38
39Host-Guest folder sharing
40*************************
41You can use the VirtFS QEMU feature to avoid changing rootfs CPIO archive every
42time you need to add additional files or modify existing files. To do this, you
43share a folder between the guest and host operating systems. To enable and use
44this feature you have to provide additional arguments when running make,
45example:
46
47.. code-block:: bash
48
49 $ make QEMU_VIRTFS_ENABLE=y QEMU_USERNET_ENABLE=y
50
51.. hint::
52
53 You can also add ``QEMU_VIRTFS_HOST_DIR=<share>`` in case you don't want to
54 use the default sharing location (which is the root of <qemu-v7-project>).
55
56When QEMU with OP-TEE is up and running, you can mount the host folder in QEMU
57(normal world UART).
58
59.. code-block:: none
60
61 # mount -t 9p -o trans=virtio host <mount_point>
62
63``<mount_point>`` here is folder in the QEMU where you want to mount the host
64PC's shared folder. So if you want to mount it at ``/mnt/host`` you typically do
65this from QEMU NW/UART.
66
67.. code-block:: none
68
69 # mkdir -p /mnt/host
70 # mount -t 9p -o trans=virtio host /mnt/host
71
72Networking
73**********
74After booting QEMU, ``eth0`` will automatically receive an IP address from
75QEMU via DHCP using the SLiRP user networking feature. QEMU will act as a
76gateway to the host network `SLiRP`_.
77
78Please note that ICMP won't work in the guest unless additional configuration is
79made, so the ``ping`` utility won't work.
80
81GDB - Normal world
82******************
83If you need to debug a client application, using GDB in a remote debugging
84configuration may be useful. Remote debugging means ``gdb`` runs on your PC,
85where it can access the source code, while the program being debugged runs on
86the remote system (in this case, in the QEMU environment in normal world). Here
87is how to do that. On your PC, build with ``GDBSERVER=y``:
88
89.. code-block:: bash
90
91 $ cd <qemu-v7-project>/build
92 # You **only** need to rm -rf the first time you build with the new flag.
93 # If you omit doing so, it's likely that you will see "stamp" errors in the
94 # build log.
95 $ rm -rf <qemu-v7-project>/out-br
96 $ make -j8 run GDBSERVER=y
97
98Boot up as usual
99
100.. code-block:: bash
101
102 (qemu) c
103
104Inside QEMU (Normal World UART), run your application with gdbserver (for
105example ``xtest 4002``):
106
107.. code-block:: none
108
109 # gdbserver :12345 xtest 4002
110 Process xtest created; pid = 654
111 Listening on port 12345
112
113Back on your PC, open another terminal, start GDB and connect to the target:
114
115.. code-block:: bash
116
117 $ <qemu-v7-project>/out-br/host/bin/arm-buildroot-linux-gnueabihf-gdb
118 (gdb) set sysroot <qemu-v7-project>/out-br/host/arm-buildroot-linux-gnueabihf/sysroot
119 (gdb) target remote :12345
120
121Now GDB is connected to the remote application. You may use GDB normally.
122
123.. code-block:: none
124
125 (gdb) b main
126 (gdb) c
127
Joakim Bech37b54362019-03-06 10:33:46 +0100128GDB - Secure world
129******************
130TEE core debugging
131==================
132To debug TEE core running QEMU with GDB, you don't have to enable any special
133flags as such, but it's easier to debug if you have optimization disabled. Other
134than that you will have four consoles that you are working with.
135
136 - Qemu console
137 - NW UART console
138 - SW UART console
139 - GDB console
140
141All of them but the GDB console are consoles you normally will see/use when
142running OP-TEE/xtest using QEMU. The first thing is to start QEMU, i.e.,
143
144.. code-block:: bash
145
146 $ cd <qemu-v7-project>/build
147 # make run-only also works if you don't want to rebuild things
148 $ make run
149
150Next launch another console for GDB and do this
151
152.. code-block:: bash
153
154 $ cd <qemu-v7-project>/toolchains/aarch32/bin
155 $ ./arm-linux-gnueabihf-gdb -q
156
157In the GDB console connect to the QEMU GDB server, like this (the output is
158included to show what you normally will see).
159
160.. code-block:: none
161
162 (gdb) target remote localhost:1234
163 Remote debugging using localhost:1234
164 warning: No executable has been specified and target does not support
165 determining executable automatically. Try using the "file" command.
166 0x00000000 in ?? ()
167
168Still in the GDB console, load the symbols for TEE core
169
170.. code-block:: none
171
172 (gdb) symbol-file <qemu-v7-project>/optee_os/out/arm/core/tee.elf
173 Reading symbols from <qemu-v7-project>/optee_os/out/arm/core/tee.elf...done.
174
175Now you can set a breakpoint for any symbol in OP-TEE, for example
176
177.. code-block:: none
178
179 (gdb) b tee_entry_std
180 Breakpoint 1 at 0xe103012: file core/arch/arm/tee/entry_std.c, line 526.
181
182Last step is to initiate the boot, do that also from the GDB console
183
184.. code-block:: none
185
186 (gdb) c
187 Continuing.
188
189At this point will see UART output in the Normal world console as well as the
190Secure world UART console. If you now for example :ref:`optee_test_run_xtest`,
191then you will rather soon hit the breakpoint we previously set and you will see
192something like this in the GDB console:
193
194.. code-block:: none
195
196 Continuing.
197 [Switching to Thread 2]
198
199 Thread 2 hit Breakpoint 1, tee_entry_std (smc_args=0xe183f18
200 <stack_thread+8216>) at core/arch/arm/tee/entry_std.c:526
201 526 struct optee_msg_arg *arg = NULL; /* fix gcc warning */
202 (gdb)
203
204From here you can start to poke around with GDB, single step, read memory, read
205registers, print variables and all sorts of things that you normally do with a
206debugger.
207
208.. hint::
209
Joakim Bech9e7464b2019-05-21 11:40:28 +0200210 Some people find it easier to also see the source code while debugging. You
211 can enable the "TUI mode" to see the source code in GDB. To enable that, run
212 GDB with
Joakim Bech37b54362019-03-06 10:33:46 +0100213
214 .. code-block:: bash
215
216 $ ./arm-linux-gnueabihf-gdb -q -tui
217
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200218.. _qemu_v8:
219
220#######
221QEMU v8
222#######
Sander Visser26011e82020-04-21 11:55:40 +0200223The instructions here will tell how to run OP-TEE using QEMU for Armv8-A.
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200224
225Build instructions
226******************
227As long as you pick the v8 manifest, i.e., ``qemu_v8.xml`` the
228":ref:`get_and_build_the_solution`" tells all you need to know to build and boot
229up QEMU v8.
230
Etienne Carrieref9869e12021-03-13 11:49:26 +0100231A usual short shell sequence to fetch, build and run OP-TEE using QEMU
232for Armv8-A is like the one below:
233
234.. code-block:: bash
235
236 $ repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml
237 $ repo sync
238 $ cd build
239 $ make toolchains
240 $ make run
241
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200242All other things (networking, GDB etc) in the v7 section above is also
243applicable on QEMU v8 as long as you replace ``<qemu-v7-project>`` with
244``<qemu-v8-project>`` to get the correct paths relative to your QEMU v8 setup.
245
Joakim Bech37b54362019-03-06 10:33:46 +0100246.. _build/PR#340: https://github.com/OP-TEE/build/pull/340
247.. _Bug#4130: https://bugs.linaro.org/show_bug.cgi?id=4130#c4
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200248.. _SLiRP: https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29