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