Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Builds OP-TEE Trusted OS. |
| 4 | # Not intended to be called directly, invoked from tos-build.sh. |
| 5 | # |
| 6 | # Board configuration is extracted from |
| 7 | # parse-platforms.py and platforms.config. |
| 8 | # |
| 9 | |
| 10 | TOOLS_DIR="`dirname $0`" |
| 11 | . "$TOOLS_DIR"/common-functions |
| 12 | |
| 13 | export CFG_TEE_CORE_LOG_LEVEL=2 # 0=none 1=err 2=info 3=debug 4=flow |
| 14 | |
| 15 | function usage |
| 16 | { |
| 17 | echo "usage:" |
| 18 | echo "opteed-build.sh -e <EDK2 source directory> -t <UEFI build profile/toolchain> <platform>" |
| 19 | echo |
| 20 | } |
| 21 | |
| 22 | function build_platform |
| 23 | { |
| 24 | unset CFG_ARM64_core PLATFORM PLATFORM_FLAVOR DEBUG |
| 25 | TOS_PLATFORM="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o tos_platform`" |
| 26 | if [ X"$TOS_PLATFORM" = X"" ]; then |
| 27 | TOS_PLATFORM="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_platform`" |
| 28 | if [ X"$TOS_PLATFORM" = X"" ]; then |
| 29 | TOS_PLATFORM=$1 |
| 30 | fi |
| 31 | fi |
| 32 | TOS_PLATFORM_FLAVOR="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o tos_platform_flavor`" |
| 33 | |
| 34 | # |
| 35 | # Read platform configuration |
| 36 | # |
| 37 | PLATFORM_ARCH="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o arch`" |
| 38 | PLATFORM_IMAGE_DIR="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o uefi_image_dir`" |
| 39 | if [ $VERBOSE -eq 1 ]; then |
| 40 | echo "PLATFORM_ARCH=$PLATFORM_ARCH" |
| 41 | echo "PLATFORM_IMAGE_DIR=$PLATFORM_IMAGE_DIR" |
| 42 | fi |
| 43 | |
| 44 | # |
| 45 | # Set up cross compilation variables (if applicable) |
| 46 | # |
| 47 | # OP-TEE requires both 64- and 32-bit compilers for a 64-bit build |
| 48 | # For details, visit |
| 49 | # https://github.com/OP-TEE/optee_os/blob/master/documentation/build_system.md#cross_compile-cross-compiler-selection |
| 50 | # |
| 51 | set_cross_compile |
| 52 | if [ "$PLATFORM_ARCH" = "AARCH64" ]; then |
| 53 | export CFG_ARM64_core=y |
| 54 | export CROSS_COMPILE_core="$TEMP_CROSS_COMPILE" |
| 55 | PLATFORM_ARCH="ARM" |
| 56 | set_cross_compile |
| 57 | PLATFORM_ARCH="AARCH64" |
| 58 | echo "CFG_ARM64_core=$CFG_ARM64_core" |
| 59 | else |
| 60 | export CFG_ARM64_core=n |
| 61 | fi |
| 62 | export CROSS_COMPILE="$TEMP_CROSS_COMPILE" |
| 63 | echo "CROSS_COMPILE=$CROSS_COMPILE" |
| 64 | echo "CROSS_COMPILE_core=$CROSS_COMPILE_core" |
| 65 | |
| 66 | # |
| 67 | # Set up build variables |
| 68 | # |
| 69 | BUILD_TOS="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o build_tos`" |
| 70 | case "$BUILD_TOS" in |
| 71 | debug*) |
| 72 | export DEBUG=1 |
| 73 | echo "PROFILE=DEBUG" |
| 74 | ;; |
| 75 | *) |
| 76 | export DEBUG=0 |
| 77 | echo "PROFILE=RELEASE" |
| 78 | ;; |
| 79 | esac |
| 80 | |
| 81 | export PLATFORM=$TOS_PLATFORM |
| 82 | export PLATFORM_FLAVOR=$TOS_PLATFORM_FLAVOR |
| 83 | echo "PLATFORM=$PLATFORM" |
| 84 | echo "PLATFORM_FLAVOR=$PLATFORM_FLAVOR" |
| 85 | echo "CFG_TEE_CORE_LOG_LEVEL=$CFG_TEE_CORE_LOG_LEVEL" |
| 86 | |
| 87 | # |
| 88 | # Build OP-TEE |
| 89 | # |
| 90 | if [ $VERBOSE -eq 1 ]; then |
| 91 | echo "Calling OP-TEE build:" |
| 92 | fi |
| 93 | make -j$NUM_THREADS |
| 94 | if [ $? -eq 0 ]; then |
| 95 | # |
| 96 | # Copy resulting images to UEFI image dir |
| 97 | # |
| 98 | if [ $VERBOSE -eq 1 ]; then |
| 99 | echo "Copying tee.bin to "$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/"" |
| 100 | fi |
| 101 | cp -a out/arm-plat-"$TOS_PLATFORM"/core/tee.bin "$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/" |
| 102 | else |
| 103 | return 1 |
| 104 | fi |
| 105 | } |
| 106 | |
| 107 | # Check to see if we are in a trusted OS directory |
| 108 | # refuse to continue if we aren't |
| 109 | if [ ! -f documentation/optee_design.md ] |
| 110 | then |
| 111 | echo "ERROR: we aren't in the optee_os directory." |
| 112 | usage |
| 113 | exit 1 |
| 114 | fi |
| 115 | |
| 116 | build= |
| 117 | |
| 118 | if [ $# = 0 ] |
| 119 | then |
| 120 | usage |
| 121 | exit 1 |
| 122 | else |
| 123 | while [ "$1" != "" ]; do |
| 124 | case $1 in |
| 125 | "-e" ) |
| 126 | shift |
| 127 | EDK2_DIR="$1" |
| 128 | ;; |
| 129 | "/h" | "/?" | "-?" | "-h" | "--help" ) |
| 130 | usage |
| 131 | exit |
| 132 | ;; |
| 133 | "-t" ) |
| 134 | shift |
| 135 | BUILD_PROFILE="$1" |
| 136 | ;; |
| 137 | * ) |
| 138 | build="$1" |
| 139 | ;; |
| 140 | esac |
| 141 | shift |
| 142 | done |
| 143 | fi |
| 144 | |
| 145 | if [ X"$build" = X"" ]; then |
| 146 | echo "No platform specified!" >&2 |
| 147 | echo |
| 148 | usage |
| 149 | exit 1 |
| 150 | fi |
| 151 | |
| 152 | build_platform $build |
| 153 | exit $? |