1# OP-TEE Trusted OS 2## Contents 31. [Introduction](#1-introduction) 42. [License](#2-license) 53. [Platforms supported](#3-platforms-supported) 6 3. [Development board for community user] (#31-development-board-for-community-user) 74. [Get and build OP-TEE software](#4-get-and-build-op-tee-software) 8 4. [Prerequisites](#41-prerequisites) 9 4. [Basic setup](#42-basic-setup) 10 4. [STMicroelectronics boards](#44-stmicroelectronics-boards) 11 4. [Allwinner A80](#45-allwinner-a80) 12 4. [Freescale MX6UL EVK](#46-freescale-mx6ul-evk) 135. [repo manifests](#5-repo-manifests) 14 5. [Install repo](#51-install-repo) 15 5. [Get the source code](#52-get-the-source-code) 16 5. [Targets](#521-targets) 17 5. [Branches](#522-branches) 18 5. [Get the toolchains](#523-get-the-toolchains) 19 5. [QEMU](#53-qemu) 20 5. [FVP](#54-fvp) 21 5. [HiKey](#55-hikey) 22 5. [MT8173-EVB](#56-mt8173-evb) 23 5. [Juno](#57-juno) 24 5. [Update flash and its layout](#571-update-flash-and-its-layout) 25 5. [GlobalPlatform testsuite support](#572-globalplatform-testsuite-support) 26 5. [GCC5 support](#573-gcc5-support) 27 5. [Raspberry Pi 3](#58-raspberry-pi-3) 28 5. [Tips and tricks](#59-tips-and-tricks) 29 5. [Reference existing project to speed up repo sync](#581-reference-existing-project-to-speed-up-repo-sync) 30 5. [Use ccache](#582-use-ccache) 316. [Load driver, tee-supplicant and run xtest](#6-load-driver-tee-supplicant-and-run-xtest) 327. [Coding standards](#7-coding-standards) 33 7. [checkpatch](#71-checkpatch) 34 35# 1. Introduction 36The `optee_os git`, contains the source code for the TEE in Linux using the 37ARM® TrustZone® technology. This component meets the GlobalPlatform 38TEE System Architecture specification. It also provides the TEE Internal core API 39v1.1 as defined by the GlobalPlatform TEE Standard for the development of 40Trusted Applications. For a general overview of OP-TEE and to find out how to 41contribute, please see the [Notice.md](Notice.md) file. 42 43The Trusted OS is accessible from the Rich OS (Linux) using the 44[GlobalPlatform TEE Client API Specification v1.0](http://www.globalplatform.org/specificationsdevice.asp), 45which also is used to trigger secure execution of applications within the TEE. 46 47--- 48## 2. License 49The software is distributed mostly under the 50[BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause) open source 51license, apart from some files in the `optee_os/lib/libutils` directory 52which are distributed under the 53[BSD 3-Clause](http://opensource.org/licenses/BSD-3-Clause) or public domain 54licenses. 55 56--- 57## 3. Platforms supported 58Several platforms are supported. In order to manage slight differences 59between platforms, a `PLATFORM_FLAVOR` flag has been introduced. 60The `PLATFORM` and `PLATFORM_FLAVOR` flags define the whole configuration 61for a chip the where the Trusted OS runs. Note that there is also a 62composite form which makes it possible to append `PLATFORM_FLAVOR` directly, 63by adding a dash in-between the names. The composite form is shown below 64for the different boards. For more specific details about build flags etc, 65please read the file [build_system.md](documentation/build_system.md). Some 66platforms have different sub-maintainers, please refer to the file 67[MAINTAINERS.md](MAINTAINERS.md) for contact details for various platforms. 68 69<!-- Please keep this list sorted in alphabetic order --> 70| Platform | Composite PLATFORM flag | Publicly available? | 71|----------|-------------------------|---------------------| 72| [Allwinner A80 Board](http://www.allwinnertech.com/en/clq/processora/A80.html)|`PLATFORM=sunxi`| No | 73| [ARM Juno Board](http://www.arm.com/products/tools/development-boards/versatile-express/juno-arm-development-platform.php) |`PLATFORM=vexpress-juno`| Yes | 74| [FSL ls1021a](http://www.freescale.com/tools/embedded-software-and-tools/hardware-development-tools/tower-development-boards/mcu-and-processor-modules/powerquicc-and-qoriq-modules/qoriq-ls1021a-tower-system-module:TWR-LS1021A?lang_cd=en)|`PLATFORM=ls-ls1021atwr`| Yes | 75| [FSL i.MX6 Quad SABRE Lite Board](https://boundarydevices.com/product/sabre-lite-imx6-sbc/) |`PLATFORM=imx`| Yes | 76| [FSL i.MX6 Quad SABRE SD Board](http://www.nxp.com/products/software-and-tools/hardware-development-tools/sabre-development-system/sabre-board-for-smart-devices-based-on-the-i.mx-6quad-applications-processors:RD-IMX6Q-SABRE) |`PLATFORM=imx`| Yes | 77| [FSL i.MX6 UltraLite EVK Board](http://www.freescale.com/products/arm-processors/i.mx-applications-processors-based-on-arm-cores/i.mx-6-processors/i.mx6qp/i.mx6ultralite-evaluation-kit:MCIMX6UL-EVK) |`PLATFORM=imx`| Yes | 78| [ARM Foundation FVP](http://www.arm.com/fvp) |`PLATFORM=vexpress-fvp`| Yes | 79| [HiSilicon D02](http://open-estuary.org/d02-2)|`PLATFORM=d02`| No | 80| [HiKey Board (HiSilicon Kirin 620)](https://www.96boards.org/products/hikey)|`PLATFORM=hikey`| Yes | 81| [MediaTek MT8173 EVB Board](http://www.mediatek.com/en/products/mobile-communications/tablet/mt8173)|`PLATFORM=mediatek-mt8173`| No | 82| [QEMU](http://wiki.qemu.org/Main_Page) |`PLATFORM=vexpress-qemu_virt`| Yes | 83| [QEMUv8](http://wiki.qemu.org/Main_Page) |`PLATFORM=vexpress-qemu_armv8a`| Yes | 84| [Raspberry Pi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b) |`PLATFORM=rpi3`| Yes | 85| [Renesas RCAR](https://www.renesas.com/en-sg/solutions/automotive/products/rcar-h3.html)|`PLATFORM=rcar`| No | 86| [STMicroelectronics b2260 - h410 (96boards fmt)](http://www.st.com/web/en/catalog/mmc/FM131/SC999/SS1628/PF258776) |`PLATFORM=stm-b2260`| No | 87| [STMicroelectronics b2120 - h310 / h410](http://www.st.com/web/en/catalog/mmc/FM131/SC999/SS1628/PF258776) |`PLATFORM=stm-cannes`| No | 88| [Texas Instruments DRA7xx](http://www.ti.com/product/DRA746)|`PLATFORM=ti-dra7xx`| Yes | 89| [Xilinx Zynq UltraScale+ MPSOC](http://www.xilinx.com/products/silicon-devices/soc/zynq-ultrascale-mpsoc.html)|`PLATFORM=zynqmp-zcu102`| Yes | 90| [Spreadtrum SC9860](http://www.spreadtrum.com/en/SC9860GV.html)|`PLATFORM=sprd-sc9860`| No | 91 92### 3.1 Development board for community user 93For community users, we suggest using [HiKey board](https://www.96boards.org/products/ce/hikey/) 94as development board. It provides detailed documentation including chip 95datasheet, board schematics, source code, binaries etc on the download link at 96the website. 97 98--- 99## 4. Get and build OP-TEE software 100There are a couple of different build options depending on the target you are 101going to use. If you just want to get the software and compile it, then you 102should follow the instructions under the "Basic setup" below. In case you are 103going to run for a certain hardware or FVP, QEMU for example, then please follow 104the respective section found below instead, having that said, we are moving from 105the shell script based setups to instead use 106[repo](https://source.android.com/source/downloading.html), so for some targets 107you will see that we are using repo ([section 5](#5-repo-manifests)) and for 108others we are still using the shell script based setup 109([section 4](#4-get-and-build-op-tee-software)), please see this transitions as 110work in progress. 111 112--- 113### 4.1 Prerequisites 114We believe that you can use any Linux distribution to build OP-TEE, but as 115maintainers of OP-TEE we are mainly using Ubuntu-based distributions and to be 116able to build and run OP-TEE there are a few packages that needs to be installed 117to start with. Therefore install the following packages regardless of what 118target you will use in the end. 119``` 120$ sudo apt-get install android-tools-adb android-tools-fastboot autoconf bc \ 121 bison cscope curl flex gdisk libc6:i386 libfdt-dev libftdi-dev \ 122 libglib2.0-dev libhidapi-dev libncurses5-dev libpixman-1-dev \ 123 libstdc++6:i386 libtool libz1:i386 mtools netcat python-crypto \ 124 python-serial python-wand unzip uuid-dev xdg-utils xz-utils zlib1g-dev 125``` 126 127--- 128### 4.2 Basic setup 129#### 4.2.1 Get the compiler 130We strive to use the latest available compiler from Linaro. Start by downloading 131and unpacking the compiler. Then export the `PATH` to the compilers `bin` 132folder. Beware that we are using a couple of different toolchains depending on 133the target device. This includes both 64- and 32-bit toolchains. For the exact 134toolchain in use, please have a look at [toolchain.mk](https://github.com/OP-TEE/build/blob/master/toolchain.mk) 135and then look at the targets makefile (see [build.git](https://github.com/OP-TEE/build)) 136to find out where the respective toolchain will be used. For example in the 137[QEMU makefile](https://github.com/OP-TEE/build/blob/master/qemu.mk#L6-L9) and 138[common makefile](https://github.com/OP-TEE/build/blob/master/common.mk#L90-L93) 139you will see, respectively: 140``` 141override COMPILE_NS_USER := 32 142override COMPILE_NS_KERNEL := 32 143override COMPILE_S_USER := 32 144override COMPILE_S_KERNEL := 32 145``` 146``` 147CROSS_COMPILE_NS_USER ?= "$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)" 148CROSS_COMPILE_NS_KERNEL ?= "$(CCACHE)$(AARCH$(COMPILE_NS_KERNEL)_CROSS_COMPILE)" 149CROSS_COMPILE_S_USER ?= "$(CCACHE)$(AARCH$(COMPILE_S_USER)_CROSS_COMPILE)" 150CROSS_COMPILE_S_KERNEL ?= "$(CCACHE)$(AARCH$(COMPILE_S_KERNEL)_CROSS_COMPILE)" 151``` 152 153However, if you only want to compile optee_os, then you can do like this: 154``` 155$ cd $HOME 156$ mkdir toolchains 157$ cd toolchains 158$ wget http://releases.linaro.org/archive/14.08/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.9-2014.08_linux.tar.xz 159$ tar xvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.08_linux.tar.xz 160$ export PATH=$HOME/toolchains/gcc-linaro-arm-linux-gnueabihf-4.9-2014.08_linux/bin:$PATH 161``` 162 163#### 4.2.2 Download the source code 164``` 165$ cd $HOME 166$ mkdir devel 167$ cd devel 168$ git clone https://github.com/OP-TEE/optee_os.git 169``` 170 171#### 4.2.3 Build 172``` 173$ cd $HOME/devel/optee_os 174$ CROSS_COMPILE=arm-linux-gnueabihf- make 175``` 176 177#### 4.2.4 Compiler flags 178To be able to see the full command when building you could build using 179following flag: 180``` 181$ make V=1 182``` 183 184To enable debug builds use the following flag: 185``` 186$ make DEBUG=1 187``` 188 189OP-TEE supports a couple of different levels of debug prints for both TEE core 190itself and for the Trusted Applications. The level ranges from 1 to 4, where 191four is the most verbose. To set the level you use the following flag: 192``` 193$ make CFG_TEE_CORE_LOG_LEVEL=4 194``` 195 196--- 197### 4.4 STMicroelectronics boards 198Currently OP-TEE is supported Cannes family (`b2120` both `h310` and `h410` 199chips) and the 96boards/cannes board (`b2260-h410`). 200 201#### 4.4.1 Get the compiler 202Follow the instructions in the "4.2 Basic setup". 203 204#### 4.4.2 Download the source code 205See section "4.2.2 Download the source code". 206 207#### 4.4.3 Build the images and files 208For the 96boards/cannes: 209``` 210$ make PLATFORM=stm-b2260 211``` 212For the legacy cannes family: 213``` 214$ make PLATFORM=stm-cannes 215``` 216 217#### 4.4.4 Prepare, install and run the software 218For 96board/cannes: 219Copy the generated 'optee.bin' on target SD or USB stick and insure the boot 220media boot scripts defines optee and non-secure worlds boot. 221 222More info to come... 223 224--- 225### 4.5 Allwinner A80 226 227#### 4.5.1 Locked versus unlocked A80 boards 228**Important!** All A80 boards sold to the general public are boards where secure 229side has been locked down, which means that you **cannot** use them for secure 230side development, i.e, it will not be possible to put OP-TEE on those devices. 231If you want to use A80 board for secure side development, then you will need to 232talk to 233[Allwinner](https://github.com/OP-TEE/optee_os/blob/master/MAINTAINERS.md) 234directly and ask if it is possible get a device from them. 235 236#### 4.5.2 Get the compiler and source 237Follow the instructions in the "4.2 Basic setup". 238 239#### 4.5.3 Build 240``` 241$ cd optee_os 242$ export PLATFORM=sunxi 243$ export CROSS_COMPILE=arm-linux-gnueabihf- 244$ make 245``` 246 247#### 4.5.4 Prepare the images to run on A80 Board 248 249Download Allwinner A80 platform SDK, the SDK refers to Allwinner A80 platform 250SDK root directory. A80 SDK directory tree looks like this: 251``` 252SDK/ 253 Android 254 lichee 255``` 256`Android` contains all source code related to Android and `lichee` 257contains the bootloader and Linux kernel. 258 259##### 4.5.4.1 Copy OP-TEE output to package directory 260Copy the OP-TEE output binary to `SDK/lichee/tools/pack/sun9i/bin` 261 262``` 263$ cd optee_os 264$ cp ./out/arm32-plat-sunxi/core/tee.bin SDK/lichee/tools/pack/sun9i/bin 265``` 266 267##### 4.5.4.2 Build Linux kernel 268In the `lichee` directory, run the following commands: 269``` 270$ cd SDK/lichee 271$ ./build.sh 272``` 273 274##### 4.5.4.3 Build Android 275In the Android directory, run the following commands: 276``` 277$ cd SDK/android 278$ extract-bsp 279$ make -j 280``` 281 282##### 4.5.4.4 Create the Android image 283In the Android directory, run the following commands: 284``` 285$ cd SDK/android 286$ pack 287``` 288The output image will been signed internally when packed. The output image name 289is `a80_android_board.img`. 290 291##### 4.5.4.5 Download the Android image 292Use `Allwinner PhoenixSuit` tool to download to A80 board. 293Choose the output image(`a80_android_board.img`), select download and wait 294for the download to complete. 295 296#### 4.5.5 Boot and run the software on A80 Board 297When the host platform is Windows, use a console application to connect A80 298board `uart0`. In the console window, You can install OP-TEE linux kernel 299driver `optee.ko`, load OP-TEE-Client daemon `tee-supplicant` and run 300the example "hello world" Trusted Application, do this by running: 301``` 302$ insmod /system/vendor/modules/optee.ko 303$ /system/bin/tee-supplicant & 304$ /system/bin/tee-helloworld 305``` 306 307--- 308### 4.6 Freescale MX6UL EVK 309 310Get U-Boot source: 311https://github.com/MrVan/uboot/commit/4f016adae573aaadd7bf6a37f8c58a882b391ae6 312 313Build U-Boot: 314``` 315 make ARCH=arm mx6ul_14x14_evk_optee_defconfig 316 make ARCH=arm 317 Burn u-boot.imx to offset 0x400 of SD card 318``` 319 320Get Kernel source: https://github.com/linaro-swg/linux/tree/optee 321 322Patch kernel: 323```c 324 diff --git a/arch/arm/boot/dts/imx6ul-14x14-evk.dts b/arch/arm/boot/dts/imx6ul-14x14-evk.dts 325 index 6aaa5ec..2ac9c80 100644 326 --- a/arch/arm/boot/dts/imx6ul-14x14-evk.dts 327 +++ b/arch/arm/boot/dts/imx6ul-14x14-evk.dts 328 @@ -23,6 +23,13 @@ 329 reg = <0x80000000 0x20000000>; 330 }; 331 332 + firmware { 333 + optee { 334 + compatible = "linaro,optee-tz"; 335 + method = "smc"; 336 + }; 337 + }; 338 + 339 regulators { 340 compatible = "simple-bus"; 341 #address-cells = <1>; 342``` 343 344Compile the Kernel: 345 346``` 347make ARCH=arm imx_v6_v7_defconfig 348make menuconfig 349select the two entries 350 CONFIG_TEE=y 351 CONFIG_OPTEE 352make ARCH=arm 353``` 354Copy zImage and imx6ul_14x14_evk.dtb to SD card. 355 356OPTEE OS Build: 357``` 358 PLATFORM_FLAVOR=mx6ulevk make PLATFORM=imx 359 ${CROSS_COMPILE}-objcopy -O binary out/arm-plat-imx/core/tee.elf optee.bin 360 copy optee.bin to the first partition of SD card which is used for boot. 361``` 362 363Run using U-Boot: 364``` 365 run loadfdt; 366 run loadimage; 367 fatload mmc 1:1 0x9c100000 optee.bin; 368 run mmcargs; 369 bootz ${loadaddr} - ${fdt_addr}; 370``` 371 372Note: 373 CAAM is not implemented now, this will be added later. 374 375More steps: http://mrvan.github.io/optee-imx6ul 376 377--- 378## 5. repo manifests 379 380A Git repository is available at https://github.com/OP-TEE/manifest where you 381will find XML-files for use with the Android 'repo' tool. 382 383### 5.1. Install repo 384Follow the instructions under the "Installing Repo" section 385[here](https://source.android.com/source/downloading.html). 386 387### 5.2. Get the source code 388First ensure that you have the necessary Ubuntu packages installed, see [4.1 389Prerequisites](#41-prerequisites) (this is the only important step from section 3904 in case you are setting up any of the target devices mentioned below). 391 392``` 393$ mkdir -p $HOME/devel/optee 394$ cd $HOME/devel/optee 395$ repo init -u https://github.com/OP-TEE/manifest.git -m ${TARGET}.xml [-b ${BRANCH}] 396$ repo sync 397``` 398**Notes**<br> 399* The folder could be at any location, we are just giving a suggestion by 400 saying `$HOME/devel/optee`. 401* `repo sync` can take an additional parameter -j to sync multiple remotes. For 402 example `repo sync -j3` will sync three remotes in parallel. 403 404#### 5.2.1 Targets 405| Target | Latest | Stable | 406|--------|--------|--------| 407| QEMU | `default.xml` | `default_stable.xml` | 408| QEMUv8 | `qemu_v8.xml` | `qemu_v8_stable.xml` | 409| FVP | `fvp.xml` | `fvp_stable.xml` | 410| HiKey | `hikey.xml` | `hikey_stable.xml` | 411| HiKey Debian | `hikey_debian.xml` | `hikey_debian_stable.xml` | 412| MediaTek MT8173 EVB Board | `mt8173-evb.xml` | `mt8173-evb_stable.xml` | 413| ARM Juno board| `juno.xml` | `juno_stable.xml` | 414| Raspberry Pi 3 | `rpi3.xml` | `rpi3_stable.xml` | 415 416#### 5.2.2 Branches 417Currently we are only using one branch, i.e, the `master` branch. 418 419#### 5.2.3 Get the toolchains 420This is a one time thing you run only once after getting all the source code 421using repo. 422``` 423$ cd build 424$ make toolchains 425``` 426 427##### Note : 428If you have been using GCC4.9 and are upgrading to GCC5 via [this commit] (https://github.com/OP-TEE/build/commit/69a8a37bc417d28d62ae57e7ca2a8df4bdec93c8), please make sure that you delete the `toolchains` directory before running `make toolchains` again, or else the toolchain binaries can get mixed up or corrupted, and generate errors during builds. 429 430--- 431### 5.3. QEMU 432After getting the source and toolchain, just run (from the `build` folder) 433``` 434$ make all run 435``` 436and everything should compile and at the end QEMU should start. 437 438--- 439### 5.4. FVP 440After getting the source and toolchain you must also obtain Foundation Model 441([link](http://www.arm.com/products/tools/models/fast-models/foundation-model.php)) 442binaries and untar it to the forest root, then just run (from the `build` folder) 443 444``` 445$ make all run 446``` 447and everything should compile and at the end FVP should start. 448 449--- 450### 5.5. HiKey 451#### 5.5.1 Initramfs based 452After getting the source and toolchain, just run (from the `build` folder) 453``` 454$ make all 455``` 456 457After that connect the board and flash the binaries by running: 458``` 459$ make flash 460``` 461 462(more information about how to flash individual binaries could be found 463[here](https://github.com/96boards/documentation/wiki/HiKeyUEFI#flash-binaries-to-emmc-)) 464 465The board is ready to be booted. 466#### 5.5.2 Debian based / 96boards RPB 467Start by getting the source and toolchain (see above), then continue by 468downloading the system image (root fs). Note that this step is something you 469only should do once. 470 471``` 472$ make system-img 473``` 474 475Which should be followed by 476``` 477$ make all 478``` 479 480When everything has been built, flash the files to the device: 481``` 482$ make flash 483``` 484 485Now you can boot up the device, note that OP-TEE normal world binaries still 486hasn't been put on the device at this stage. So by now you're basically booting 487up an RPB build. When you have a prompt, the next step is to connect the device 488to the network. WiFi is preferable, since HiKey has no Ethernet jack. Easiest is 489to edit `/etc/network/interfaces`. To find out what to add, run: 490``` 491$ make help 492``` 493 494When that's been added, reboot and when you have a prompt again, you're ready to 495push the OP-TEE client binaries and the kernel with OP-TEE support. First find 496out the IP for your device (`ifconfig`). Then send the files to HiKey by 497running: 498``` 499$ IP=111.222.333.444 make send 500 501Credentials for the image are: 502username: linaro 503password: linaro 504``` 505 506When the files has been transfered, please follow the commands from the `make 507send` command which will install the debian packages on the device. Typically it 508tells you to run something like this on the device itself: 509``` 510$ dpkg --force-all -i /tmp/out/optee_2.0-1.deb 511$ dpkg --force-all -i /tmp/linux-image-*.deb 512``` 513 514Now you are ready to use OP-TEE on HiKey using Debian, please goto step 6 below 515to continue. 516 517##### Good to know 518Just want to update secure side? Put the device in fastboot mode and 519``` 520$ make arm-tf 521$ make flash-fip 522 523``` 524 525Just want to update OP-TEE client software? Put the device in fastboot mode and 526``` 527$ make optee-client 528$ make xtest 529``` 530 531Boot up the device and follow the instructions from make send 532``` 533$ IP=111.222.333.444 make send 534``` 535 536--- 537### 5.6. MT8173-EVB 538After getting the source and toolchain, just run (from the `build` folder) 539 540``` 541$ make all run 542``` 543 544When `< waiting for device >` prompt appears, press reset button and the 545flashing procedure should begin. 546 547--- 548### 5.7 Juno 549After getting the source and toolchain, just run (from the `build` folder) 550``` 551$ make all 552``` 553 554Enter the firmware console on the juno board and press enter to stop 555the auto boot flow 556``` 557ARM V2M_Juno Firmware v1.3.9 558Build Date: Nov 11 2015 559 560Time : 12:50:45 561Date : 29:03:2016 562 563Press Enter to stop auto boot... 564 565``` 566Enable ftp at the firmware prompt 567``` 568Cmd> ftp_on 569Enabling ftp server... 570 MAC address: xxxxxxxxxxxx 571 572 IP address: 192.168.1.158 573 574 Local host name = V2M-JUNO-A2 575``` 576 577Flash the binary by running (note the IP address from above): 578``` 579make JUNO_IP=192.168.1.158 flash 580``` 581 582Once the binaries are transferred, reboot the board: 583``` 584Cmd> reboot 585 586``` 587 588#### 5.7.1 Update flash and its layout 589The flash in the board may need to be updated for the flashing above to 590work. If the flashing fails or if ARM-TF refuses to boot due to wrong 591version of the SCP binary the flash needs to be updated. To update the 592flash please follow the instructions at [Using Linaro's deliverable on 593Juno](https://community.arm.com/docs/DOC-10804) selecting one of the zips 594under "4.1 Prebuilt configurations" flashing it as described under "5. 595Running the software". 596 597#### 5.7.2 GlobalPlatform testsuite support 598##### Warning : 599Depending on the Juno pre-built configuration, the built ramdisk.img 600size with GlobalPlatform testsuite may exceed its pre-defined Juno flash 601memory reserved location (image.txt file). 602In that case, you will need to extend the Juno flash block size reserved 603location for the ramdisk.img in the image.txt file accordingly and 604follow the instructions under "5.7.1 Update flash and its layout". 605 606##### Example with juno-latest-busybox-uboot.zip: 607The current ramdisk.img size with GlobalPlatform testsuite 608is 8.6 MBytes. 609 610###### Updated file is /JUNO/SITE1/HBI0262B/images.txt (limited to 8.3 MB) 611``` 612NOR4UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 613NOR4ADDRESS: 0x01800000 ;Image Flash Address 614NOR4FILE: \SOFTWARE\ramdisk.img ;Image File Name 615NOR4NAME: ramdisk.img 616NOR4LOAD: 00000000 ;Image Load Address 617NOR4ENTRY: 00000000 ;Image Entry Point 618``` 619 620###### Extended to 16MB 621``` 622NOR4UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 623NOR4ADDRESS: 0x01000000 ;Image Flash Address 624NOR4FILE: \SOFTWARE\ramdisk.img ;Image File Name 625NOR4NAME: ramdisk.img 626NOR4LOAD: 00000000 ;Image Load Address 627NOR4ENTRY: 00000000 ;Image Entry Point 628``` 629 630#### 5.7.3 GCC5 support 631##### Note : 632In case you are using the **Latest version** of the ARM Juno board (this is 633`juno.xml` manifest), the built `ramdisk.img` size with GCC5 compiler, at 634the moment, exceeds its pre-defined Juno flash memory reserved location 635(`image.txt` file). 636 637To solve this problem you will need to extend the Juno flash block size 638reserved location for the `ramdisk.img` and decrease the size for other 639images in the `image.txt` file accordingly and then follow the instructions 640under "5.7.1 Update flash and its layout". 641 642##### Example with juno-latest-busybox-uboot.zip: 643The current `ramdisk.img` size with GCC5 compiler is 29.15 MBytes we will 644extend it to 32 MBytes. The only changes that you need to do are those in 645**bold** 646 647###### File to update is /JUNO/SITE1/HBI0262B/images.txt 648<pre> 649NOR2UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 650NOR2ADDRESS: <b>0x00100000</b> ;Image Flash Address 651NOR2FILE: \SOFTWARE\Image ;Image File Name 652NOR2NAME: norkern ;Rename kernel to norkern 653NOR2LOAD: 00000000 ;Image Load Address 654NOR2ENTRY: 00000000 ;Image Entry Point 655 656NOR3UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 657NOR3ADDRESS: <b>0x02C00000</b> ;Image Flash Address 658NOR3FILE: \SOFTWARE\juno.dtb ;Image File Name 659NOR3NAME: board.dtb ;Specify target filename to preserve file extension 660NOR3LOAD: 00000000 ;Image Load Address 661NOR3ENTRY: 00000000 ;Image Entry Point 662 663NOR4UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 664NOR4ADDRESS: <b>0x00D00000</b> ;Image Flash Address 665NOR4FILE: \SOFTWARE\ramdisk.img ;Image File Name 666NOR4NAME: ramdisk.img 667NOR4LOAD: 00000000 ;Image Load Address 668NOR4ENTRY: 00000000 ;Image Entry Point 669 670NOR5UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE 671NOR5ADDRESS: <b>0x02D00000</b> ;Image Flash Address 672NOR5FILE: \SOFTWARE\hdlcdclk.dat ;Image File Name 673NOR5LOAD: 00000000 ;Image Load Address 674NOR5ENTRY: 00000000 ;Image Entry Point 675</pre> 676 677--- 678### 5.8 Raspberry Pi 3 679There is a separate document for Raspberry Pi 3 [here](documentation/rpi3.md). 680That document will tell you how to flash, how to debug, known problems and 681things still to be done. 682 683--- 684### 5.9 Tips and tricks 685#### 5.9.1 Reference existing project to speed up repo sync 686Doing a `repo init`, `repo sync` from scratch can take a fair amount of time. 687The main reason for that is simply because of the size of some of the gits we 688are using, like for the Linux kernel and EDK2. With repo you can reference an 689existing forest and by doing so you can speed up repo sync to instead taking ~20 690seconds instead of an hour. The way to do this are as follows. 691 6921. Start by setup a clean forest that you will not touch, in this example, let 693 us call that `optee-ref` and put that under for `$HOME/devel/optee-ref`. This 694 step will take roughly an hour. 6952. Then setup a cronjob (`crontab -e`) that does a `repo sync` in this folder 696 particular folder once a night (that is more than enough). 6973. Now you should setup your actual tree which you are going to use as your 698 working tree. The way to do this is almost the same as stated in the 699 instructions above, the only difference is that you reference the other local 700 forest when running `repo init`, like this 701 ``` 702 repo init -u https://github.com/OP-TEE/manifest.git --reference /home/jbech/devel/optee-ref 703 ``` 7044. The rest is the same above, but now it will only take a couple of seconds to 705 clone a forest. 706 707Normally step 1 and 2 above is something you will only do once. Also if you 708ignore step 2, then you will still get the latest from official git trees, since 709repo will also check for updates that aren't at the local reference. 710 711#### 5.9.2. Use ccache 712ccache is a tool that caches build object-files etc locally on the disc and can 713speed up build time significantly in subsequent builds. On Debian-based systems 714(Ubuntu, Mint etc) you simply install it by running: 715``` 716$ sudo apt-get install ccache 717``` 718 719The helper makefiles are configured to automatically find and use ccache if 720ccache is installed on your system, so other than having it installed you don't 721have to think about anything. 722 723#### 5.9.3 Host-Guest folder sharing in QEMU/QEMUv8 configurations 724To avoid changing rootfs CPIO archive each time you need to add additional 725files to it, you can also use VirtFS QEMU feature to share a folder between 726the guest and host operating systems. To use this feature enable VirtFS 727QEMU build in `build/common.mk` (set `QEMU_VIRTFS_ENABLE ?= y`), adjust 728`QEMU_VIRTFS_HOST_DIR` and rebuild QEMU. 729 730To mount host folder in QEMU, simply run: 731``` 732$ mount_shared <mount_point> 733``` 734--- 735## 6. Load driver, tee-supplicant and run xtest 736Since release v2.0.0 you don't have to load the kernel driver explicitly. In the 737standard configuration it will be built into the kernel directly. To actually 738run something on a device you however need to run tee-supplicant. This is the 739same for all platforms, so when a device has booted, then run 740``` 741$ tee-supplicant & 742``` 743and OP-TEE is ready to be used. 744 745In case you want to try run something that triggers both normal and secure side 746code you could run xtest (the main test suite for OP-TEE), run 747``` 748$ xtest 749``` 750 751--- 752## 7. Coding standards 753In this project we are trying to adhere to the same coding convention as used in 754the Linux kernel (see 755[CodingStyle](https://www.kernel.org/doc/Documentation/CodingStyle)). We achieve this by running 756[checkpatch](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl) 757from Linux kernel. However there are a few exceptions that we had to make since 758the code also follows GlobalPlatform standards. The exceptions are as follows: 759 760- CamelCase for GlobalPlatform types are allowed. 761- And we also exclude checking third party code that we might use in this 762 project, such as LibTomCrypt, MPA, newlib (not in this particular git, but 763 those are also part of the complete TEE solution). The reason for excluding 764 and not fixing third party code is because we would probably deviate too much 765 from upstream and therefore it would be hard to rebase against those projects 766 later on (and we don't expect that it is easy to convince other software 767 projects to change coding style). 768 769### 7.1 checkpatch 770Since checkpatch is licensed under the terms of GNU GPL License Version 2, we 771cannot include this script directly into this project. Therefore we have 772written the Makefile so you need to explicitly point to the script by exporting 773an environment variable, namely CHECKPATCH. So, suppose that the source code for 774the Linux kernel is at `$HOME/devel/linux`, then you have to export like follows: 775 776 $ export CHECKPATCH=$HOME/devel/linux/scripts/checkpatch.pl 777thereafter it should be possible to use one of the different checkpatch targets 778in the [Makefile](Makefile). There are targets for checking all files, checking 779against latest commit, against a certain base-commit etc. For the details, read 780the [Makefile](Makefile). 781