Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Builds ARM Trusted Firmware, and generates FIPs with UEFI and optionally |
| 4 | # Trusted OS for the supported platforms. |
| 5 | # Not intended to be called directly, invoked from uefi-build.sh. |
| 6 | # |
| 7 | # Board configuration is extracted from |
| 8 | # parse-platforms.py and platforms.config. |
| 9 | # |
| 10 | |
| 11 | TOOLS_DIR="`dirname $0`" |
| 12 | . "$TOOLS_DIR"/common-functions |
| 13 | OUTPUT_DIR="$PWD"/uefi-build |
| 14 | |
| 15 | ATF_BUILDVER=1 |
| 16 | |
| 17 | function usage |
| 18 | { |
| 19 | echo "usage:" |
| 20 | echo "atf-build.sh -e <EDK2 source directory> -t <UEFI build profile/toolchain> <platform>" |
| 21 | echo |
| 22 | } |
| 23 | |
| 24 | function check_atf_buildver |
| 25 | { |
| 26 | MAJOR=`grep "^VERSION_MAJOR" Makefile | sed 's/.*:= *\([0-9]*\).*/\1/'` |
| 27 | [ $? -ne 0 ] && return 1 |
| 28 | MINOR=`grep "^VERSION_MINOR" Makefile | sed 's/.*:= *\([0-9]*\).*/\1/'` |
| 29 | [ $? -ne 0 ] && return 1 |
| 30 | |
| 31 | if [ "$MAJOR" -eq 1 -a "$MINOR" -ge 2 ]; then |
| 32 | ATF_BUILDVER=2 |
| 33 | fi |
| 34 | } |
| 35 | |
| 36 | function build_platform |
| 37 | { |
| 38 | if [ X"$EDK2_DIR" = X"" ];then |
| 39 | echo "EDK2_DIR not set!" >&2 |
| 40 | return 1 |
| 41 | fi |
| 42 | |
| 43 | check_atf_buildver || return 1 |
| 44 | |
| 45 | BUILD_ATF="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o build_atf`" |
| 46 | if [ X"$BUILD_ATF" = X"" ]; then |
| 47 | echo "Platform '$1' is not configured to build ARM Trusted Firmware." |
| 48 | return 0 |
| 49 | fi |
| 50 | |
| 51 | ATF_PLATFORM="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_platform`" |
| 52 | if [ X"$ATF_PLATFORM" = X"" ]; then |
| 53 | ATF_PLATFORM=$1 |
| 54 | fi |
| 55 | |
| 56 | # |
| 57 | # Read platform configuration |
| 58 | # |
| 59 | PLATFORM_NAME="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o longname`" |
| 60 | PLATFORM_ARCH="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o arch`" |
| 61 | PLATFORM_IMAGE_DIR="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o uefi_image_dir`" |
| 62 | PLATFORM_BUILDFLAGS="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_buildflags`" |
| 63 | |
| 64 | if [ $VERBOSE -eq 1 ]; then |
| 65 | echo "PLATFORM_NAME=$PLATFORM_NAME" |
| 66 | echo "PLATFORM_ARCH=$PLATFORM_ARCH" |
| 67 | echo "PLATFORM_IMAGE_DIR=$PLATFORM_IMAGE_DIR" |
| 68 | echo "PLATFORM_BUILDFLAGS=$PLATFORM_BUILDFLAGS" |
| 69 | fi |
| 70 | |
| 71 | unset BL30 BL31 BL32 BL33 |
| 72 | BL30="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o scp_bin`" |
| 73 | if [ $ATF_BUILDVER -gt 1 ]; then |
| 74 | unset SCP_BL2 |
| 75 | SCP_BL2="$EDK2_DIR/$BL30" |
| 76 | fi |
| 77 | BL31="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o el3_bin`" |
| 78 | BL33="$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o uefi_bin`" |
| 79 | |
| 80 | # |
| 81 | # Set up cross compilation variables (if applicable) |
| 82 | # |
| 83 | set_cross_compile |
| 84 | CROSS_COMPILE="$TEMP_CROSS_COMPILE" |
| 85 | echo "Building ARM Trusted Firmware for $PLATFORM_NAME - $BUILD_PROFILE" |
| 86 | echo "CROSS_COMPILE=\"$TEMP_CROSS_COMPILE\"" |
| 87 | |
| 88 | if [ X"$BL30" != X"" ]; then |
| 89 | BL30="${EDK2_DIR}"/"${BL30}" |
| 90 | fi |
| 91 | if [ X"$BL31" != X"" ]; then |
| 92 | BL31="${EDK2_DIR}"/"${BL31}" |
| 93 | fi |
| 94 | |
| 95 | # |
| 96 | # BL32 requires more attention |
| 97 | # If TOS_DIR is not set, we assume user does not want a Trusted OS, |
| 98 | # even if the source directory and/or binary for it exists |
| 99 | # |
| 100 | if [ X"$TOS_DIR" != X"" ]; then |
| 101 | SPD="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_spd`" |
| 102 | |
| 103 | TOS_BIN="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o tos_bin`" |
| 104 | if [ X"$TOS_BIN" != X"" ]; then |
| 105 | BL32=$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/$TOS_BIN |
| 106 | fi |
| 107 | |
| 108 | if [ X"$SPD" != X"" ] && [ X"$BL32" != X"" ]; then |
| 109 | # |
| 110 | # Since SPD cannot be exported or undefined, |
| 111 | # we parametrise it here |
| 112 | # |
| 113 | SPD_OPTION="SPD=$SPD" |
| 114 | else |
| 115 | echo "WARNING: Proceeding without Trusted OS!" |
| 116 | echo " Please specify both ATF_SPD and TOS_BIN" |
| 117 | echo " if you wish to use a Trusted OS!" |
| 118 | fi |
| 119 | fi |
| 120 | |
| 121 | # |
| 122 | # Debug extraction handling |
| 123 | # |
| 124 | case "$BUILD_ATF" in |
| 125 | debug*) |
| 126 | DEBUG=1 |
| 127 | BUILD_TYPE="debug" |
| 128 | ;; |
| 129 | *) |
| 130 | DEBUG=0 |
| 131 | BUILD_TYPE="release" |
| 132 | ;; |
| 133 | esac |
| 134 | |
| 135 | export BL30 BL31 BL32 BL33 |
| 136 | |
| 137 | echo "BL30=$BL30" |
| 138 | if [ $ATF_BUILDVER -gt 1 ]; then |
| 139 | export SCP_BL2 |
| 140 | echo "SCP_BL2=$BL30" |
| 141 | fi |
| 142 | echo "BL31=$BL31" |
| 143 | echo "BL32=$BL32" |
| 144 | echo "BL33=$BL33" |
| 145 | echo "$SPD_OPTION" |
| 146 | echo "BUILD_TYPE=$BUILD_TYPE" |
| 147 | |
| 148 | # |
| 149 | # If a build was done with BL32, and followed by another without, |
| 150 | # the BL32 component remains in fip.bin, so we delete the build dir |
| 151 | # contents before calling make |
| 152 | # |
| 153 | rm -rf build/"$ATF_PLATFORM/$BUILD_TYPE"/* |
| 154 | |
| 155 | # |
| 156 | # Build ARM Trusted Firmware and create FIP |
| 157 | # |
| 158 | if [ $VERBOSE -eq 1 ]; then |
| 159 | echo "Calling ARM Trusted Firmware build:" |
| 160 | echo "CROSS_COMPILE="$CROSS_COMPILE" make -j$NUM_THREADS PLAT="$ATF_PLATFORM" $SPD_OPTION DEBUG=$DEBUG ${PLATFORM_BUILDFLAGS} all fip" |
| 161 | fi |
| 162 | CROSS_COMPILE="$CROSS_COMPILE" make -j$NUM_THREADS PLAT="$ATF_PLATFORM" $SPD_OPTION DEBUG=$DEBUG ${PLATFORM_BUILDFLAGS} all fip |
| 163 | if [ $? -eq 0 ]; then |
| 164 | # |
| 165 | # Copy resulting images to UEFI image dir |
| 166 | # |
| 167 | if [ $VERBOSE -eq 1 ]; then |
| 168 | echo "Copying bl1.bin and fip.bin to "$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/"" |
| 169 | fi |
| 170 | cp -a build/"$ATF_PLATFORM/$BUILD_TYPE"/{bl1,fip}.bin "$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/" |
| 171 | else |
| 172 | return 1 |
| 173 | fi |
| 174 | } |
| 175 | |
| 176 | # Check to see if we are in a trusted firmware directory |
| 177 | # refuse to continue if we aren't |
| 178 | if [ ! -d bl32 ] |
| 179 | then |
| 180 | echo "ERROR: we aren't in the arm-trusted-firmware directory." |
| 181 | usage |
| 182 | exit 1 |
| 183 | fi |
| 184 | |
| 185 | build= |
| 186 | |
| 187 | if [ $# = 0 ] |
| 188 | then |
| 189 | usage |
| 190 | exit 1 |
| 191 | else |
| 192 | while [ "$1" != "" ]; do |
| 193 | case $1 in |
| 194 | "-e" ) |
| 195 | shift |
| 196 | EDK2_DIR="$1" |
| 197 | ;; |
| 198 | "/h" | "/?" | "-?" | "-h" | "--help" ) |
| 199 | usage |
| 200 | exit |
| 201 | ;; |
| 202 | "-t" ) |
| 203 | shift |
| 204 | BUILD_PROFILE="$1" |
| 205 | ;; |
| 206 | * ) |
| 207 | build="$1" |
| 208 | ;; |
| 209 | esac |
| 210 | shift |
| 211 | done |
| 212 | fi |
| 213 | |
| 214 | if [ X"$build" = X"" ]; then |
| 215 | echo "No platform specified!" >&2 |
| 216 | echo |
| 217 | usage |
| 218 | exit 1 |
| 219 | fi |
| 220 | |
| 221 | build_platform $build |
| 222 | exit $? |