Skip to content

Commit ec8589e

Browse files
author
Daniel Campora
committed
cc3200: Improve uniflash script and make it a bit more verbose.
1 parent b864e7a commit ec8589e

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

cc3200/tools/uniflash.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ def print_exception(e):
2222
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
2323

2424

25+
def execute(command):
26+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
27+
cmd_log = ""
28+
29+
# Poll process for new output until finished
30+
while True:
31+
nextline = process.stdout.readline()
32+
if nextline == '' and process.poll() != None:
33+
break
34+
sys.stdout.write(nextline)
35+
sys.stdout.flush()
36+
cmd_log += nextline
37+
38+
output = process.communicate()[0]
39+
exitCode = process.returncode
40+
41+
if exitCode == 0:
42+
return cmd_log
43+
else:
44+
raise ProcessException(command, exitCode, output)
45+
2546
def main():
2647
cmd_parser = argparse.ArgumentParser(description='Flash the WiPy and optionally run a small test on it.')
2748
cmd_parser.add_argument('-u', '--uniflash', default=None, help='the path to the uniflash cli executable')
@@ -30,27 +51,31 @@ def main():
3051
cmd_parser.add_argument('-s', '--servicepack', default=None, help='the path to the servicepack file')
3152
args = cmd_parser.parse_args()
3253

33-
result = 1
54+
output = ""
3455
com_port = 'com=' + str(args.port)
3556
servicepack_path = 'spPath=' + args.servicepack
3657

3758
try:
3859
if args.uniflash == None or args.config == None:
3960
raise ValueError('uniflash path and config path are mandatory')
4061
if args.servicepack == None:
41-
subprocess.check_call([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'], stderr=subprocess.STDOUT)
62+
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'])
4263
else:
43-
subprocess.check_call([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'], stderr=subprocess.STDOUT)
44-
result = 0
64+
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'])
4565
except Exception as e:
4666
print_exception(e)
67+
output = ""
4768
finally:
48-
if result:
49-
print ("ERROR: Programming failed!")
69+
if "Finish Executing operation: program" in output:
70+
print("======================================")
71+
print("Board programmed OK")
72+
print("======================================")
73+
sys.exit(0)
5074
else:
51-
print ("Board programmed OK")
52-
sys.exit(result)
53-
75+
print("======================================")
76+
print("ERROR: Programming failed!")
77+
print("======================================")
78+
sys.exit(1)
5479

5580
if __name__ == "__main__":
5681
main()

0 commit comments

Comments
 (0)