forked from nrobinson2000/po-util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
po-util.sh
executable file
·692 lines (605 loc) · 19.4 KB
/
po-util.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/bin/bash
# __ __ __
# / | / |/ |
# ______ ______ __ __ _██ |_ ██/ ██ |
# / \ / \ ______ / | / |/ ██ | / |██ |
# /██████ |/██████ |/ |██ | ██ |██████/ ██ |██ |
# ██ | ██ |██ | ██ |██████/ ██ | ██ | ██ | __ ██ |██ |
# ██ |__██ |██ \__██ | ██ \__██ | ██ |/ |██ |██ |
# ██ ██/ ██ ██/ ██ ██/ ██ ██/ ██ |██ |
# ███████/ ██████/ ██████/ ████/ ██/ ██/
# ██ |
# ██ |
# ██/ https://po-util.com
#
# Particle Offline Utility: A handy script for installing and using the Particle
# Toolchain on Ubuntu-based distros and OSX. This script downloads and installs:
# dfu-util, nodejs, gcc-arm-embedded, particle-cli, and the Particle Firmware
# source code.
# Read more at https://github.com/nrobinson2000/po-util
# ACII Art Generated from: http://www.patorjk.com/software/taag
# Helper functions
function pause()
{
read -rp "$*"
}
blue_echo()
{
echo "$(tput setaf 6)$(tput bold)$MESSAGE$(tput sgr0)"
}
green_echo()
{
echo "$(tput setaf 2)$(tput bold)$MESSAGE$(tput sgr0)"
}
red_echo()
{
echo "$(tput setaf 1)$(tput bold)$MESSAGE$(tput sgr0)"
}
function find_objects() #Consolidated function
{
if [ "$1" != "" ];
then
case "$1" in
*/)
#"has slash"
DEVICESFILE="${1%?}"
FIRMWAREDIR="${1%?}"
FIRMWAREBIN="${1%?}"
DIRECTORY="${1%?}"
;;
*)
echo "doesn't have a slash" > /dev/null
DEVICESFILE="$1"
FIRMWAREDIR="$1"
FIRMWAREBIN="$1"
;;
esac
if [ -f "$CWD/$DEVICESFILE/devices.txt" ] || [ -d "$CWD/$FIRMWAREDIR/firmware" ] || [ -f "$CWD/$FIRMWAREBIN/bin/firmware.bin" ];
then
DEVICESFILE="$CWD/$DEVICESFILE/devices.txt"
FIRMWAREDIR="$CWD/$FIRMWAREDIR/firmware"
FIRMWAREBIN="$CWD/$FIRMWAREBIN/bin/firmware.bin"
else
if [ -d "$DIRECTORY" ] && [ -d "$DIRECTORY/firmware" ];
then
DEVICESFILE="$DIRECTORY/devices.txt"
FIRMWAREDIR="$DIRECTORY/firmware"
FIRMWAREBIN="$DIRECTORY/bin/firmware.bin"
else
if [ -d "$CWD/$DIRECTORY" ];
then
DEVICESFILE="$CWD/$DIRECTORY/../devices.txt"
FIRMWAREDIR="$CWD/$DIRECTORY"
FIRMWAREBIN="$CWD/$DIRECTORY/../bin/firmware.bin"
else
if [ "$DIRECTORY" == "." ];
then
cd "$CWD/.."
DEVICESFILE="$(pwd)/devices.txt"
FIRMWAREDIR="$CWD"
FIRMWAREBIN="$(pwd)/bin/firmware.bin"
fi
fi
fi
fi
else
DEVICESFILE="$CWD/devices.txt"
FIRMWAREDIR="$CWD/firmware"
FIRMWAREBIN="$CWD/bin/firmware.bin"
fi
if [ -d "$FIRMWAREDIR" ];
then
FIRMWAREDIR="$FIRMWAREDIR"
else
if [ "$DIRWARNING" == "true" ];
then
echo
MESSAGE="Firmware directory not found!" ; red_echo
MESSAGE="Please run \"po init\" to setup this repository or choose a valid directory." ; blue_echo
echo
fi
FINDDIRFAIL="true"
fi
if [ -f "$DEVICESFILE" ];
then
DEVICES="$(cat $DEVICESFILE)"
else
if [ "$DEVICEWARNING" == "true" ];
then
echo
MESSAGE="devices.txt not found!" ; red_echo
MESSAGE="You need to create a \"devices.txt\" file in your project directory with the names
of your devices on each line." ; blue_echo
MESSAGE="Example:" ; green_echo
echo " product1
product2
product3
"
fi
FINDDEVICESFAIL="true"
fi
if [ -f "$FIRMWAREBIN" ];
then
FIRMWAREBIN="$FIRMWAREBIN"
else
if [ "$BINWARNING" == "true" ];
then
echo
MESSAGE="Firmware Binary not found!" ; red_echo
MESSAGE="Perhaps you need to build your firmware?" ; blue_echo
echo
fi
FINDBINFAIL="true"
fi
}
build_message()
{
echo
cd "$FIRMWAREDIR"/.. || exit
BINARYDIR="$(pwd)/bin"
MESSAGE="Binary saved to $BINARYDIR/firmware.bin" ; green_echo
echo
exit
}
dfu_open()
{
if [ "$MODEM" != "" ];
then
MODEM="$MODEM"
else
echo
MESSAGE="Device not found!" ; red_echo
MESSAGE="Your device must be connected by USB."; blue_echo
echo
exit
fi
stty "$STTYF" "$MODEM" "$DFUBAUDRATE" > /dev/null
}
switch_branch()
{
if [ "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ];
then
git checkout "$BRANCH" > /dev/null
fi
}
common_commands() #List common commands
{
echo
MESSAGE="Common commands include:
build, flash, clean, ota, dfu, serial, init"
blue_echo
echo
}
build_firmware()
{
make all -s -C "$BASE_FIRMWARE/"firmware APPDIR="$FIRMWAREDIR" TARGET_DIR="$FIRMWAREDIR/../bin" PLATFORM="$1" $GCC_MAKE || exit
}
# End of helper functions
if [ "$1" == "" ]; # Print help
then
MESSAGE=" __ __ __
/ | / |/ |
______ ______ __ __ _██ |_ ██/ ██ |
/ \ / \ ______ / | / |/ ██ | / |██ |
/██████ |/██████ |/ |██ | ██ |██████/ ██ |██ |
██ | ██ |██ | ██ |██████/ ██ | ██ | ██ | __ ██ |██ |
██ |__██ |██ \__██ | ██ \__██ | ██ |/ |██ |██ |
██ ██/ ██ ██/ ██ ██/ ██ ██/ ██ |██ |
███████/ ██████/ ██████/ ████/ ██/ ██/
██ |
██ |
██/ https://po-util.com
"
blue_echo
echo "Copyright (GPL) 2016 Nathan Robinson
Usage: po DEVICE_TYPE COMMAND DEVICE_NAME
po DFU_COMMAND
po install [full_install_path]
Commands:
install Download all of the tools needed for development.
Requires sudo. You can also re-install with this command.
You can optionally install to an alternate location by
specifying [full_install_path].
Example:
po install ~/particle
By default, Firmware is installed in ~/github.
build Compile code in \"firmware\" subdirectory
flash Compile code and flash to device using dfu-util
NOTE: You can supply another argument to \"build\" and \"flash\"
to specify which firmware directory to compile.
Example:
po photon flash photon-firmware/
clean Refresh all code (Run after switching device or directory)
init Initialize a new po-util project
update Update Particle firmware, particle-cli and po-util
upgrade Upgrade system firmware on device
ota Upload code Over The Air using particle-cli
NOTE: You can flash code to multiple devices at once by passing
the -m or --multi argument to \"ota\".
Example:
po photon ota -m product-firmware/
NOTE: This is different from the product firmware update feature
in the Particle Console because it updates the firmware of
devices one at a time and only if the devices are online when
the command is run.
serial Monitor a device's serial output (Close with CRTL-A +D)
DFU Commands:
dfu Quickly flash pre-compiled code to your device.
Example:
po photon dfu
dfu-open Put device into DFU mode
dfu-close Get device out of DFU mode
"
exit
fi
# Configuration file is created at "~/.po"
SETTINGS=~/.po
BASE_FIRMWARE=~/github # These
BRANCH="latest" # can
BINDIR=~/bin # be
DFUBAUDRATE=19200 # changed in the "~/.po" file.
CWD="$(pwd)" # Global Current Working Directory variable
# Mac OSX uses lowercase f for stty command
if [ "$(uname -s)" == "Darwin" ];
then
OS="Darwin"
STTYF="-f"
MODEM="$(ls -1 /dev/cu.* | grep -vi bluetooth | tail -1)"
else
OS="Linux"
STTYF="-F"
MODEM="$(ls -1 /dev/* | grep "ttyACM" | tail -1)"
#THIS COULD BE IMPROVED!
GCC_ARM_VER=gcc-arm-none-eabi-4_9-2015q3 # Updated to 4.9
export GCC_ARM_PATH=$BINDIR/gcc-arm-embedded/$GCC_ARM_VER/bin/
# export PATH=$GCC_ARM_PATH:$PATH
fi
# Check if we have a saved settings file. If not, create it.
if [ ! -f $SETTINGS ]
then
echo BASE_FIRMWARE="$BASE_FIRMWARE" >> $SETTINGS
echo BRANCH="latest" >> $SETTINGS
echo PARTICLE_DEVELOP="1" >> $SETTINGS
echo BINDIR="$BINDIR" >> $SETTINGS
echo DFUBAUDRATE="$DFUBAUDRATE" >> $SETTINGS
if [ $OS == "Linux" ];
then
echo export GCC_ARM_PATH=$GCC_ARM_PATH >> $SETTINGS
fi
fi
# Import our overrides from the ~/.po file.
source "$SETTINGS"
# GCC path for linux make utility
if [ $GCC_ARM_PATH ]; then GCC_MAKE=GCC_ARM_PATH=$GCC_ARM_PATH ; fi
if [ "$1" == "install" ]; # Install
then
if [ "$CWD" != "$HOME" ];
then
cp po-util.sh ~/po-util.sh #Replace ~/po-util.sh with one in current directory.
fi
if [ -f ~/.bash_profile ]; #Create .bash_profile
then
MESSAGE=".bash_profile present." ; green_echo
else
MESSAGE="No .bash_profile present. Installing.." ; red_echo
echo "
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi" >> ~/.bash_profile
fi
if [ -f ~/.bashrc ]; #Add po alias to .bashrc
then
MESSAGE=".bashrc present." ; green_echo
if grep "po-util.sh" ~/.bashrc ;
then
MESSAGE="po alias already in place." ; green_echo
else
MESSAGE="no po alias. Installing..." ; red_echo
echo 'alias po="~/po-util.sh"' >> ~/.bashrc
echo 'alias p="particle"' >> ~/.bashrc #Also add 'p' alias for 'particle'
fi
else
MESSAGE="No .bashrc present. Installing..." ; red_echo
echo 'alias po="~/po-util.sh"' >> ~/.bashrc
fi
# Download po-util-README.md
curl -fsSLo ~/.po-util-README.md https://raw.githubusercontent.com/nrobinson2000/po-util/master/po-util-README.md
# Check to see if we need to override the install directory.
if [ "$2" ] && [ "$2" != $BASE_FIRMWARE ]
then
BASE_FIRMWARE="$2"
echo BASE_FIRMWARE="$BASE_FIRMWARE" > $SETTINGS
fi
[ -d "$BASE_FIRMWARE" ] || mkdir -p "$BASE_FIRMWARE" # If BASE_FIRMWARE does not exist, create it
# clone firmware repository
cd "$BASE_FIRMWARE" || exit
MESSAGE="Installing Particle firmware from Github..." ; blue_echo
git clone https://github.com/spark/firmware.git
if [ "$OS" == "Linux" ]; # Linux installation steps
then
cd "$BASE_FIRMWARE" || exit
# Install dependencies
MESSAGE="Installing ARM toolchain and dependencies locally in $BINDIR/gcc-arm-embedded/..." ; blue_echo
mkdir -p $BINDIR/gcc-arm-embedded && cd "$_" || exit
if [ -d "$GCC_ARM_VER" ]; #
then
echo
MESSAGE="ARM toolchain version $GCC_ARM_VER is already downloaded... Continuing..." ; blue_echo
else
curl -fsSLO https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 #Update to v4.9
tar xjf gcc-arm-none-eabi-*-linux.tar.bz2
fi
MESSAGE="Creating links in /usr/local/bin..." ; blue_echo
sudo ln -s $GCC_ARM_PATH* /usr/local/bin # LINK gcc-arm-none-eabi
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs python-software-properties python g++ make build-essential libusb-1.0-0-dev libarchive-zip-perl screen
# Install dfu-util
MESSAGE="Installing dfu-util (requires sudo)..." ; blue_echo
cd "$BASE_FIRMWARE" || exit
git clone git://git.code.sf.net/p/dfu-util/dfu-util
cd dfu-util || exit
git pull
./autogen.sh
./configure
make
sudo make install
cd ..
# Install particle-cli
MESSAGE="Installing particle-cli..." ; blue_echo
sudo npm install -g node-pre-gyp npm particle-cli
# Install udev rules file
MESSAGE="Installing udev rule (requires sudo) ..." ; blue_echo
curl -fsSLO https://raw.githubusercontent.com/nrobinson2000/po-util/master/60-po-util.rules
sudo mv 60-po-util.rules /etc/udev/rules.d/60-po-util.rules
fi # CLOSE: "$OS" == "Linux"
if [ "$OS" == "Darwin" ]; # Mac installation steps
then
# Install Homebrew
MESSAGE="Installing Brew..." ; blue_echo
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap PX4/homebrew-px4
brew update
# Install ARM toolchain
MESSAGE="Installing ARM toolchain..." ; blue_echo
brew install gcc-arm-none-eabi dfu-util
# Install Node.js
curl -Ss https://nodejs.org/dist/ > node-result.txt
cat node-result.txt | grep "<a href=\"v" > node-new.txt
tail -1 node-new.txt > node-oneline.txt
sed -n 's/.*\"\(.*.\)\".*/\1/p' node-oneline.txt > node-version.txt
NODEVERSION="$(cat node-version.txt)"
NODEVERSION="${NODEVERSION%?}"
INSTALLVERSION="node-$NODEVERSION"
MESSAGE="Installing Node.js version $NODEVERSION..." ; blue_echo
curl -fsSLO "https://nodejs.org/dist/$NODEVERSION/$INSTALLVERSION.pkg"
sudo installer -pkg node-*.pkg -target /
rm -rf node-*.pkg
rm -f node-*.txt
# Install particle-cli
MESSAGE="Installing particle-cli..." ; blue_echo
sudo npm install -g node-pre-gyp npm serialport particle-cli
fi # CLOSE: "$OS" == "Darwin"
MESSAGE="Sucessfully Installed!" ; green_echo
exit
fi
# Create our project files
if [ "$1" == "init" ];
then
if [ -d firmware ];
then
MESSAGE="Directory is already Initialized!" ; green_echo
exit
fi
mkdir firmware/
echo "#include \"application.h\"
void setup() // Put setup code here to run once
{
}
void loop() // Put code here to loop forever
{
}" > firmware/main.cpp
cp *.cpp firmware/
cp *.h firmware/
cp ~/.po-util-README.md README.md
MESSAGE="Copied c++ files into firmware directory. Setup complete." ; green_echo
exit
fi
# Open serial monitor for device
if [ "$1" == "serial" ];
then
if [ "$MODEM" == "" ]; # Don't run screen if device is not connected
then
MESSAGE="No device connected!" red_echo ; exit
else
screen -S particle "$MODEM"
screen -S particle -X quit && exit || MESSAGE="If \"po serial\" is putting device into DFU mode, power off device, removing battery for Electron, and run \"po serial\" several times.
This bug will hopefully be fixed in a later release." && blue_echo
fi
exit
fi
# Put device into DFU mode
if [ "$1" == "dfu-open" ];
then
dfu_open
exit
fi
# Get device out of DFU mode
if [ "$1" == "dfu-close" ];
then
dfu-util -d 2b04:D006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
exit
fi
# Update po-util
if [ "$1" == "update" ];
then
MESSAGE="Updating firmware..." ; blue_echo
cd "$BASE_FIRMWARE"/firmware || exit
git checkout $BRANCH
git pull
MESSAGE="Updating particle-cli..." ; blue_echo
sudo npm update -g particle-cli
MESSAGE="Updating po-util.." ; blue_echo
rm ~/po-util.sh
curl -fsSLo ~/po-util.sh https://raw.githubusercontent.com/nrobinson2000/po-util/master/po-util.sh
chmod +x ~/po-util.sh
rm ~/.po-util-README.md
curl -fsSLo ~/.po-util-README.md https://raw.githubusercontent.com/nrobinson2000/po-util/master/po-util-README.md
exit
fi
# Make sure we are using photon, P1, or electron
if [ "$1" == "photon" ] || [ "$1" == "P1" ] || [ "$1" == "electron" ];
then
echo
MESSAGE="$1 selected." ; blue_echo
else
echo
MESSAGE="Please choose \"photon\", \"P1\" or \"electron\", or choose a proper command." ; red_echo
common_commands
exit
fi
cd "$BASE_FIRMWARE"/firmware || exit
if [ "$1" == "photon" ];
then
switch_branch
DFU_ADDRESS1="2b04:D006"
DFU_ADDRESS2="0x080A0000"
fi
if [ "$1" == "P1" ];
then
switch_branch
DFU_ADDRESS1="2b04:D008"
DFU_ADDRESS2="0x080A0000"
fi
if [ "$1" == "electron" ];
then
switch_branch
DFU_ADDRESS1="2b04:d00a"
DFU_ADDRESS2="0x08080000"
fi
# Flash already compiled binary
if [ "$2" == "dfu" ];
then
BINWARNING="true"
find_objects "$3"
if [ "$FINDBINFAIL" == "true" ];
then
exit
fi
dfu_open
sleep 1
echo
MESSAGE="Flashing $FIRMWAREBIN with dfu-util..." ; blue_echo
dfu-util -d "$DFU_ADDRESS1" -a 0 -i 0 -s "$DFU_ADDRESS2":leave -D "$FIRMWAREBIN" || ( MESSAGE="Device not found." ; red_echo )
exit
fi
#Upgrade our firmware on device
if [ "$2" == "upgrade" ] || [ "$2" == "patch" ] || [ "$2" == "update" ];
then
pause "Connect your device and put into DFU mode. Press [ENTER] to continue..."
cd "$CWD" || exit
sed "2s/.*/START_DFU_FLASHER_SERIAL_SPEED=$DFUBAUDRATE/" "$BASE_FIRMWARE/"firmware/build/module-defaults.mk > temp.particle
rm -f "$BASE_FIRMWARE"/firmware/build/module-defaults.mk
mv temp.particle "$BASE_FIRMWARE"/firmware/build/module-defaults.mk
cd "$BASE_FIRMWARE/firmware/modules/$1/system-part1" || exit
make clean all PLATFORM="$1" "$GCC_MAKE" program-dfu
cd "$BASE_FIRMWARE/firmware/modules/$1/system-part2" || exit
make clean all PLATFORM="$1" $GCC_MAKE program-dfu
cd "$BASE_FIRMWARE/firmware" && git stash || exit
sleep 1
dfu-util -d $DFU_ADDRESS1 -a 0 -i 0 -s $DFU_ADDRESS2:leave -D /dev/null
exit
fi
# Clean firmware directory
if [ "$2" == "clean" ];
then
DIRWARNING="true"
find_objects "$3"
if [ "$FINDDIRFAIL" == "true" ];
then
exit
fi
make clean -s 2>&1 /dev/null
if [ "$FIRMWAREDIR/../bin" != "$HOME/bin" ];
then
rm -rf "$FIRMWAREDIR/../bin"
fi
MESSAGE="Sucessfully cleaned." ; blue_echo
echo
exit
fi
# Flash binary over the air
# Use --multi to flash multiple devices at once. This reads a file named devices.txt
if [ "$2" == "ota" ];
then
DIRWARNING="true"
BINWARNING="true"
find_objects "$4"
if [ "$FINDDIRFAIL" == "true" ] || [ "$FINDBINFAIL" == "true" ];
then
exit
fi
if [ "$3" == "" ];
then
MESSAGE="Please specify which device to flash ota." ; red_echo ; exit
fi
if [ "$3" == "--multi" ] || [ "$3" == "-m" ];
then
DEVICEWARNING="true"
find_objects "$4"
if [ "$FINDDEVICESFAIL" == "true" ];
then
exit
fi
for DEVICE in $DEVICES ; do
echo
MESSAGE="Flashing to device $DEVICE..." ; blue_echo
particle flash "$DEVICE" "$FIRMWAREBIN" || ( MESSAGE="Your device must be online in order to flash firmware OTA." ; red_echo )
done
exit
fi
echo
MESSAGE="Flashing to device $3..." ; blue_echo
particle flash "$3" "$FIRMWAREBIN" || ( MESSAGE="Try using \"particle flash\" if you are having issues." ; red_echo )
exit
fi
if [ "$2" == "build" ];
then
DIRWARNING="true"
find_objects "$3"
if [ "$FINDDIRFAIL" == "true" ];
then
exit
fi
echo
build_firmware "$1"
build_message "$@"
fi
if [ "$2" == "debug-build" ];
then
DIRWARNING="true"
find_objects "$3"
if [ "$FINDDIRFAIL" == "true" ];
then
exit
fi
echo
make all -C "$BASE_FIRMWARE/"firmware APPDIR="$FIRMWAREDIR" TARGET_DIR="$FIRMWAREDIR/../bin" PLATFORM="$1" DEBUG_BUILD="y" $GCC_MAKE || exit
build_message "$@"
fi
if [ "$2" == "flash" ];
then
DIRWARNING="true"
find_objects "$3"
if [ "$FINDDIRFAIL" == "true" ];
then
exit
fi
dfu_open
build_firmware "$1"
dfu-util -d "$DFU_ADDRESS1" -a 0 -i 0 -s "$DFU_ADDRESS2":leave -D "$FIRMWAREDIR/../bin/firmware.bin"
exit
fi
# If an improper command is chosen:
echo
MESSAGE="Please choose a proper command." ; red_echo
common_commands