forked from smittytone/RP2040-FreeRTOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·105 lines (90 loc) · 2.27 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
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
#!/usr/bin/env bash
#
# Deploy RP2040 application code
#
# @copyright 2022, Tony Smith @smittytone
# @version 1.0.1
# @license MIT
#
# GLOBALS
timeout=30
do_build=0
rpi_path="/Volumes/RPI-RP2"
uf2_path="UNDEFINED"
# FUNCTIONS
show_help() {
echo -e "Usage:\n"
echo -e " deploy [-b][-h] /path/to/compiled/uf2/file\n"
echo -e "Options:\n"
echo " -b / --build Build the app first. Default: use a"
echo " pre-built version of the app"
echo " -h / --help Show this help screen"
echo
}
# RUNTIME START
for arg in "$@"; do
check_arg=${arg,,}
if [[ "$check_arg" = "--help" || "$check_arg" = "-h" ]]; then
show_help
exit 0
elif [[ "$check_arg" = "--build" || "$check_arg" = "-b" ]]; then
do_build=1
else
uf2_path="$arg"
fi
done
if [[ "${uf2_path}" == "UNDEFINED" ]]; then
show_help
exit 0
fi
# Check we have what looks like a UF2
extension="${uf2_path##*.}"
if [[ "${extension}" != "uf2" ]]; then
echo "[ERROR] ${uf2_path} does not indicate a .uf2 file"
exit 1
fi
# Do we build first?
err=0
if [[ ${do_build} -eq 1 ]]; then
if [[ ! -e "./build" ]]; then
# No build folder? Then create it
# and configure the build
cmake -S . -B build/ -D "CMAKE_C_COMPILER:FILEPATH=$(which arm-none-eabi-gcc)" -D CMAKE_BUILD_TYPE:STRING=Release
err=$?
fi
# Build the app
cmake --build build
err=$?
fi
# Check for errors
if [[ ${err} -ne 0 ]]; then
exit 1
fi
# Wait for the RPI_R2 mount
count=0
if [ ! -e "${rpi_path}" ]; then
echo "Waiting for RP2040 device to mount"
while [ ! -e "${rpi_path}" ]; do
sleep 1
((count+=1))
if [[ $count -eq $timeout ]]; then
echo "[ERROR] RP2040 device not mounted after ${timeout}s... exiting"
exit 1
fi
done
fi
echo "RP2040 device mounted..."
# Check for available app file
if [ ! -e "${uf2_path}" ]; then
echo "[ERROR] Cannot find file ${uf2_path}... exiting"
exit 1
fi
echo "Copying ${uf2_path##*/} to ${rpi_path}/${uf2_path##*/}"
# Copy file
if cp "${uf2_path}" "${rpi_path}"; then
echo "${uf2_path##*/} copied to ${rpi_path}"
else
echo "[ERROR] Could not copy ${uf2_path##*/} to ${rpi_path}/${uf2_path##*/}"
exit 1
fi
exit 0