forked from MarlinFirmware/Marlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-lulzbot-firmware.sh
executable file
·354 lines (321 loc) · 8.18 KB
/
build-lulzbot-firmware.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/sh
####
# Copyright (C) 2017 AlephObjects, Inc.
#
#
# The bash script in this page is free software: you can
# redistribute it and/or modify it under the terms of the GNU Affero
# General Public License (GNU AGPL) as published by the Free Software
# Foundation, either version 3 of the License, or (at your option)
# any later version. The code is distributed WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU AGPL for more details.
#
####
# The following variables list the models and toolheads to build for:
UNIVERSAL_TOOLHEADS="AchemonSphinx_SmallLayer CecropiaSilk_SingleExtruderAeroV2 BandedTiger_HardenedSteel DingyCutworm_HardenedSteelPlus"
MINI_MODELS="Gladiola_Mini Gladiola_MiniLCD"
MINI_TOOLHEADS="Gladiola_SingleExtruder Albatross_Flexystruder Finch_Aerostruder $UNIVERSAL_TOOLHEADS"
TAZ_MODELS="Juniper_TAZ5 Oliveoil_TAZ6"
TAZ_TOOLHEADS="Tilapia_SingleExtruder Kanyu_Flexystruder Opah_Moarstruder Javelin_DualExtruderV2 Longfin_FlexyDually Yellowfin_DualExtruderV3 Angelfish_Aerostruder $UNIVERSAL_TOOLHEADS"
TAZ_PRO_MODELS="Quiver_TAZPro"
TAZ_PRO_TOOLHEADS="Quiver_DualExtruder $UNIVERSAL_TOOLHEADS"
MINI2_MODELS="Hibiscus_Mini2"
MINI2_TOOLHEADS="$UNIVERSAL_TOOLHEADS"
####
# usage
#
# Prints out a usage summary
#
usage() {
echo
echo "Usage: $0 [-s|--short-names] [-h|--hash] [-c|--config] [printer_model toolhead_name]"
echo
echo " -s|--short-names Omits LulzBot code names from generated .hex files"
echo
echo " -h|--hash Records md5sum of the .hex files. These files will be generated:"
echo " md5sums-full* Sum w/ embedded version str and timestamp"
echo " md5sums-bare* Sum w/o embedded version str and timestamp"
echo
echo " -c|--config Save the values of 'Configuration.h' and 'Configuration_adv.h'"
echo " that are used for the specified printer and toolhead."
echo " -n|--dry-run Just print commands, don't execute"
echo
exit
}
####
# compile_dependencies <printer>
#
# Compiles dependencies for the specific printer
#
compile_dependencies() {
printer=$1 ; shift 1
get_arch_info $printer
case $HARDWARE_MOTHERBOARD in
1592)
ARCHIM_SRC="ArduinoAddons/arduino-1.8.5/packages/ultimachine/hardware/sam/1.6.9-b"
(cd "$ARCHIM_SRC/system/libsam/build_gcc"; ARM_GCC_TOOLCHAIN="$gcc_path" make)
cp -u $ARCHIM_SRC/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a $ARCHIM_SRC/variants/archim/libsam_sam3x8e_gcc_rel.a
cp -u $ARCHIM_SRC/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt $ARCHIM_SRC/variants/archim/libsam_sam3x8e_gcc_rel.a.txt
;;
*) ;;
esac
}
####
# compile_firmware <printer> <toolhead> [makeopts]
#
# Compiles firmware for the specified printer and toolhead
#
get_arch_info() {
printer=$1 ; shift 1
case $printer in
Quiver_TAZPro | Unsupported_ArchimTAZ6 | Unsupported_ArchimRedGum)
gcc_path=$ARM_TOOLS_PATH
format=bin
HARDWARE_MOTHERBOARD=1592
;;
*)
gcc_path=$AVR_TOOLS_PATH
format=hex
HARDWARE_MOTHERBOARD=301
;;
esac
}
####
# compile_firmware <printer> <toolhead> [makeopts]
#
# Compiles firmware for the specified printer and toolhead
#
compile_firmware() {
printer=$1 ; shift 1
toolhead=$1 ; shift 1
# Build the firmware
(cd Marlin; make clean; make $MAKE_FLAGS HARDWARE_MOTHERBOARD=${HARDWARE_MOTHERBOARD} AVR_TOOLS_PATH=${gcc_path}/ MODEL=${printer} TOOLHEAD=${toolhead} $*) || exit
}
####
# record_checksum <hex_file> <checksum-file-prefix>
#
# Records the md5sum of a hex file to the checksum file
#
record_checksum() {
HEX_NAME=`basename $1`
VERSION=`echo $HEX_NAME | sed -r "s/Marlin_(.+)_(.+)_(.+)_(.+)_(.+)_(.+).hex/\5-\6/"`
VARIANT=`echo $HEX_NAME | sed -r "s/Marlin_(.+)_(.+)_(.+)_(.+)_(.+)_(.+).hex/\1_\2 \3_\4/"`
cat $1 | md5sum | sed "s/-/$VARIANT/" >> ${2}-${VERSION}.txt
}
####
# generate_bare_checksum <printer> <toolhead>
#
# Builds firmware without timestamp and version strings, and
# saves md5sum to a file. These are useful to see if anything
# actually changed between two versions.
#
generate_bare_checksum() {
echo
echo Generating bare checksum for $1 and $2
echo
compile_firmware $1 $2 NO_TIMESTAMP=1 NO_VERSION=1
record_checksum Marlin/applet/*.hex build/md5sums-bare
}
####
# build_config <printer> <toolhead>
#
# Compiles Configuration.h and Configuration_adv.h for the specified printer and toolhead
#
build_config() {
echo
echo Generating config for $1 and $2
echo
compile_firmware $1 $2 config
}
####
# build_firmware <printer> <toolhead> <dest-dir>
#
# Compiles firmware for the specified printer and toolhead
#
build_firmware() {
printer=$1 ; shift 1
toolhead=$1 ; shift 1
get_arch_info $printer
if [ $MAKE_HASHES ]; then
generate_bare_checksum $printer $toolhead
fi
echo
echo Building for $printer and $toolhead
echo
compile_firmware $printer $toolhead
if [ $MAKE_HASHES ]; then
record_checksum Marlin/applet/*.hex build/md5sums-full
fi
if [ $DRY_RUN ]; then
return
fi
mv Marlin/applet/*.$format build
chmod a-x build/*
if [ $GENERATE_CONFIG ]; then
build_config $printer $toolhead
mv Marlin/applet/*.config build
fi
}
####
# check_tool <path> <exec_name>
#
# Checks whether a tool exists in path
#
check_tool() {
if [ ! -x "$1/$2" ]; then
echo Cannot locate $2 in $1.
exit 1
fi
}
####
# locate_tools <path_var> <prefix>
#
# Attempts to locate a tool, otherwise prompts
# the user for a location. The found path is
# stored in <path_var>
#
locate_tools() {
DEST_VAR=$1
TOOL_BINARY=`which $2-objcopy`
if [ $? -eq 0 ]; then
TOOLS_PATH=`dirname $TOOL_BINARY`
fi
while [ ! -x $TOOLS_PATH/$2-objcopy ]
do
echo
echo $2-objcopy not found!
echo
read -p "Type path to $2 tools: " TOOLS_PATH
if [ -z $TOOLS_PATH ]; then
echo Aborting.
exit
fi
done
eval "$DEST_VAR=$TOOLS_PATH"
}
####
# check_tools <path> <prefix>
#
# Verify that all the AVR tools we need exist in the located
# directory.
#
check_tools() {
echo
echo Using $1 for $2 tools.
echo
check_tool $1 $2-gcc
check_tool $1 $2-objcopy
check_tool $1 $2-g++
check_tool $1 $2-objdump
check_tool $1 $2-ar
check_tool $1 $2-size
}
####
# build_for_mini
#
# Build all the toolhead variants for the mini
#
build_for_mini() {
for model in $MINI_MODELS
do
for toolhead in $MINI_TOOLHEADS
do
build_firmware ${model} ${toolhead}
done
done
for model in $MINI2_MODELS
do
for toolhead in $MINI2_TOOLHEADS
do
build_firmware ${model} ${toolhead}
done
done
}
####
# build_for_taz
#
# Build all the toolhead variants for the TAZ
#
build_for_taz() {
for model in $TAZ_MODELS
do
for toolhead in $TAZ_TOOLHEADS
do
build_firmware ${model} ${toolhead}
done
done
for model in $TAZ_PRO_MODELS
do
for toolhead in $TAZ_PRO_TOOLHEADS
do
build_firmware ${model} ${toolhead}
done
done
}
####
# build_summary
#
# Print out a summary of hex files that were created
#
build_summary() {
echo
echo
echo
echo Generated files stored in "`pwd`/build":
echo
ls build
echo
}
############################################
# MAIN SCRIPT
############################################
while true
do
case $1 in
-h|--hash)
MAKE_HASHES=1
shift
;;
-s|--short-names)
SHORTNAMES=1
shift
;;
-c|--config)
GENERATE_CONFIG=1
shift
;;
-n|--dry-run)
MAKE_FLAGS=-n
DRY_RUN=1
shift
;;
-*|--*)
usage
;;
*)
break
;;
esac
done
locate_tools AVR_TOOLS_PATH avr
locate_tools ARM_TOOLS_PATH arm-none-eabi
check_tools $AVR_TOOLS_PATH avr
check_tools $ARM_TOOLS_PATH arm-none-eabi
MAKE_FLAGS="$MAKE_FLAGS -j $(grep -c ^processor /proc/cpuinfo)"
rm -rf build
mkdir build
if [ $# -eq 2 ]
then
compile_dependencies $1
build_firmware $1 $2
else
compile_dependencies Quiver_TAZPro
build_for_mini
build_for_taz
fi
if [ $SHORTNAMES ]; then
rename 's/Marlin_(.+)_(.+)_(.+)_(.+)_(.+)_(.+).hex/Marlin_$2_$4_$5_$6.hex/' build/*
rename 's/Marlin_(.+)_(.+)_(.+)_(.+)_(.+)_(.+).config/Marlin_$2_$4_$5_$6.config/' build/*
fi
build_summary