-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile_mainline_atf
executable file
·96 lines (80 loc) · 2.18 KB
/
compile_mainline_atf
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile official ATF firmware
Usage: ${SH_FILE} -b board [-h] [-d dir] [-s dir]
Where:
-b name of the board to configure (for example: sun50i_a64)
-d compile firmware in debug mode
-s ATF source directory
-h this help page
EOF
exit 0
}
# Error function
function error() {
echo -e "$@" >&2
exit 1
}
# Copy/Check function
function copy() {
typeset -r FILE=$1
typeset -r DEST=$2
cp ${FILE} ${DEST} >/dev/null 2>&1 \
|| error "Error while copying file ${FILE} to ${DEST}!"
}
# Variable(s)
typeset -r SH_FILE=${0##*/}
typeset -r TMPFS=/dev/shm/atf-tmp
typeset -rx ARCH=arm
typeset -rx CROSS_COMPILE=aarch64-elf-
typeset -x ATF_DIR=~/git/github/arm-trusted-firmware
typeset -x PATH=~/cross-compile/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-elf/bin:$PATH
typeset DEBUG=0
typeset RELEASE=release
typeset BOARD
# Get options
while getopts "b:ds:h" ARG; do
case ${ARG} in
b) BOARD=${OPTARG}
;;
d) DEBUG=1
RELEASE=debug
;;
s) ATF_DIR=${OPTARG}
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Board model must be filled!
[[ -z "${BOARD}" ]] \
&& error "Board model must be filled!\n"
# Remove old TMPFS and re-create it
echo "- Cleaning/Creating ${TMPFS} directory..."
rm -rf ${TMPFS} \
|| error "Cannot clean temporary directory ${TMPFS}!"
mkdir -p ${TMPFS} \
|| error "Cannot create temporary directory ${TMPFS}!"
# Copy ATF source in the tmpfs directory
rsync -aq ${ATF_DIR}/ ${TMPFS} \
|| error "Cannot copy ${ATF_DIR}/* in ${TMPFS}!"
# Cleanup ATF build
echo "- Cleaning ATF build directory..."
cd ${TMPFS}
make clean && make distclean
# Compile ATF
echo "- Compiling ATF for ${BOARD} board..."
make PLAT=${BOARD} DEBUG=${DEBUG} bl31 \
|| error "Failed to compile ATF!"
# Copy compiled bl31.bin
echo "- Copying BL31 (ATF firmware) file..."
[[ "${BOARD}" =~ "rk3" ]] \
&& copy build/${BOARD}/${RELEASE}/bl31/bl31.elf ${OLDPWD}/atf-bl31.elf \
|| copy build/${BOARD}/${RELEASE}/bl31.bin ${OLDPWD}/atf-bl31.bin
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit 0