xref: /optee_os/README.md (revision 5580c17c51ad1e391e7f8a3c5130d0034eba8bb4)
1# OP-TEE Trusted OS
2## Contents
3<!--- TOC generated using http://doctoc.herokuapp.com/ -->
41. [Introduction](#1-introduction)
52. [License](#2-license)
63. [Platforms supported](#3-platforms-supported)
74. [Get and build the software](#4-get-and-build-the-software)
8    4. [Basic setup](#41-basic-setup)
9    4. [Foundation Models](#42-foundation-models)
10    4. [ARM Juno board](#43-juno)
11    4. [QEMU](#44-qemu)
12    4. [STMicroelectronics boards](#45-stmicroelectronics-boards)
135. [Coding standards](#5-coding-standards)
14	5. [checkpatch](#51-checkpatch)
15
16# 1. Introduction
17The optee_os git, contains the source code for the TEE in Linux using the ARM(R)
18TrustZone(R) technology. This component meets the GlobalPlatform TEE System
19Architecture specification. It also provides the TEE Internal API v1.0 as
20defined by the Global Platform TEE Standard for the development of Trusted
21Applications. For a general overview of OP-TEE and to find out how to contribute,
22please see the [Notice.md](Notice.md) file.
23
24The Trusted OS is accessible from the Rich OS (Linux) using the
25[GlobalPlatform TEE Client API Specification v1.0](http://www.globalplatform.org/specificationsdevice.asp),
26which also is used to trigger secure execution of applications within the TEE.
27
28## 2. License
29The software is distributed mostly under the
30[BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause) open source
31license, apart from some files in the optee_os/lib/libutils directory which
32are distributed under the
33[BSD 3-Clause](http://opensource.org/licenses/BSD-3-Clause) or public domain
34licenses.
35
36## 3. Platforms supported
37Several platforms are supported. In order to manage slight differences
38between platforms, a `PLATFORM_FLAVOR` flag has been introduced.
39The `PLATFORM` and `PLATFORM_FLAVOR` flags define the whole configuration
40for a chip the where the Trusted OS runs. Note that there is also a
41composite form which makes it possible to append `PLATFORM_FLAVOR` directly,
42by adding a dash inbetween the names. The composite form is shown below
43for the different boards. For more specific details about build flags etc,
44please read the file [build_system.md](documentation/build_system.md).
45
46| Platform | Composite PLATFORM flag |
47|--------|--------|
48| [Foundation FVP](http://www.arm.com/fvp) |`PLATFORM=vexpress-fvp`|
49| [ARMs Juno Board](http://www.arm.com/products/tools/development-boards/versatile-express/juno-arm-development-platform.php) |`PLATFORM=vexpress-juno`|
50| [QEMU](http://wiki.qemu.org/Main_Page) |`PLATFORM=vexpress-qemu_virt`|
51| [STMicroelectronics b2120 - h310 / h410](http://www.st.com/web/en/catalog/mmc/FM131/SC999/SS1628/PF258776) |`PLATFORM=stm-cannes`|
52| [STMicroelectronics b2020-h416](http://www.st.com/web/catalog/mmc/FM131/SC999/SS1633/PF253155?sc=internet/imag_video/product/253155.jsp)|`PLATFORM=stm-orly2`|
53
54## 4. Get and build the software
55There are a couple of different build options depending on the target you are
56going to use. If you just want to get the software and compile it, then you
57should follow the instructions under the "Basic setup" below. In case you are
58going to run for a certain hardware or FVP, QEMU for example, then please follow
59the respective section instead.
60
61---
62### 4.1 Basic setup
63#### 4.1.1 Get the compiler
64We will strive to use the latest available compiler from Linaro. Start by
65downloading and unpacking the compiler. Then export the PATH to the bin folder.
66
67```
68$ cd $HOME
69$ mkdir toolchains
70$ cd toolchains
71$ wget http://releases.linaro.org/14.05/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux.tar.xz
72$ tar xvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux.tar.xz
73$ export PATH=$HOME/toolchains/gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux/bin:$PATH
74```
75
76#### 4.1.2 Download the source code
77```
78$ cd $HOME
79$ mkdir devel
80$ cd devel
81$ git clone https://github.com/OP-TEE/optee_os.git
82```
83
84#### 4.1.3 Build
85```
86$ cd $HOME/devel/optee_os
87$ CROSS_COMPILE=arm-linux-gnueabihf- make
88```
89
90#### 4.1.4 Compiler flags
91To be able to see the full command when building you could build using
92following flag:
93```
94$ make V=1
95```
96
97To enable debug builds use the following flag:
98```
99$ make DEBUG=1
100```
101
102OP-TEE supports a couple of different levels of debug prints for both TEE core
103itself and for the Trusted Applications. The level ranges from 1 to 4, where
104four is the most verbose. To set the level you use the following flag:
105```
106$ make CFG_TEE_CORE_LOG_LEVEL=4
107```
108
109---
110### 4.2 Foundation Models
111By following this section will setup OP-TEE using FVP (Foundation Models and
112also Fast Models). You will have to download a script in this git and then run
113it, modify it slightly and then run it again. The reason for this is that we
114are not allowed to share Foundation models. I.e, the user has to download it
115from ARM directly.
116
117#### 4.2.1 Prerequisites
118To be able run this script you will need to install a couple of dependencies. On
119a Debian based system (Ubuntu, Mint etc.), you will at least need to install the
120following packages:
121
122```
123$ sudo apt-get install uuid-dev
124```
125and in case you are running on a 64bits system, then you will need to install
126the following packages.
127
128```
129$ sudo apt-get install libc6:i386 libstdc++6:i386 libz1:i386
130```
131
132#### 4.2.2 Download and setup FVP
133```
134$ wget https://raw.githubusercontent.com/OP-TEE/optee_os/master/scripts/setup_fvp_optee.sh
135$ chmod 711 setup_fvp_optee.sh
136$ ./setup_fvp_optee.sh
137```
138Follow the instructions to download Foundation Models and then update the first
139few lines under the "EDIT" section in the script. Note that if you are not
140working in Linaro and belongs to Security Working Group you will probably not
141have access to teetest.git, hence you should most likely leave this as it is.
142Run the script again.
143```
144$ ./setup_fvp_optee.sh
145```
146After about one hour (it's mainly cloning the kernel and edk2 that takes time)
147everything should have been cloned and built and you should be ready to use
148this. Pay attention to the line saying `OP-TEE and FVP setup completed.` that
149would be displayed when the script successfully ended. If you don't see this at
150the end, then something went wrong.
151
152#### 4.2.3 Compile
153During installation a couple of helper scripts were generated, the main reason
154for this is that there is a lot of interdependencies between the different
155software components and it's a bit tricky to point to the correct toolchains and
156to know in which order to build things.
157
158* `build_atf_opteed.sh`: This is used to build ARM-Trusted-Firmware and must be
159  called when you have updated any component that are included in the FIP (like
160  for example OP-TEE os).
161
162* `build_linux.sh`: This is used to build the Linux Kernel.
163
164* `build_normal.sh`: This is a pure helper script that build all the normal
165   world components (in correct order).
166
167* `build_optee_client.sh`: This will build OP-TEEs client library.
168
169* `build_optee_linuxkernel.sh`: This will build OP-TEEs Linux Kernel driver (as
170   a module).
171
172* `build_optee_os.sh`: Builds the Trusted OS itself.
173
174* `build_optee_tests.sh`: This will build the test suite (pay attention to the
175   access needed).
176
177* `build_secure.sh`: This is the helper script for the secure side that will
178  build all secure side components in the correct order.
179
180* `build_uefi.sh`: This will build Tianocore (UEFI).
181
182* `clean_gits.sh`: This will clean all gits. Beware that it will not reset the
183  commit to the one used when first cloning. Also note that it will only clean
184  git's (meaning that it will not clean Foundation models, toolchain folders).
185
186* `run_foundation.sh`: This is the script to use when starting FVP.
187
188* `update_rootfs.sh`: This script will update rootfs. For example when you have
189  updated normal world component, you will need to put them into rootfs. Calling
190  this script will do so. In case you are creating a new Trusted Application,
191  you must also edit filelist-tee.text in the gen_rootfs folder accordingly.
192
193Depending on how you are working you have the option to build components
194separately or you can build everything by running two of the scripts above.
195In case you want to make sure that everything was built and updated, we suggest
196that you call the scripts in the following order.
197```
198$ ./build_secure.sh
199$ ./build_normal.sh
200```
201By doing so all components should be (re-)built in the correct order and rootfs
202will be updated accordingly.
203
204#### 4.2.4 Run Foundation models and OP-TEE
205You simply run the script `run_foundation.sh`, load the module and start
206tee-supplicant.
207```
208$ ./run_foundation.sh
209```
210and in the console write
211```
212root@FVP:/ modprobe optee
213root@FVP:/ tee-supplicant &
214```
215Now everything has been set up and OP-TEE is ready to be used.
216
217#### 4.2.5 Known problems and limitations
218* The script `setup_fvp_optee.sh` doesn't do much error checking and doesn't
219  have many fallbacks in case of a problem.
220* The script `setup_fvp_optee.sh` setup things using absolute paths, i.e, you
221  cannot just copy a working environment to a new location.
222* In some situations you will get an error message about `undefined reference to
223  raise`. We know about this issue and it is being tracked in
224  [#issue95](https://github.com/OP-TEE/optee_os/issues/95) at GitHub.
225
226---
227### 4.3 Juno
228Juno has been supported in OP-TEE since mid October 2014.
229#### 4.3.1 Get the compiler and source
230Follow the instructions in the "4.1 Basic setup".
231
232#### 4.3.2 Build
233```
234$ cd optee_os
235$ PLATFORM=vexpress PLATFORM_FLAVOR=juno CROSS_COMPILE=arm-linux-gnueabihf- make
236```
237
238#### 4.3.3 Prepare the images to run on Juno
239Will be written soon.
240
241#### 4.3.4 Boot and run the software on Juno
242Will be written soon.
243
244---
245### 4.4 QEMU
246You can run OP-TEE using QEMU since October 2014.
247
248#### 4.4.1 Prerequisites
249To be able run this script you will need to install a couple of dependencies. On
250a Debian based system (Ubuntu, Mint etc.), you will at least need to install the
251following packages:
252
253```
254$ sudo apt-get install zlib1g-dev libglib2.0-dev libpixman-1-dev libfdt-dev \
255		       libc6:i386 libstdc++6:i386 libz1:i386 cscope
256```
257
258#### 4.4.2 Download and setup QEMU
259```
260$ wget https://raw.githubusercontent.com/OP-TEE/optee_os/master/scripts/setup_qemu_optee.sh
261$ chmod 711 setup_qemu_optee.sh
262$ ./setup_qemu_optee.sh
263```
264
265#### 4.4.3 Compile for QEMU
266During installation a couple of helper scripts were generated, the main reason
267for this is that there is a lot of interdependencies between the different
268software components and it's a bit tricky to point to the correct toolchains and
269to know in which order to build things.
270
271* `build_bios.sh`: This build the BIOS needed in QEMU
272
273* `build_linux.sh`: This is used to build the Linux Kernel.
274
275* `build_optee_client.sh`: This will build OP-TEEs client library.
276
277* `build_optee_linuxkernel.sh`: This will build OP-TEEs Linux Kernel driver (as
278   a module).
279
280* `build_optee_os.sh`: Builds the Trusted OS itself.
281
282* `build.sh`: Builds all software components in the correct order.
283
284* `run_qemu.sh`: This script starts QEMU.
285
286* `serial_0.sh`: Starts listening to QEMUs normal world UART console.
287
288* `serial_1.sh`: Starts listening to QEMUs secure world UART console.
289
290* `update_rootfs.sh`: This script will update rootfs. For example when you have
291  updated normal world component, you will need to put them into rootfs. Calling
292  this script will do so. In case you are creating a new Trusted Application,
293  you must also edit filelist-tee.text in the gen_rootfs folder accordingly.
294
295To build everything you will need to run the script `build.sh`, which will build
296all gits and in the correct order.
297
298#### 4.4.4 Boot and run QEMU and OP-TEE
299To run this you need to lunch two consoles for the UARTs and one console for
300QEMU itself, so in separate shell windows run:
301```
302$ ./serial_0.sh
303```
304```
305$ ./serial_1.sh
306```
307and finally
308```
309$ ./run_qemu.sh
310...
311QEMU 2.1.50 monitor - type 'help' for more information
312(qemu) c
313```
314
315In the window for serial_0 you will now get the normal world console and here
316you need to load and OP-TEEs Linux Kernel driver and also load tee-supplicant.
317This is done by the following lines:
318
319```
320$ root@Vexpress:/ modprobe optee
321$ root@Vexpress:/ tee-supplicant &
322```
323
324---
325### 4.5 STMicroelectronics boards
326Currently OP-TEE is supported on Orly-2 (b2020-h416) and Cannes family (b2120
327both h310 and h410 chip).
328
329#### 4.5.1 Get the compiler for Orly-2
330Will be written soon.
331
332#### 4.5.2 Download the source code
333See section "4.1.2 Download the source code".
334
335#### 4.5.3 Build for Orly-2
336Will be written soon.
337
338For Orly-2 do as follows
339```
340$ PLATFORM_FLAVOR=orly2 CROSS_COMPILE=arm-linux-gnueabihf- make
341```
342
343For Cannes family do as follows
344```
345$ PLATFORM_FLAVOR=cannes CROSS_COMPILE=arm-linux-gnueabihf- make
346```
347
348#### 4.5.4 Prepare and install the images
349Will be written soon.
350
351For Orly-2 do as follows
352```
353To be written.
354```
355
356For Cannes family do as follows
357```
358To be written.
359```
360
361#### 4.5.5 Boot and run the software
362Will be written soon. All magic with STM and so on must be stated here.
363
364For Orly-2 do as follows
365```
366To be written.
367```
368
369For Cannes family do as follows
370```
371To be written.
372```
373
374## 5. Coding standards
375In this project we are trying to adhere to the same coding convention as used in
376the Linux kernel (see
377[CodingStyle](https://www.kernel.org/doc/Documentation/CodingStyle)). We achieve this by running
378[checkpatch](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl) from Linux kernel.
379However there are a few exceptions that we had to make since the code also
380follows GlobalPlatform standards. The exceptions are as follows:
381
382- CamelCase for GlobalPlatform types are allowed.
383- And we also exclude checking third party code that we might use in this
384  project, such as LibTomCrypt, MPA, newlib (not in this particular git, but
385  those are also part of the complete TEE solution). The reason for excluding
386  and not fixing third party code is because we would probably deviate too much
387  from upstream and therefore it would be hard to rebase against those projects
388  later on (and we don't expect that it is easy to convince other software
389  projects to change coding style).
390
391### 5.1 checkpatch
392Since checkpatch is licensed under the terms of GNU GPL License Version 2, we
393cannot include this script directly into this project. Therefore we have
394written the Makefile so you need to explicitly point to the script by exporting
395an environment variable, namely CHECKPATCH. So, suppose that the source code for
396the Linux kernel is at `$HOME/devel/linux`, then you have to export like follows:
397
398	$ export CHECKPATCH=$HOME/devel/linux/scripts/checkpatch.pl
399thereafter it should be possible to use one of the different checkpatch targets
400in the [Makefile](Makefile). There are targets for checking all files, checking
401against latest commit, against a certain base-commit etc. For the details, read
402the [Makefile](Makefile).
403