This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·80 lines (70 loc) · 2.36 KB
/
deploy.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
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
#!/bin/bash
# Deploy compiled firmare to RP2040-based board
# as a cli2c USB-to-I2C hardware bridge
#
# Usage:
# ./deploy.sh {path/to/device} {path/to/uf2}
#
# Examples:
# macOS: ./deploy.sh /dev/cu.usbmodem1.1 /build/firmware/pico/firmware_pico.uf2
# Linux RPiOS: ./deploy.sh /dev/ttyACMO /build/firmware/pico/firmware_pico.uf2
show_error_and_exit() {
echo "[ERROR] $1"
exit 1
}
if [[ -z ${1} ]]; then
echo "Usage: deploy.sh {path/to/device} {path/to/uf2}"
exit 0
fi
if [[ -z ${2} || ${2##*.} != "uf2" ]]; then
echo "[ERROR] No .uf2 file specified"
exit 1
fi
if [[ ! -f ${2} ]]; then
echo "[ERROR] ${2} cannot be found"
exit 1
fi
# Put the Pico onto BOOTSEL mode
platform=$(uname)
if [[ ${platform} = Darwin ]]; then
# macOS mount path
pico_path=/Volumes/RPI-RP2
stty -f ${1} 1200 || show_error_and_exit "Could not connect to device ${1}"
else
# NOTE This is for Raspberry Pi -- you may need to change it
# depending on how you or your OS locate USB drive mount points
pico_path="/media/$USER/RPI-RP2"
stty -F ${1} 1200 || show_error_and_exit "Could not connect to device ${1}"
# Allow for command line usage -- ie. not in a GUI terminal
# Command line is SHLVL 1, so script is SHLVL 2 (under the GUI we'd be a SHLVL 3)
if [[ $SHLVL -eq 2 ]]; then
# Mount the disk, but allow time for it to appear (not immediate on RPi)
sleep 5
rp2_disk=$(sudo fdisk -l | grep FAT16 | cut -f 1 -d ' ')
if [[ -z ${rp2_disk} ]]; then
show_error_and_exit "Could not see device ${1}"
fi
sudo mkdir ${pico_path} || show_error_and_exit "Could not make mount point ${pico_path}"
sudo mount ${rp2_disk} ${pico_path} -o rw || show_error_and_exit "Could not mount device ${1}"
fi
fi
echo "Waiting for Pico to mount..."
count=0
while [ ! -d ${pico_path} ]; do
sleep 0.1
((count+=1))
[[ ${count} -eq 200 ]] && show_error_and_exit "Pico mount timed out"
done
sleep 0.5
# Copy the target file
echo "Copying ${2} to ${1}..."
if [[ ${platform} = Darwin ]]; then
cp ${2} ${pico_path}
else
sudo cp ${2} ${pico_path}
if [[ $SHLVL -eq 2 ]]; then
# We're at the command line, so unmount (RPi GUI does this automatically)
sudo umount ${rp2_disk} && echo "Pico unmounted" && sudo rm -rf ${pico_path} && echo "Mountpoint removed"
fi
fi
echo Done