-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautobuild.sh
More file actions
executable file
·333 lines (303 loc) · 11.1 KB
/
autobuild.sh
File metadata and controls
executable file
·333 lines (303 loc) · 11.1 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/bin/sh
set -Eeuo pipefail
# DIAGNOSTICS
SCRIPT_USER=`whoami`
SCRIPT_HM=`uname -n`
SCRIPT_DATE=`date +%Y%m%dT%H%M%S.%N`
SCRIPT_DIR=`pwd`
SCRIPT_PROG=$0
SCRIPT_ARGS=$@
SCRIPT_DIAGNOSTICS_SHORT="$SCRIPT_USER@$SCRIPT_HM:$SCRIPT_DIR/$SCRIPT_PROG $SCRIPT_ARGS"
SCRIPT_UNAME=`uname -n -s -r -m`
function print_diagnostics_short(){
echo "INFO: `date +%Y%m%dT%H%M%S.%N`: $SCRIPT_DIAGNOSTICS_SHORT"
}
function print_diagnostics() {
echo "----------------------------------------"
echo $SCRIPT_PROG $SCRIPT_ARGS
echo "----------------------------------------"
echo "Running as: $SCRIPT_USER@$SCRIPT_HM "
echo "Script Directory: $SCRIPT_DIR"
echo "Script Launch Date: $SCRIPT_DATE"
echo "Uname: $SCRIPT_UNAME"
echo "----------------------------------------"
echo "Current Time: `date +%Y%m%dT%H%M%S.%N` "
echo "PWD: `pwd` "
echo "----------------------------------------"
}
function check_rc() {
local rc=$1
local cmd_name=${2:-"Previous command"}
if [[ $rc != 0 ]]; then
echo "----------------------------------------"
echo "ERROR: ${cmd_name} returned non-zero exit code, exiting..."
echo "----------------------------------------"
print_diagnostics
exit $rc
fi
}
rc=0
# Used for validating values from user
VALID_PRODUCTS=('TATE_NRNT' 'LILY' 'VAUNT' 'AVERY')
VAUNT_RTMS=('RTM6' 'RTM7' 'RTM8' 'RTM9' 'RTM10' 'RTM11' 'RTM12' 'RTM15')
VAUNT_RATES=('NA') # Vaunt detects sample rate at runtime
AVERY_RTMS=('RTM1' 'RTM2')
AVERY_RATES=$VAUNT_RATES # Avery (based on Vaunt) detects sample rate at runtime
TATE_RTMS=('RTM3' 'RTM4' 'RTM5' 'RTM6' 'RTM7')
TATE_RATES=('1000' '3000')
LILY_RTMS=('RTM0' 'RTM1')
LILY_RATES=('500')
function print_help() {
echo "Compiles server for device with provided configuration options."
echo "Usage:"
echo " ./autobuild.sh -p <PRODUCT> -v <RTM_VERSION> -r <NUM_RX> -t <NUM_TX> -s <MAX_RATE_MHZ> [optional flags]..."
echo " ./autobuild.sh [-h|--help] # Prints this help menu"
echo ""
echo "Required:"
echo " -p, --product The product to compile the server for (TATE_NRNT | LILY | VAUNT | AVERY)"
echo " -v, --hw-revision The hardware revision to compile for (RTM5, RTM6, etc...)"
echo " -r, --rx-channels The number of Rx channels on the device"
echo " -t, --tx-channels The number of Tx channels on the device"
echo " -s, --max-rate The max sample rate of the device in MHz (3000|1000|500|NA)"
echo ""
echo "Optional:"
echo " -h, --help Print help message showing usage and options for this script"
echo " --rx_40ghz_fe (DEPRICATE, use AVERY product instead) Indicates the device Tx board has been replaced by a 40GHz Rx frontend"
echo " --use_3g_as_1g Use 1GSPS sample rate with 3GSPS backplane"
echo " --user_lo Enable user LO mode"
echo ""
echo "Examples:"
echo " ./autobuild.sh -p VAUNT -v RTM10 -r 4 -t 4 -s NA # Vaunt RTM10. Vaunt detects sample rate at runtime, so set to NA for compilation"
echo " ./autobuild.sh -p TATE_NRNT -v RTM5 -r 4 -t 4 -s 1000 --use_3g_as_1g # Tate RTM5 using 3G backplane as 1G"
echo " ./autobuild.sh -p LILY -v RTM1 -r 4 -t 4 -s 500 # Lily RTM1"
}
# Compares a value to an array of valid values
function validate_value() {
local val=$1
shift
local valid_values=("$@")
local is_valid=0
for v in ${valid_values[@]}; do
if [ "${val}" == "$v" ]; then
is_valid=1
break
fi
done
return $is_valid
}
function check_argument_exists() {
local name=$1
local arg=${2:-}
if [ -z $arg ]; then
print_diagnostics_short
echo "[ERROR] $name was not specified but is required for compilation."
exit 1
fi
}
# Required arguments
PRODUCT=
HW_REV=
NUM_RX=
NUM_TX=
MAX_RATE=
# Optional arguments
RX_40GHZ_FE=0
USE_3G_AS_1G=0
USER_LO=0
# Parse arguments/flags
while [ $# -gt 0 ]; do
key="$1"
case $key in
-h|--help)
print_help
exit 0
;;
-p|--product)
if [ -z "${2:-}" ]; then
print_diagnostics_short
echo "[ERROR] Could not find value for -p|--product flag."
echo " Make sure you provide a valid product after the product flag."
exit 1
fi
PRODUCT="${2^^}"
shift
shift
;;
-v|--hw-revision)
if [ -z "${2:-}" ]; then
print_diagnostics_short
echo "[ERROR] Could not find value for -v|--hw-revision flag."
echo " Make sure you provide a valid RTM number after the hardware revision flag."
exit 1
fi
HW_REV="${2^^}"
shift
shift
;;
-r|--rx-channels)
if [ -z "${2:-}" ]; then
print_diagnostics_short
echo "[ERROR] Could not find value for -r|--rx-channels flag."
echo " Make sure you provide a value after the rx-channels flag."
exit 1
fi
NUM_RX="R$2"
shift
shift
;;
-t|--tx-channels)
if [ -z "${2:-}" ]; then
print_diagnostics_short
echo "[ERROR] Could not find value for -t|--tx-channels flag."
echo " Make sure you provide a value after the rx-channels flag."
exit 1
fi
NUM_TX="T$2"
shift
shift
;;
-s|--max-rate)
if [ -z "${2:-}" ]; then
print_diagnostics_short
echo "[ERROR] Could not find value for -s|--max-rate flag."
echo " Make sure you provide a value after the max rate flag."
exit 1
fi
MAX_RATE=$2
shift
shift
;;
--rx_40ghz_fe)
# Depricated: rx_40ghz_fe is now compiled using -p AVERY
# Indicates the unit is an avery rx where the tx board has been replaced by a 40GHz RX front end
RX_40GHZ_FE=1
shift
;;
--use_3g_as_1g)
# Uses 1GSPS sample rate with 3GSPS backplane, can use 3GSPS or 1GSPS RFEs.
# The server will set 3GSPS RX boards programmed with Rx3 code to 1GSPS mode.
# TX boards must be programmed with regular (1GSPS) Tx mcu.
# Time board must be programmed with Time1on3 mcu if 3GSPS RX boards, or regular (1GSPS) time mcu if 1GSPS RX boards.
USE_3G_AS_1G=1
shift
;;
--user_lo)
USER_LO=1
shift
;;
*)
print_diagnostics $@
echo Unrecognized option: $key
echo
print_help
exit 1
;;
esac
done
# Validate values and check that required arguments were included
check_argument_exists "Product" $PRODUCT
if validate_value $PRODUCT ${VALID_PRODUCTS[@]}; then
print_diagnostics_short
echo "[ERROR] Invalid product: $PRODUCT"
echo " Valid products are: ${VALID_PRODUCTS[@]}"
exit 1
fi
# Alias VAUNT RTM10 rx_40ghz_fe to AVERY RTM1
# If rx_40ghz_fe was requested for anything other than VAUNT RTM10 throw an error
if [ $RX_40GHZ_FE == 1 ]; then
echo "[WARNING]: --rx_40ghz_fe is depricated"
if [ "$PRODUCT" == "AVERY" ]; then
echo "--rx_40ghz_fe is redundant for Avery, ignoring"
RX_40GHZ_FE=0
elif [ "$PRODUCT" == "VAUNT" && "$HW_REV" == "RTM10" ]; then
echo "VAUNT RTM10 matches AVERY RTM1, aliasing"
RX_40GHZ_FE=0
PRODUCT="AVERY"
HW_REV="RTM1"
else
print_diagnostics_short
echo "[ERROR]: no know equivalent for rx_40ghz_fe, aborting"
exit 1
fi
fi
if [ $PRODUCT == "VAUNT" ]; then
VALID_RTMS=${VAUNT_RTMS[@]}
VALID_RATES=${VAUNT_RATES[@]}
elif [ $PRODUCT == "AVERY" ]; then
VALID_RTMS=${AVERY_RTMS[@]}
VALID_RATES=${AVERY_RATES[@]}
elif [ $PRODUCT == "TATE_NRNT" ]; then
VALID_RTMS=${TATE_RTMS[@]}
VALID_RATES=${TATE_RATES[@]}
elif [ $PRODUCT == "LILY" ]; then
VALID_RTMS=${LILY_RTMS[@]}
VALID_RATES=${LILY_RATES[@]}
fi
check_argument_exists "Hardware revision" $HW_REV
if validate_value $HW_REV ${VALID_RTMS[@]}; then
print_diagnostics_short
echo "[ERROR] Invalid RTM: $HW_REV"
echo " Valid RTMS for specified product are: ${VALID_RTMS[@]}"
exit 1
fi
check_argument_exists "Number of Rx channels" $NUM_RX
check_argument_exists "Number of Tx channels" $NUM_TX
check_argument_exists "Max sample rate" $MAX_RATE
if validate_value $MAX_RATE ${VALID_RATES[@]}; then
print_diagnostics_short
echo "[ERROR] Invalid max sample rate: $MAX_RATE"
echo " Valid rates for specified product are: ${VALID_RATES[@]}"
exit 1
fi
# Source dkr command to run commands in Docker container with toolchains installed
source ./dkr_env.sh
# Check if the necessary docker image exists locally, if not pull
if [ -z "$(docker images -q $PV_DOCKER 2> /dev/null)" ]; then
docker pull $PV_DOCKER || rc=$?
check_rc $rc "docker pull"
fi
if [ "${PRODUCT}" == "VAUNT" ] || [ "${PRODUCT}" == "AVERY" ]; then
# Docker image has these two installed, no need to autodetect
SERVER_CC="arm-linux-gnueabihf-gcc"
SERVER_CXX="arm-linux-gnueabihf-g++"
PRODUCT_CFLAGS="-Wall -O3 -pipe -fomit-frame-pointer -Wfatal-errors \
-march=armv7-a -mtune=cortex-a9 -mfpu=neon"
elif [ "${PRODUCT}" == "TATE_NRNT" ] || [ "${PRODUCT}" == "LILY" ]; then
SERVER_CC="aarch64-linux-gnu-gcc"
SERVER_CXX="aarch64-linux-gnu-g++"
PRODUCT_CFLAGS="-Wall -O3 -pipe -fomit-frame-pointer -Wfatal-errors \
-march=armv8-a -mtune=cortex-a53"
else
print_diagnostics_short
echo "ERROR: missing compiler flags for product $PRODUCT"
exit 1
fi
# Use autoconf in Docker container to configure compilation of server
dkr ./autogen.sh clean || rc=$?
check_rc $rc "dkr ./autogen.sh clean"
dkr ./autogen.sh || rc=$?
check_rc $rc "dkr ./autogen.sh"
dkr ./configure \
--prefix=/usr \
--host=x86_64 \
CC=$SERVER_CC \
CFLAGS=\"${PRODUCT_CFLAGS} \
-Werror -lm -pthread\" \
CPPFLAGS=\"$PRODUCT_CFLAGS\" \
CXX=$SERVER_CXX \
CXXFLAGS=\"$PRODUCT_CFLAGS\" \
PRODUCT=$PRODUCT \
HW_REV=$HW_REV \
NRX=$NUM_RX \
NTX=$NUM_TX \
MAX_RATE="S${MAX_RATE}" \
USE_3G_AS_1G=$USE_3G_AS_1G \
USER_LO=$USER_LO || rc=$?
check_rc $rc "Configure"
# Compile the server through the Docker container.
# The container has a volume for this directory, so all generated files will be present on the host.
dkr make -j$(nproc) || rc=$?
check_rc $rc "Make"
echo "----------------------------------------"
echo "SUCCESS"
echo "----------------------------------------"