2015-08-06 18:22:38 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Flash the WiPy (format, update service pack and program).
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
> python uniflash.py -u "C:\ti\uniflash_3.2\uniflashCLI.bat" -c "C:\VirtualBoxShared\GitHub\wipy_uniflash.usf" -p 8 -s "C:\ti\CC31xx_CC32xx_ServicePack_1.0.0.10.0\servicepack_1.0.0.10.0.bin"
|
|
|
|
|
|
|
|
or:
|
|
|
|
|
|
|
|
> python uniflash.py -u "C:\ti\uniflash_3.2\uniflashCLI.bat" -c "C:\VirtualBoxShared\GitHub\launchxl_uniflash.usf" -p 8 -s "C:\ti\CC31xx_CC32xx_ServicePack_1.0.0.10.0\servicepack_1.0.0.10.0.bin"
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
def print_exception(e):
|
2020-02-27 04:36:53 +00:00
|
|
|
print("Exception: {}, on line {}".format(e, sys.exc_info()[-1].tb_lineno))
|
2015-08-06 18:22:38 +01:00
|
|
|
|
|
|
|
|
2015-08-19 13:00:20 +01:00
|
|
|
def execute(command):
|
|
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
cmd_log = ""
|
|
|
|
|
|
|
|
# Poll process for new output until finished
|
|
|
|
while True:
|
|
|
|
nextline = process.stdout.readline()
|
2020-02-27 04:36:53 +00:00
|
|
|
if nextline == "" and process.poll() != None:
|
2015-08-19 13:00:20 +01:00
|
|
|
break
|
|
|
|
sys.stdout.write(nextline)
|
|
|
|
sys.stdout.flush()
|
|
|
|
cmd_log += nextline
|
|
|
|
|
|
|
|
output = process.communicate()[0]
|
|
|
|
exitCode = process.returncode
|
|
|
|
|
|
|
|
if exitCode == 0:
|
|
|
|
return cmd_log
|
|
|
|
else:
|
|
|
|
raise ProcessException(command, exitCode, output)
|
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
|
2015-08-06 18:22:38 +01:00
|
|
|
def main():
|
2020-02-27 04:36:53 +00:00
|
|
|
cmd_parser = argparse.ArgumentParser(
|
|
|
|
description="Flash the WiPy and optionally run a small test on it."
|
|
|
|
)
|
|
|
|
cmd_parser.add_argument(
|
|
|
|
"-u", "--uniflash", default=None, help="the path to the uniflash cli executable"
|
|
|
|
)
|
|
|
|
cmd_parser.add_argument(
|
|
|
|
"-c", "--config", default=None, help="the path to the uniflash config file"
|
|
|
|
)
|
|
|
|
cmd_parser.add_argument("-p", "--port", default=8, help="the com serial port")
|
|
|
|
cmd_parser.add_argument(
|
|
|
|
"-s", "--servicepack", default=None, help="the path to the servicepack file"
|
|
|
|
)
|
2015-08-06 18:22:38 +01:00
|
|
|
args = cmd_parser.parse_args()
|
|
|
|
|
2015-08-19 13:00:20 +01:00
|
|
|
output = ""
|
2020-02-27 04:36:53 +00:00
|
|
|
com_port = "com=" + str(args.port)
|
|
|
|
servicepack_path = "spPath=" + args.servicepack
|
2015-08-06 18:22:38 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
if args.uniflash == None or args.config == None:
|
2020-02-27 04:36:53 +00:00
|
|
|
raise ValueError("uniflash path and config path are mandatory")
|
2015-08-06 18:22:38 +01:00
|
|
|
if args.servicepack == None:
|
2020-02-27 04:36:53 +00:00
|
|
|
output += execute(
|
|
|
|
[
|
|
|
|
args.uniflash,
|
|
|
|
"-config",
|
|
|
|
args.config,
|
|
|
|
"-setOptions",
|
|
|
|
com_port,
|
|
|
|
"-operations",
|
|
|
|
"format",
|
|
|
|
"program",
|
|
|
|
]
|
|
|
|
)
|
2015-08-06 18:22:38 +01:00
|
|
|
else:
|
2020-02-27 04:36:53 +00:00
|
|
|
output += execute(
|
|
|
|
[
|
|
|
|
args.uniflash,
|
|
|
|
"-config",
|
|
|
|
args.config,
|
|
|
|
"-setOptions",
|
|
|
|
com_port,
|
|
|
|
servicepack_path,
|
|
|
|
"-operations",
|
|
|
|
"format",
|
|
|
|
"servicePackUpdate",
|
|
|
|
"program",
|
|
|
|
]
|
|
|
|
)
|
2015-08-06 18:22:38 +01:00
|
|
|
except Exception as e:
|
|
|
|
print_exception(e)
|
2015-08-19 13:00:20 +01:00
|
|
|
output = ""
|
2015-08-06 18:22:38 +01:00
|
|
|
finally:
|
2015-08-19 13:00:20 +01:00
|
|
|
if "Finish Executing operation: program" in output:
|
|
|
|
print("======================================")
|
|
|
|
print("Board programmed OK")
|
|
|
|
print("======================================")
|
|
|
|
sys.exit(0)
|
2015-08-06 18:22:38 +01:00
|
|
|
else:
|
2015-08-19 13:00:20 +01:00
|
|
|
print("======================================")
|
|
|
|
print("ERROR: Programming failed!")
|
|
|
|
print("======================================")
|
|
|
|
sys.exit(1)
|
2015-08-06 18:22:38 +01:00
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
|
2015-08-06 18:22:38 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|