summaryrefslogtreecommitdiff
path: root/atf-build.sh
blob: d61338af95273ea9a82feb2d7e6676b786eadc62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# Builds ARM Trusted Firmware, and generates FIPs with UEFI
# for the supported platforms. Not intended to be called directly,
# invoked from uefi-build.sh.
#
# Board configuration is extracted from
# parse-platforms.py and platforms.config.
#

TOOLS_DIR="`dirname $0`"
. "$TOOLS_DIR"/common-functions
OUTPUT_DIR="$PWD"/uefi-build

function usage
{
	echo "usage:"
	echo "atf-build.sh -e <EDK2 source directory> -t <UEFI build profile/toolchain> <platform>"
	echo
}

function build_platform
{
	if [ X"$EDK2_DIR" = X"" ];then
		echo "EDK2_DIR not set!" >&2
		return 1
	fi

	if [ X"`$TOOLS_DIR/parse-platforms.py -p $1 get -o build_atf`" = X"" ]; then
		echo "Platform '$1' is not configured to build ARM Trusted Firmware."
		return 0
	fi

	ATF_PLATFORM=`$TOOLS_DIR/parse-platforms.py -p $1 get -o atf_platform`
	if [ X"$ATF_PLATFORM" = X"" ]; then
		ATF_PLATFORM=$1
	fi

	#
	# Read platform configuration
	#
	PLATFORM_NAME="`$TOOLS_DIR/parse-platforms.py -p $1 get -o longname`"
	PLATFORM_ARCH="`$TOOLS_DIR/parse-platforms.py -p $1 get -o arch`"
	PLATFORM_IMAGE_DIR="`$TOOLS_DIR/parse-platforms.py -p $1 get -o uefi_image_dir`"
	unset BL30 BL31 BL32 BL33
	BL30="`$TOOLS_DIR/parse-platforms.py -p $1 get -o scp_bin`"
	BL31="`$TOOLS_DIR/parse-platforms.py -p $1 get -o el3_bin`"
	BL32="`$TOOLS_DIR/parse-platforms.py -p $1 get -o tos_bin`"
	BL33="$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/`$TOOLS_DIR/parse-platforms.py -p $1 get -o uefi_bin`"
	export BL33

	#
	# Set up cross compilation variables (if applicable)
	#
	set_cross_compile
	CROSS_COMPILE="$TEMP_CROSS_COMPILE"
	echo "Building $PLATFORM_NAME - $BUILD_PROFILE"
	echo "CROSS_COMPILE=\"$TEMP_CROSS_COMPILE\""

	if [ X"$BL30" != X"" ]; then
		BL30="${EDK2_DIR}"/"${BL30}"
	fi
	if [ X"$BL31" != X"" ]; then
		BL31="${EDK2_DIR}"/"${BL31}"
	fi
	if [ X"$BL32" != X"" ]; then
		BL32="${EDK2_DIR}"/"${BL32}"
	fi
	export BL30 BL31 BL32

	#
	# Build ARM Trusted Firmware and create FIP
	#
	CROSS_COMPILE="$CROSS_COMPILE" make PLAT="$ATF_PLATFORM" all fip || return 1

	#
	# Copy resulting images to UEFI image dir
	#
	cp -a build/"$ATF_PLATFORM"/release/{bl1,fip}.bin "$EDK2_DIR/Build/$PLATFORM_IMAGE_DIR/$BUILD_PROFILE/FV/"
}

# Check to see if we are in a trusted firmware directory
# refuse to continue if we aren't
if [ ! -d bl32 ]
then
	echo "ERROR: we aren't in the arm-trusted-firmware directory."
	usage
	exit 1
fi

build=

if [ $# = 0 ]
then
	usage
	exit 1
else
	while [ "$1" != "" ]; do
		case $1 in
			"-e" )
				shift
				EDK2_DIR="$1"
				;;
			"/h" | "/?" | "-?" | "-h" | "--help" )
				usage
				exit
				;;
			"-t" )
				shift
				BUILD_PROFILE="$1"
				;;
			* )
				build="$1"
				;;
		esac
		shift
	done
fi

if [ X"$build" = X"" ]; then
	echo "No platform specified!" >&2
	echo
	usage
	exit 1
fi

build_platform $build
exit $?