-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_mainline_opensbi
executable file
·126 lines (105 loc) · 2.73 KB
/
compile_mainline_opensbi
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile official OpenSBI firmware
Usage: ${SH_FILE} -b board [-c] [-h] [-d] [-s dir]
Where:
-b name of the board to configure
-c copy firmware file
-d compile firmware in debug mode
-s OpenSBI source directory
-h this help page
Currently supported boards are: beaglev/starlight, visionfive and visionfive2/visionfive2-sdk
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/opensbi-tmp
typeset -r U_BOOT_TMP=/dev/shm/u-boot-tmp
typeset -rx ARCH=riscv64
typeset -rx CROSS_COMPILE=${ARCH}-suse-linux-
typeset -x SRC_DIR=~/git/github/starfive/opensbi
typeset -x PAYLOAD_FILE=${U_BOOT_TMP}/u-boot.bin
typeset -x FDT_FILE=${U_BOOT_TMP}/u-boot.dtb
typeset BOARD COPY DEBUG OPTS
# Get options
while getopts "b:cds:h" ARG; do
case ${ARG} in
b) BOARD=${OPTARG}
;;
c) COPY=1
;;
d) DEBUG=1
;;
s) SRC_DIR=${OPTARG}
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Board model must be filled!
[[ -z "${BOARD}" ]] \
&& error "Board model must be filled!"
# Define specific options if needed
case ${BOARD} in
beaglev|starlight|visionfive|visionfive2-sdk)
OPTS="FW_OPTIONS=0 FW_PAYLOAD_PATH=${PAYLOAD_FILE} FW_FDT_PATH=${FDT_FILE}"
;;
visionfive2)
OPTS="FW_OPTIONS=0 FW_TEXT_START=0x40000000"
unset COPY
;;
esac
# Extract git branch if provided
if [[ "${SRC_DIR#*:}" != "${SRC_DIR}" ]]; then
SRC_BRANCH=${SRC_DIR#*:}
SRC_DIR=${SRC_DIR%:*}
fi
# 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 source in the tmpfs directory
rsync -aq ${SRC_DIR}/ ${TMPFS} \
|| error "Cannot copy ${SRC_DIR}/* in ${TMPFS}!"
# Go to build directory
cd ${TMPFS}
# Change branch if needed
if [[ -n "${SRC_BRANCH}" ]]; then
echo "- Checking out branch ${SRC_BRANCH}..."
git checkout ${SRC_BRANCH}
fi
# Cleanup build
echo "- Cleaning build directory..."
make clean && make distclean
# Compile OpenSBI
echo "- Compiling OpenSBI..."
make PLATFORM=generic DEBUG=${DEBUG} ${OPTS} \
|| error "Failed to compile OpenSBI!"
# Copy firmware file(s) locally if asked
if (( COPY )); then
for FILE in ${PAYLOAD_FILE} ${FDT_FILE}; do
copy ${FILE} ${OLDPWD}
done
fi
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit 0