summaryrefslogtreecommitdiffstatshomepage
path: root/cc3200
diff options
context:
space:
mode:
authorDaniel Campora <daniel@wipy.io>2015-07-05 22:31:50 +0200
committerDaniel Campora <daniel@wipy.io>2015-07-07 16:11:48 +0200
commit76e52b5daf9c1440357723e610ff8d0a68eee416 (patch)
tree161cff4b66d0dde7ac81cd43053f2bac10218744 /cc3200
parentfa655ce196ad82e3b8664dcd0ba78328ecaa9a58 (diff)
downloadmicropython-76e52b5daf9c1440357723e610ff8d0a68eee416.tar.gz
micropython-76e52b5daf9c1440357723e610ff8d0a68eee416.zip
cc3200: Make update-wipy.py more robust.
Diffstat (limited to 'cc3200')
-rw-r--r--cc3200/tools/update-wipy.py49
1 files changed, 33 insertions, 16 deletions
diff --git a/cc3200/tools/update-wipy.py b/cc3200/tools/update-wipy.py
index 06241a9de1..eeb159332d 100644
--- a/cc3200/tools/update-wipy.py
+++ b/cc3200/tools/update-wipy.py
@@ -25,26 +25,43 @@ def print_exception(e):
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
+def ftp_directory_exists(ftpobj, directory_name):
+ filelist = []
+ ftpobj.retrlines('LIST',filelist.append)
+ for f in filelist:
+ if f.split()[-1] == directory_name:
+ return True
+ return False
+
+
def transfer_file(args):
- with FTP(args.ip, timeout=10) as ftp:
+ with FTP(args.ip, timeout=20) as ftp:
print ('FTP connection established')
if '230' in ftp.login(args.user, args.password):
print ('Login successful')
- if '250' in ftp.cwd('/flash/sys'):
- print ("Entered '/flash/sys' directory")
-
- with open(args.file, "rb") as fwfile:
- print ('Firmware image found, initiating transfer...')
-
- if '226' in ftp.storbinary("STOR " + 'mcuimg.bin', fwfile, 512):
- print ('File transfer complete')
- return True
+ if '250' in ftp.cwd('/flash'):
+ if not ftp_directory_exists(ftp, 'sys'):
+ print ('/flash/sys directory does not exist')
+ if not '550' in ftp.mkd('sys'):
+ print ('/flash/sys directory created')
else:
- print ('Error: file transfer failed')
+ print ('Error: cannot create /flash/sys directory')
+ return False
+ if '250' in ftp.cwd('sys'):
+ print ("Entered '/flash/sys' directory")
+ with open(args.file, "rb") as fwfile:
+ print ('Firmware image found, initiating transfer...')
+ if '226' in ftp.storbinary("STOR " + 'mcuimg.bin', fwfile, 512):
+ print ('File transfer complete')
+ return True
+ else:
+ print ('Error: file transfer failed')
+ else:
+ print ('Error: cannot enter /flash/sys directory')
else:
- print ('Error: cannot enter /flash/sys directory')
+ print ('Error: cannot enter /flash directory')
else:
print ('Error: ftp login failed')
@@ -97,12 +114,12 @@ def verify_update(args):
firmware_tag = ''
def find_tag (tag):
- nonlocal success, firmware_tag
if tag in firmware_tag:
- success = True
print("Verification passed")
+ return True
else:
print("Error: verification failed, the git tag doesn't match")
+ return False
try:
# Specify a longer time out value here because the board has just been
@@ -114,14 +131,14 @@ def verify_update(args):
tag_file_path = args.file.rstrip('mcuimg.bin') + 'genhdr/mpversion.h'
if args.tag is not None:
- find_tag(bytes(args.tag, 'ascii'))
+ success = find_tag(bytes(args.tag, 'ascii'))
else:
with open(tag_file_path) as tag_file:
for line in tag_file:
bline = bytes(line, 'ascii')
if b'MICROPY_GIT_HASH' in bline:
bline = bline.lstrip(b'#define MICROPY_GIT_HASH ').replace(b'"', b'').replace(b'\r', b'').replace(b'\n', b'')
- find_tag(bline)
+ success = find_tag(bline)
break
except Exception as e: