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