This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
dctt_upload.sh
executable file
·131 lines (112 loc) · 3.26 KB
/
dctt_upload.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
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
#!/bin/bash
usage() {
echo ""
echo "Usage: $0 [-P <path> -C <config-file>] [-p <serial port>] -f <hex file>"
echo -e " -P\t The avrdude binary. If not specified, script will look in /usr/bin and /usr/local/bin."
echo -e " -C\t The avrdude config file. If not specified, script will look in /usr/etc and /usr/local/etc"
echo -e " -p\t The serial port of the Arduino Mega 2560. Default: /dev/ttyACM0"
echo -e " -f\t Full path to the binary hex file. (Required)"
1>&2;
exit 1;
}
(( $# )) || usage
while getopts ":P:C:p:f:" o; do
case "${o}" in
P)
avrdude_binary=${OPTARG}
;;
C)
avrdude_config=${OPTARG}
;;
p)
port=${OPTARG}
;;
f)
file=${OPTARG}
;;
*)
usage
;;
esac
done
#
# Setup path to avrdude binary and config file.
#
if ([ "${avrdude_binary}" ] && [ "${avrdude_config}" ]); then
if [ ! -f "${avrdude_binary}" ]; then
echo "ERROR: Could not find avrdude here: $avrdude_binary. Install avrdude, e.g. sudo apt-get install avrdude"
exit 1
fi
if [ ! -f "${avrdude_config}" ]; then
echo "ERROR: Could not find avrdude config file here: $avrdude_config."
exit 1
fi
else
# Check that -P and -C are specified together.
if ( ([ -z "${avrdude_binary}" ] && [ "${avrdude_config}" ]) || ([ -z "${avrdude_config}" ] && [ "${avrdude_binary}" ])); then
echo "ERROR: -P and -C parameters need to be used in conjunction."
exit 1
fi
fi
# If avrdude is not pointed out explicitly, use defaults.
if [ -z "${avrdude_binary}" ]; then
if [ -f "/usr/local/bin/avrdude" ]; then
avrdude_binary="/usr/local/bin/avrdude"
if [ -f "/usr/local/etc/avrdude.conf" ]; then
avrdude_config="/usr/local/etc/avrdude.conf"
else
echo "ERROR: Could not find avrdude config file here: $avrdude_config."
exit 1
fi
else
if [ -f "/usr/bin/avrdude" ]; then
avrdude_binary="/usr/bin/avrdude"
if [ -f "/etc/avrdude.conf" ]; then
avrdude_config="/etc/avrdude.conf"
else
echo "ERROR: Could not find avrdude config file here: $avrdude_config."
exit 1
fi
else
echo "ERROR: Could not find avrdude in /usr/bin or /usr/bin/local. Install avrdude, e.g. sudo apt-get install avrdude"
exit 1
fi
fi
fi
#
# Arduino serial port
#
# If no port is defined, use default.
if [ -z "${port}" ]; then
port="/dev/ttyACM0"
fi
# Use stty and to see if the port "exists".
stty -F ${port} &> /dev/null;
if [ "$?" != "0" ]; then
echo "ERROR: The serial port ${port} does not exist."
exit 1
fi
#
# HEX file
#
# Check if the file exists.
if [ -z "${file}" ]; then
exit 1
fi
if [ ! -f "${file}" ]; then
echo "ERROR: The file ${file} does not exist."
exit 1
fi
cmd="${avrdude_binary} -C${avrdude_config} -patmega2560 -cstk500v2 -P${port} -b115200 -D -u -V -Uflash:w:${file}:i"
echo "Using following settings:"
echo ""
echo "Avrdude binary: ${avrdude_binary}"
echo "Avrdude config: ${avrdude_config}"
echo "Arduino Mega 2560 serial port: ${port}"
echo "Door Controller Test Tool binary file: ${file}"
echo ""
echo "-------------------------------"
echo "Starting avrdude write process!"
echo "-------------------------------"
echo "${cmd}"
$cmd