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