Mercurial > louis > kiibohd-controller
annotate LoadFile/load.dfu @ 401:99f93dec8fea
Start removing select Linux-isms
bash might not be in /bin. Don't expect it there.
author | Dan McGregor <dan.mcgregor@usask.ca> |
---|---|
date | Mon, 10 Aug 2015 14:49:46 -0600 |
parents | c86eb7d0a693 |
children | 45feb80a2ad1 |
rev | line source |
---|---|
401
99f93dec8fea
Start removing select Linux-isms
Dan McGregor <dan.mcgregor@usask.ca>
parents:
297
diff
changeset
|
1 #!/usr/bin/env bash |
276
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
2 # Convenience script for loading firmware onto a dfu type device |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
3 # By default, initiates dfu-util |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
4 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
5 SERIAL_PORT="" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
6 AUTO_SCREEN_SESSION="" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
7 PROG_NAME=$(basename $0) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
8 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
9 # Parse all the command line arguments |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
10 while (( "$#" >= "1" )); do |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
11 # Scan each argument |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
12 key="$1" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
13 case $key in |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
14 -a|--autoscreen) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
15 AUTO_SCREEN_SESSION="$2" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
16 shift |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
17 ;; |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
18 -f|--fastload) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
19 SERIAL_PORT="$2" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
20 shift |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
21 ;; |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
22 -h|--help) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
23 echo "Usage: $PROG_NAME [options...]" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
24 echo "" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
25 echo "Loads the most recent built firmware (@TARGET_BIN@) to the device." |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
26 echo " (load.dfu)" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
27 echo "" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
28 echo "Arguments:" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
29 echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading." |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
30 echo " e.g. /dev/ttyACM0" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
31 echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal." |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
32 echo " e.g. /dev/ttyACM0" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
33 echo " NOTE: May not work due to non-functional terminal, or disable remote flashing" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
34 echo " -h, --help This message." |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
35 exit 1 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
36 ;; |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
37 *) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
38 echo "INVALID ARG: '$1'" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
39 exit 2 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
40 ;; |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
41 esac |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
42 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
43 # Shift to the next argument |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
44 shift |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
45 done |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
46 |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
47 # If a SERIAL_PORT was specified set the uC into reflash mode |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
48 # XXX May not be successful if uC is not in a good state (or does not allow remote flashing) |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
49 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
50 echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing" |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
51 printf "reload\r" > $SERIAL_PORT |
297
c86eb7d0a693
Fixing releasing Function key and holding layered key
Jacob Alexander <haata@kiibohd.com>
parents:
281
diff
changeset
|
52 sleep 2 |
276
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
53 fi |
207
8b11031e38a7
Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 |
8b11031e38a7
Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 # Load via dfu-util |
8b11031e38a7
Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 # Used for McHCK based uCs |
281
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
57 if type dfu-util &>/dev/null; then |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
58 dfu-util -D @TARGET_BIN@ |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
59 EXIT_STATUS=$? |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
60 else |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
61 echo "dfu-util is required to reprogram the device" |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
62 exit 3 |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
63 fi |
207
8b11031e38a7
Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 |
276
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
65 # Load Screen Session if specified |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
66 if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then |
281
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
67 if type screen &>/dev/null; then |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
68 sleep 0.1 |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
69 screen $AUTO_SCREEN_SESSION |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
70 else |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
71 echo "screen is not installed" |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
72 exit 3 |
71882cd1c362
Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents:
276
diff
changeset
|
73 fi |
276
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
74 fi |
207
8b11031e38a7
Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 |
276
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
76 exit $EXIT_STATUS |
2a3468f5d8be
Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents:
207
diff
changeset
|
77 |