-
Notifications
You must be signed in to change notification settings - Fork 17
/
odroid
executable file
·270 lines (219 loc) · 5.25 KB
/
odroid
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
#!/bin/sh
# Client for the webserver
#
# File management and control requests require `curl` to be installed.
#
# Connecting to the Serial or Console interfaces requires a version of
# `websocat` build with SSL support. (see
# https://github.com/vi/websocat)
#
# This can be installed with cargo using:
#
# cargo install \
# --git https://github.com/vi/websocat.git \
# --features ssl
AUTH_TOKEN_FILE="$HOME/.aos_auth_token"
AOS_DOMAIN="aos-2.cse.unsw.edu.au"
AOS_HTTP_URL="https://${AOS_DOMAIN}"
AOS_WS_URL="wss://${AOS_DOMAIN}"
if [ ! -e "${AUTH_TOKEN_FILE}" ]; then
printf "Enter UNSW zID: "
read zid
if token=$(curl -f -s -u "${zid}" "${AOS_HTTP_URL}/token")
then
touch "${AUTH_TOKEN_FILE}"
chmod 600 "${AUTH_TOKEN_FILE}"
printf "%s" "$token" > "${AUTH_TOKEN_FILE}"
else
echo "Failed to authenticate"
exit 1
fi
fi
COMMAND_NAME="$0"
BEARER_HEADER=""
http_query () {
path=$1; shift
curl \
-H "Authorization: Bearer $(cat "${AUTH_TOKEN_FILE}")" \
"${AOS_HTTP_URL}/${path}" \
"$@"
echo
}
ws_stream () {
path=$1; shift
websocat \
--binary -E \
--ping-interval 5 \
--ping-timeout 20 \
"$@" \
-H "Authorization: Bearer $(cat "${AUTH_TOKEN_FILE}")" \
-- - "${AOS_WS_URL}/${path}"
}
# Download the boot image
download_boot () {
if [ "$#" -lt 1 ]; then
image_name="sos-image-arm-odroidc2"
else
image_name="$1"
fi
http_query "boot-file" -o "$image_name"
}
# Upload a new boot image
upload_boot () {
http_query "boot-file" -T "$1"
}
# Delete the boot image
delete_boot () {
http_query "boot-file" -X DELETE
}
# List the NFS directory
list () {
http_query "nfs" -s | column -s ' ' -t
}
# Download files from the NFS directory
download () {
while [ "$#" -gt 0 ]; do
file=$1; shift
mkdir -p "$(dirname "$file")"
http_query "nfs/$(basename "$file")" -o "$file"
done
}
# Upload files to the NFS directory
upload () {
while [ "$#" -gt 0 ]; do
file=$1; shift
http_query "nfs/$(basename "$file")" -T "$file"
done
}
# Delete files from the NFS directory
delete () {
while [ "$#" -gt 0 ]; do
file=$1; shift
http_query "nfs/$(basename "$file")" -X DELETE
done
}
# Restart the ODroidC2
reset () {
http_query "reset" -X POST
}
# Request to be allocated a different ODroid
#
# Only do this after talking to tutors or course staff
reallocate () {
http_query "reallocate" -X POST
}
# Request to be allocated a specific ODroid
#
# Do not do this unless you are course staff
take () {
odroid=$1; shift
http_query "take/${odroid}" -X POST
}
# Get a list of all odroids
odroids () {
http_query "odroids" -s
}
# Get a list of all odroids
odroid_status () {
http_query "status" -s
}
# Run the test image on the odroid
odroid_test () {
http_query "test" -X POST
}
# Reset the Das-UBoot configuration
reconfigure () {
http_query "reconfigure" -X POST
}
# Connect to the hardware UART stream
serial () {
ws_stream serial "$@"
}
# Connect to the hardware UART stream
serial_raw () {
ws_stream serial_raw "$@"
}
# Connect to the network console
netcon () {
ws_stream netcon "$@"
}
# Connect to a arbitrary TCP port on the odroid
tcp () {
port=$1; shift
ws_stream "tcp/$port" "$@"
}
show_help () {
cat <<- __end_help
ODroidC2 multiplexer client
Tool to manage assigned ODroidC2 for AOS course
Usage: ${COMMAND_NAME} <command>
Commands:
download-boot <file>
Download the current boot image.
upload-boot <file>
Upload a new boot image.
rm-boot
Remove the current boot image.
ls
List all of the files in the NFS directory.
download <file>...
Download one or more files from the NFS directoy.
upload <file>...
Upload one or more files to the NFS directoy.
rm <file>...
Remove one or more files from the NFS directory.
reset, restart
Send the 'reset' command to the ODroidC2. This will cause U-Boot
or seL4 to reset the device.
reallocate
Request allocation of a different ODroidC2. Only use this if you
are having issues with your assigned ODroidC2 (specifically, you're
unable to reset it) and have spoken to a tutor or course staff.
take <n>
Take an odroid with a specific numeric identifier
reconfigure
Reload the configuration for the U-Boot bootloader.
status
get the details of the allocated odroid
odroids
List all of the odroids
serial
Connect to the ODroidC2's UART output (where
\`seL4_DebugPutChar\` prints). This is read-only.
serial_raw
Connect GDB to the ODroidC2's UART output for debugging. Do
not use for any other type of access.
netcon
Connect to assigned ODroidC2's UDP network console
interface interactively.
tcp <port>
Connect to a TCP port on the ODroidC2.
help, --help, -h
Show this help message.
__end_help
}
action=$1; shift;
case "${action}" in
"download-boot") download_boot "$@";;
"upload-boot") upload_boot "$@";;
"rm-boot") delete_boot;;
"ls") list;;
"download") download "$@";;
"upload") upload "$@";;
"rm") delete "$@";;
"reset") reset;;
"restart") reset;;
"reallocate") reallocate;;
"status") odroid_status;;
"test") odroid_test;;
"take") take "$@";;
"reconfigure") reconfigure;;
"odroids") odroids;;
"serial") serial "$@";;
"serial_raw") serial_raw "$@";;
"netcon") netcon "$@";;
"tcp") tcp "$@";;
"help") show_help;;
"--help") show_help;;
"-h") show_help;;
esac