forked from mmone/marlintool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
marlintool.sh
executable file
·273 lines (223 loc) · 7.56 KB
/
marlintool.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
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
271
272
273
#!/bin/bash
# by mmone with contribution by jhol
# on github at https://github.com/mmone/marlintool
# Marlin fork optimized for the AnetA8 Prusa clone
marlinRepositoryUrl="https://github.com/SkyNet3D/Marlin"
# Original Marlin
# marlinRepositoryUrl="https://github.com/MarlinFirmware/Marlin"
# Anet board
boardString="anet:avr:anetv1"
# Arduino Mega
# boardString="arduino:avr:mega:cpu=atmega2560"
arduinoToolchainVersion="1.8.2"
# Toolchain architecture
arch=$(uname -m)
case $arch in
arm*) arduinoToolchainArchitecture="linuxarm" ;;
i386|i486|i586|i686) arduinoToolchainArchitecture="linux32" ;;
x86_64) arduinoToolchainArchitecture="linux64" ;;
*)
>&2 echo "Unsuppored platform architecture: $arch"
exit 1
;;
esac
# Serialport for uploading
port="/dev/ttyUSB0"
# Where to put the arduino toolchain
arduinoDir="./arduino"
# Where to checkout Marlin sources
marlinDir="Marlin"
# Build directory
buildDir="./build"
# The path to additional hardware defnitions for the arduino tool chain
# eg. sanguino boards that live in "/arduino/hardware".
# Set to an empty string if you dont need this.
hardwareDefintionDirectory="./hardware/anet"
scriptName=$0
## Checks that the tools listed in arguments are all installed.
checkTools()
{
for cmd in "$@"; do
type -p $cmd >/dev/null || [ -x /usr/bin/$cmd ] || [ -x /bin/$cmd ] || [ -x /sbin/$cmd ] || {
>&2 echo "The following tools must be installed:"
>&2 echo " $@"
>&2 echo " Failed to find $cmd"
>&2 echo
exit 1
}
done
}
## Download the toolchain and unpack it
getArduinoToolchain()
{
echo -e "\nDownloading Arduino environment ...\n"
wget http://downloads-02.arduino.cc/arduino-"$arduinoToolchainVersion"-"$arduinoToolchainArchitecture".tar.xz
mkdir "$arduinoDir"
echo -e "\nUnpacking Arduino environment. This might take a while ... "
tar -xf arduino-"$arduinoToolchainVersion"-"$arduinoToolchainArchitecture".tar.xz -C "$arduinoDir" --strip 1
rm -R arduino-"$arduinoToolchainVersion"-"$arduinoToolchainArchitecture".tar.xz
}
## Get dependencies and move them in place
getDependencies()
{
echo -e "\nDownloading libraries ...\n"
git clone https://github.com/kiyoshigawa/LiquidCrystal_I2C.git
rm -rf "$arduinoDir"/libraries/LiquidCrystal_I2C
mv -f LiquidCrystal_I2C/LiquidCrystal_I2C "$arduinoDir"/libraries/LiquidCrystal_I2C
rm -rf LiquidCrystal_I2C
git clone https://github.com/lincomatic/LiquidTWI2.git
rm -rf "$arduinoDir"/libraries/LiquidTWI2
mv -f LiquidTWI2 "$arduinoDir"/libraries/LiquidTWI2
rm -rf LiquidTWI2
git clone https://github.com/olikraus/U8glib_Arduino.git
mv -f U8glib_Arduino "$arduinoDir"/libraries/U8glib_Arduino
rm -rf U8glib_Arduino
}
## Clone Marlin
getMarlin()
{
echo -e "\nCloning Marlin \"$marlinRepositoryUrl\"...\n"
git clone "$marlinRepositoryUrl" "$marlinDir"
exit
}
## Update an existing Marlin clone
checkoutMarlin()
{
date=`date +%Y-%m-%d-%H-%M-%S`
# backup configuration
backupMarlinConfiguration $date
cd $marlinDir
echo -e "\nFetching most recent Marlin from \"$marlinRepositoryUrl\"..\n"
git fetch
git checkout
git reset origin/`git rev-parse --abbrev-ref HEAD` --hard
echo -e "\n"
cd ..
restoreMarlinConfiguration $date
exit
}
## Get the toolchain and Marlin, install board definition
setupEnvironment()
{
echo -e "\nSetting up build environment in \"$arduinoDir\" ...\n"
getArduinoToolchain
getDependencies
installHardwareDefinition
exit
}
## Install board definition
installHardwareDefinition()
{
if [ "$hardwareDefintionDirectory" != "" ]; then
echo -e "\nInstalling board hardware definition ... \n"
cp -R "$hardwareDefintionDirectory" "$arduinoDir"/hardware/
fi
}
## Backup Marlin configuration
## param #1 backup name
backupMarlinConfiguration()
{
echo -e "\nSaving Marlin configuration\n"
echo -e " \"Configuration.h\""
echo -e " \"Configuration_adv.h\""
echo -e "\nto \"./configuration/$1/\"\n"
mkdir -p configuration/$1
cp "$marlinDir"/Marlin/Configuration.h configuration/"$1"
cp "$marlinDir"/Marlin/Configuration_adv.h configuration/"$1"
}
## Restore Marlin Configuration from backup
## param #1 backup name
restoreMarlinConfiguration()
{
if [ -d "configuration/$1" ]; then
echo -e "Restoring Marlin configuration\n"
echo -e " \"Configuration.h\""
echo -e " \"Configuration_adv.h\""
echo -e "\nfrom \"./configuration/$1/\"\n"
cp configuration/"$1"/Configuration.h "$marlinDir"/Marlin/
cp configuration/"$1"/Configuration_adv.h "$marlinDir"/Marlin/
else
echo -e "\nBackup configuration/$1 not found!\n"
fi
exit
}
## Build Marlin
verifyBuild()
{
echo -e "\nVerifying build...\n"
./arduino/arduino --verify --verbose --board "$boardString" "$marlinDir"/Marlin/Marlin.ino --pref build.path="$buildDir"
exit
}
## Build Marlin and upload
buildAndUpload()
{
echo -e "\nBuilding and uploading Marlin build from \"$buildDir\" ...\n"
./arduino/arduino --upload --port "$port" --verbose --board "$boardString" "$marlinDir"/Marlin/Marlin.ino --pref build.path="$buildDir"
exit
}
## Delete everything that was downloaded
cleanEverything()
{
rm -Rf "$arduinoDir"
rm -Rf "$marlinDir"
rm -Rf "$buildDir"
}
## Print help
printDocu()
{
echo "Usage:"
echo " $scriptName ARGS"
echo
echo "Builds an installs Marlin 3D printer firmware."
echo
echo "Options:"
echo
echo " -s, --setup Download and configure the toolchain and the"
echo " necessary libraries for building Marlin."
echo " -m, --marlin Download Marlin sources."
echo " -f, --fetch Update an existing Marlin clone."
echo " -v, --verify Build without uploading."
echo " -u, --upload Build and upload Marlin."
echo " -b, --backupConfig [name] Backup the Marlin configuration to the named backup."
echo " -r, --restoreConfig [name] Restore the given configuration into the Marlin directory."
echo " Rename to Configuration.h implicitly."
echo " -c, --clean Cleanup everything. Remove Marlin sources and Arduino toolchain"
echo " -p, --port [port] Set the serialport for uploading the firmware."
echo " Overrides the default in the script."
echo " -h, --help Show this doc."
echo
exit
}
checkTools git tar wget
if [ "$1" = "" ]; then printDocu; exit 1; fi
while [ "$1" != "" ]; do
case $1 in
-p | --port ) shift
port=$1
;;
-s | --setup ) setupEnvironment
;;
-m | --marlin ) getMarlin
;;
-f | --fetch ) checkoutMarlin
;;
-v | --verify ) verifyBuild
;;
-u | --upload ) buildAndUpload
;;
-b | --backupConfig ) shift
backupMarlinConfiguration $1 exit
;;
-r | --restoreConfig ) shift
restoreMarlinConfiguration $1
;;
-c | --clean ) shift
cleanEverything
;;
-h | --help ) printDocu
;;
* ) printDocu
exit 1
esac
shift
done