-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_mainline_crust
executable file
·97 lines (80 loc) · 2.07 KB
/
compile_mainline_crust
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile official CRUST 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/verbose mode
-s CRUST 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/crust-tmp
typeset -rx ARCH=arm
typeset -rx CROSS_COMPILE=or1k-linux-musl-
typeset -x CRUST_DIR=~/git/github/crust
typeset -x PATH=~/cross-compile/or1k/or1k-linux-musl/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) CRUST_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 ${CRUST_DIR}/ ${TMPFS} \
|| error "Cannot copy ${CRUST_DIR}/* in ${TMPFS}!"
# Cleanup CRUST build
echo "- Cleaning CRUST build directory..."
cd ${TMPFS}
make clean && make distclean
# Workaround for lex/flex
sed -i "s/\(^LEX[[:blank:]]*=[[:blank:]]*\)lex/\1flex/" Makefile
# Compile CRUST
echo "- Compiling CRUST for ${BOARD} board..."
(make ${BOARD}_defconfig && make scp) \
|| error "Failed to compile CRUST!"
# Copy compiled bl31.bin
echo "- Copying CRUST firmware file..."
copy build/scp/scp.bin ${OLDPWD}/
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit 0