uniflash.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. """
  3. Flash the WiPy (format, update service pack and program).
  4. Example:
  5. > 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"
  6. or:
  7. > 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"
  8. """
  9. import sys
  10. import argparse
  11. import subprocess
  12. def print_exception(e):
  13. print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
  14. def execute(command):
  15. process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  16. cmd_log = ""
  17. # Poll process for new output until finished
  18. while True:
  19. nextline = process.stdout.readline()
  20. if nextline == '' and process.poll() != None:
  21. break
  22. sys.stdout.write(nextline)
  23. sys.stdout.flush()
  24. cmd_log += nextline
  25. output = process.communicate()[0]
  26. exitCode = process.returncode
  27. if exitCode == 0:
  28. return cmd_log
  29. else:
  30. raise ProcessException(command, exitCode, output)
  31. def main():
  32. cmd_parser = argparse.ArgumentParser(description='Flash the WiPy and optionally run a small test on it.')
  33. cmd_parser.add_argument('-u', '--uniflash', default=None, help='the path to the uniflash cli executable')
  34. cmd_parser.add_argument('-c', '--config', default=None, help='the path to the uniflash config file')
  35. cmd_parser.add_argument('-p', '--port', default=8, help='the com serial port')
  36. cmd_parser.add_argument('-s', '--servicepack', default=None, help='the path to the servicepack file')
  37. args = cmd_parser.parse_args()
  38. output = ""
  39. com_port = 'com=' + str(args.port)
  40. servicepack_path = 'spPath=' + args.servicepack
  41. try:
  42. if args.uniflash == None or args.config == None:
  43. raise ValueError('uniflash path and config path are mandatory')
  44. if args.servicepack == None:
  45. output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'])
  46. else:
  47. output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'])
  48. except Exception as e:
  49. print_exception(e)
  50. output = ""
  51. finally:
  52. if "Finish Executing operation: program" in output:
  53. print("======================================")
  54. print("Board programmed OK")
  55. print("======================================")
  56. sys.exit(0)
  57. else:
  58. print("======================================")
  59. print("ERROR: Programming failed!")
  60. print("======================================")
  61. sys.exit(1)
  62. if __name__ == "__main__":
  63. main()