blob: 65d4dbc61c62cca5b58b663263a5d32acda21541 [file] [log] [blame]
Vishal Bhoj9a67d912016-06-09 10:02:07 +01001#!/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
Vishal Bhoj9a67d912016-06-09 10:02:07 +010011. "$TOOLS_DIR"/common-functions
12OUTPUT_DIR="$PWD"/uefi-build
13
14ATF_BUILDVER=1
15
16function usage
17{
18 echo "usage:"
19 echo "atf-build.sh -e <EDK2 source directory> -t <UEFI build profile/toolchain> <platform>"
20 echo
21}
22
23function check_atf_buildver
24{
25 MAJOR=`grep "^VERSION_MAJOR" Makefile | sed 's/.*:= *\([0-9]*\).*/\1/'`
26 [ $? -ne 0 ] && return 1
27 MINOR=`grep "^VERSION_MINOR" Makefile | sed 's/.*:= *\([0-9]*\).*/\1/'`
28 [ $? -ne 0 ] && return 1
29
30 if [ "$MAJOR" -eq 1 -a "$MINOR" -ge 2 ]; then
31 ATF_BUILDVER=2
32 fi
33}
34
35function build_platform
36{
37 if [ X"$EDK2_DIR" = X"" ];then
38 echo "EDK2_DIR not set!" >&2
39 return 1
40 fi
41
42 check_atf_buildver || return 1
43
44 BUILD_ATF="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o build_atf`"
45 if [ X"$BUILD_ATF" = X"" ]; then
46 echo "Platform '$1' is not configured to build ARM Trusted Firmware."
47 return 0
48 fi
49
50 ATF_PLATFORM="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_platform`"
51 if [ X"$ATF_PLATFORM" = X"" ]; then
52 ATF_PLATFORM=$1
53 fi
54
55 #
56 # Read platform configuration
57 #
58 PLATFORM_NAME="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o longname`"
59 PLATFORM_ARCH="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o arch`"
60 PLATFORM_IMAGE_DIR="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o uefi_image_dir`"
61 PLATFORM_BUILDFLAGS="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_buildflags`"
62
63 if [ $VERBOSE -eq 1 ]; then
64 echo "PLATFORM_NAME=$PLATFORM_NAME"
65 echo "PLATFORM_ARCH=$PLATFORM_ARCH"
66 echo "PLATFORM_IMAGE_DIR=$PLATFORM_IMAGE_DIR"
67 echo "PLATFORM_BUILDFLAGS=$PLATFORM_BUILDFLAGS"
68 fi
69
70 unset BL30 BL31 BL32 BL33
71 BL30="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o scp_bin`"
72 if [ $ATF_BUILDVER -gt 1 ]; then
73 unset SCP_BL2
John Stultzaccad872017-07-06 13:56:07 -070074 SCP_BL2=`search_packages_path "$BL30"`
Vishal Bhoj9a67d912016-06-09 10:02:07 +010075 fi
76 BL31="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o el3_bin`"
John Stultzaccad872017-07-06 13:56:07 -070077 BL33="$WORKSPACE/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o uefi_bin`"
Vishal Bhoj9a67d912016-06-09 10:02:07 +010078
79 #
80 # Set up cross compilation variables (if applicable)
81 #
82 set_cross_compile
83 CROSS_COMPILE="$TEMP_CROSS_COMPILE"
84 echo "Building ARM Trusted Firmware for $PLATFORM_NAME - $BUILD_PROFILE"
85 echo "CROSS_COMPILE=\"$TEMP_CROSS_COMPILE\""
86
87 if [ X"$BL30" != X"" ]; then
John Stultzaccad872017-07-06 13:56:07 -070088 BL30=`search_packages_path "$BL30"`
Vishal Bhoj9a67d912016-06-09 10:02:07 +010089 fi
90 if [ X"$BL31" != X"" ]; then
John Stultzaccad872017-07-06 13:56:07 -070091 BL31=`search_packages_path "$BL31"`
Vishal Bhoj9a67d912016-06-09 10:02:07 +010092 fi
93
94 #
95 # BL32 requires more attention
96 # If TOS_DIR is not set, we assume user does not want a Trusted OS,
97 # even if the source directory and/or binary for it exists
98 #
99 if [ X"$TOS_DIR" != X"" ]; then
100 SPD="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o atf_spd`"
101
102 TOS_BIN="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o tos_bin`"
103 if [ X"$TOS_BIN" != X"" ]; then
John Stultzaccad872017-07-06 13:56:07 -0700104 BL32=$WORKSPACE/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/$TOS_BIN
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100105 fi
106
107 if [ X"$SPD" != X"" ] && [ X"$BL32" != X"" ]; then
108 #
109 # Since SPD cannot be exported or undefined,
110 # we parametrise it here
111 #
112 SPD_OPTION="SPD=$SPD"
113 else
114 echo "WARNING: Proceeding without Trusted OS!"
115 echo " Please specify both ATF_SPD and TOS_BIN"
116 echo " if you wish to use a Trusted OS!"
117 fi
John Stultzaccad872017-07-06 13:56:07 -0700118 else
119 #
120 # Since TOS_DIR is not set, user does not want a Trusted OS
121 # even if the source directory and/or binary for it exists.
122 # Next, Check whether user wants secure partition image.
123 # If SPM_BIN is set then include pre-built secure partition image as a
124 # BL32 Image and implicitly set SPM=1.
125 #
126 SPM_BIN="`$TOOLS_DIR/parse-platforms.py $PLATFORM_CONFIG -p $1 get -o spm_bin`"
127
128 if [ X"$SPM_BIN" != X"" ]; then
129 BL32=$WORKSPACE/Build/StandaloneSmmPkg/$BUILD_PROFILE/FV/$SPM_BIN
130 PLATFORM_BUILDFLAGS="$PLATFORM_BUILDFLAGS SPM=1"
131 fi
132 # We assume that user does not want secure partition either.
133 # Todo: Revisit if either one of Trusted OS or Secure Partition Image is Mandatory.
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100134 fi
135
John Stultzaccad872017-07-06 13:56:07 -0700136
137
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100138 #
139 # Debug extraction handling
140 #
141 case "$BUILD_ATF" in
142 debug*)
143 DEBUG=1
144 BUILD_TYPE="debug"
145 ;;
146 *)
147 DEBUG=0
148 BUILD_TYPE="release"
149 ;;
150 esac
151
152 export BL30 BL31 BL32 BL33
153
154 echo "BL30=$BL30"
John Stultzaccad872017-07-06 13:56:07 -0700155 if [ $ATF_BUILDVER -gt 1 ] && [ X"$BL30" != X"" ]; then
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100156 export SCP_BL2
157 echo "SCP_BL2=$BL30"
158 fi
159 echo "BL31=$BL31"
160 echo "BL32=$BL32"
161 echo "BL33=$BL33"
162 echo "$SPD_OPTION"
163 echo "BUILD_TYPE=$BUILD_TYPE"
164
165 #
166 # If a build was done with BL32, and followed by another without,
167 # the BL32 component remains in fip.bin, so we delete the build dir
168 # contents before calling make
169 #
170 rm -rf build/"$ATF_PLATFORM/$BUILD_TYPE"/*
171
172 #
173 # Build ARM Trusted Firmware and create FIP
174 #
175 if [ $VERBOSE -eq 1 ]; then
176 echo "Calling ARM Trusted Firmware build:"
177 echo "CROSS_COMPILE="$CROSS_COMPILE" make -j$NUM_THREADS PLAT="$ATF_PLATFORM" $SPD_OPTION DEBUG=$DEBUG ${PLATFORM_BUILDFLAGS} all fip"
178 fi
179 CROSS_COMPILE="$CROSS_COMPILE" make -j$NUM_THREADS PLAT="$ATF_PLATFORM" $SPD_OPTION DEBUG=$DEBUG ${PLATFORM_BUILDFLAGS} all fip
180 if [ $? -eq 0 ]; then
181 #
182 # Copy resulting images to UEFI image dir
183 #
184 if [ $VERBOSE -eq 1 ]; then
John Stultzaccad872017-07-06 13:56:07 -0700185 echo "Copying bl1.bin and fip.bin to "$WORKSPACE/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/""
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100186 fi
John Stultzaccad872017-07-06 13:56:07 -0700187 cp -a build/"$ATF_PLATFORM/$BUILD_TYPE"/{bl1,fip}.bin "$WORKSPACE/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/"
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100188 else
189 return 1
190 fi
191}
192
193# Check to see if we are in a trusted firmware directory
194# refuse to continue if we aren't
195if [ ! -d bl32 ]
196then
197 echo "ERROR: we aren't in the arm-trusted-firmware directory."
198 usage
199 exit 1
200fi
201
202build=
203
204if [ $# = 0 ]
205then
206 usage
207 exit 1
208else
209 while [ "$1" != "" ]; do
210 case $1 in
211 "-e" )
212 shift
213 EDK2_DIR="$1"
214 ;;
215 "/h" | "/?" | "-?" | "-h" | "--help" )
216 usage
217 exit
218 ;;
219 "-t" )
220 shift
221 BUILD_PROFILE="$1"
222 ;;
223 * )
224 build="$1"
225 ;;
226 esac
227 shift
228 done
229fi
230
231if [ X"$build" = X"" ]; then
232 echo "No platform specified!" >&2
233 echo
234 usage
235 exit 1
236fi
237
238build_platform $build
239exit $?