-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash.sh
executable file
·36 lines (33 loc) · 1.24 KB
/
flash.sh
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
#!/usr/bin/bash
build_folder="./build/src/"
player_0_u2f="player_0.uf2"
player_1_u2f="player_1.uf2"
first_pico_addr=$(lsusb | grep 2e8a | awk '{print $4}' | awk -v FS="" -v OFS="" '{ $NF = "" ; print }' | sed -n 1p)
second_pico_addr=$(lsusb | grep 2e8a | awk '{print $4}' | awk -v FS="" -v OFS="" '{ $NF = "" ; print }' | sed -n 2p)
function error_and_exit() {
echo $1
exit 1
}
# Flash player 0
if [ "$1" == "0" ]; then
echo "Flashing player 0"
if [ "${first_pico_addr}" == "" ]; then error_and_exit "Valid pico not found"; fi
picotool load "${build_folder}${player_0_u2f}" -f --address "${first_pico_addr}"
exit 0
# Flash player 1
elif [ "$1" == "1" ]; then
echo "Flashing player 1"
if [ "${first_pico_addr}" == "" ]; then error_and_exit "Valid pico not found"; fi
picotool load "${build_folder}${player_1_u2f}" -f --address "${first_pico_addr}"
exit 0
# Else, flash both
elif [ "$1" == "" ]; then
echo "Flashing player 0 & 1"
if [ "${second_pico_addr}" == "" ]; then error_and_exit "At least two valid picos not found"; fi
picotool load "${build_folder}${player_0_u2f}" -f --address "${first_pico_addr}"
picotool load "${build_folder}${player_1_u2f}" -f --address "${second_pico_addr}"
exit 0
else
echo "Unknown argument"
exit 1
fi