-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluploadEdison
174 lines (168 loc) · 5.79 KB
/
cluploadEdison
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
#!/bin/sh
#
# Name: cluploadEdison
#
# Version Date Comment
# ------- ---- -------
# 0.0.3 191029 Adapted to work on MacOS and Linux
# 0.0.2 191028 change from sshfs to scp with key-pair
# 0.0.1 170815 Initial version fork from Intel cluploadEdison using sshfs
#
# Created on: 170815
# Author: Jacob
#
# Purpose:
# To either use the serial connection to download the executable to the Intel Edison.
# Or to use a wifiConnection.
# The wificonnection name is determined from the "usb port name"
# The distinction between USB or WiFi is made on the usbport name.
# On MacOS they contain the word usbmodem.
# Based on that either the USB or the WiFi part is executed.
# The WiFi part uses scp using the user download with a rsa key edison_rsa.
#
# The required information is extracted out of the command line send by
# arduinocdt
#
# Usage:
# 1. Prepare the Edison:
# Create the user and group "download" on the Intel Edison
# > sudo groupadd download
# > sudo useradd -G download download
# change the group of the /sketch directory to download
# > sudo chgrp download /sketch
# Change the mode of the /sketch directory to give group read write and execute privilege.
# > sudo chmod 0776 /sketch
# Create the ssh keypair for the download user name the edison_rsa with no password.
# > ssh-keygen
# Move the private key to the Mac. scp from mac
# Add the public key to the authorized_keys of the download user
# > cp edison_rsa.pub to /home/download/.ssh/authorized_keys
# 2. Prepare the Mac Linux
# Make a node file with the hostname of the the edison wifi.
# i.e. for hostname is foo
# MacOS
# > sudo mknode /dev/cu.foo c 3 2
# Linux
# > sudo mknod /dev/ttyACM0.wifi.foo c 3 2
# NOTE1: This have to be repeated after a reboot.
# NOTE2: On MacOS this must start with cu.
# On Linux this must start with ttyACM
# Otherwise it will not be offered in the Serial Port drop down menu
# 3. Place this script in:
# /Users/[YOURUSERNAME]/.arduinocdt/packages/Intel/tools/sketchUploader/[VERSION]/clupload/
# 4. Edit:
# /Users/[YOURUSERNAME]/.arduinocdt/packages/Intel/hardware/i686/[VERSION]/platform.txt
# Replace for:
# MacOS
# tools.izmirdl.cmd.path={runtime.tools.sketchUploader-1.6.2+1.0.path}/clupload/cluploadEdison_osx.sh
# Linux
# tools.izmirdl.cmd.path={runtime.tools.sketchUploader-1.6.2+1.0.path}/clupload/cluploadEdison_linux.sh
# With:
# tools.izmirdl.cmd.path={runtime.tools.sketchUploader-1.6.2+1.0.path}/clupload/cluploadEdison
# 5. (re)start Eclipse
#
####################################################################################
##
## clupload script to invoke lsz
## Copyright (C) 2014 Intel Corporation
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
##
####################################################################################
#
#
#========[ START SCRIPT ]========
#
# Set DEBUG to non zero for additional output
DEBUG=0
ME=`basename "$0"`
echo "$ME: starting download script"
#
# print parameters when in debug mode
if [ $DEBUG -ne 0 ]
then
echo "$ME: Args to shell:" $*
fi
#
# ARG 1: Path to lsz executable.
# ARG 2: Elf File to download
# ARG 3: TTY port to use.
#
# The tty_port provides the clue if we are using USB or WiFi
# if it contains usbmodem
# then its USB
# else it is wifi and contains the name of the host
#
port_id=$3
#
if [[ "$port_id" =~ "usbmodem" ]]
then
echo "Serial Port PORT" $com_port_id "(note: should be /dev/cu.xxxxxx for OSX)"
echo "Using tty Port" $port_id
#
#path may contain \ need to change all to /
path_to_exe=$1
fixed_path=${path_to_exe//\\/\/}
#
echo "$ME: Sending Command String to move to download if not already in download mode"
echo "~sketch downloadEdison" > $port_id
#Give the host time to stop the process and wait for download
sleep 1
#
#Move the existing sketch on target.
echo "$ME: Deleting existing sketch on target"
"$fixed_path/lsz" --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old" < $port_id > $port_id
#"$fixed_path/lsz.exe" --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old" < $port_id > $port 1>&0
#
# Execute the target download command
#
#Download the file.
host_file_name=$2
"$fixed_path/lsz" --escape --binary --overwrite $host_file_name < $port_id > $port_id
#
#mv the downloaded file to /sketch/sketch.elf
target_download_name="${host_file_name##*/}"
echo "$ME: Moving downloaded file to /sketch/sketch.elf on target"
"$fixed_path/lsz" --escape -c "mv $target_download_name /sketch/sketch.elf; chmod +x /sketch/sketch.elf" < $port_id > $port_id
exit 0
else # It is WIFI
# Prepair the file
ELFILE=$2
FILE=${ELFILE%.*}
FILE=${FILE##*/}
# add the execution privilege
chmod +x $ELFILE
#
PORT=$3
HOST="${PORT##*.}"
COMMAND="/usr/bin/scp -pi ~/.ssh/edison_rsa $ELFILE download@$HOST.local:/sketch/$FILE"
if [ $DEBUG -ne 0 ]
then
echo "$ME: Destination file is: $FILE"
echo "$ME: Port is: $PORT"
echo "$ME: Destination host is: $HOST"
echo "$ME: Command is: $COMMAND"
fi
echo "$ME: Trying to send file $ELFILE to $HOST.local"
if `$COMMAND`
then
echo "$ME: file $FILE send"
else
echo "$ME: file $FILE FAILED!!!"
fi
# remove the execution privilege
chmod -x $ELFILE
fi
exit 0