From e361c7349a4b05a470c99dfa7cf79e9dab292d2c Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 07:56:02 -0700 Subject: [PATCH 01/24] First commit of faraday-bsl program Added setup.cfg entry points as well as skeleton application code. --- faraday/bootstrap.py | 97 ++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 5 ++- 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 faraday/bootstrap.py diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py new file mode 100644 index 00000000..7d72c467 --- /dev/null +++ b/faraday/bootstrap.py @@ -0,0 +1,97 @@ +#------------------------------------------------------------------------------- +# Name: /faraday/bootstrap.py +# Purpose: Bootstrap loads firmware onto the Faraday Wireless Node via USB +# +# Author: Bryce Salmi +# +# Created: 7/12/2017 +# Licence: GPLv3 +#------------------------------------------------------------------------------- + +import logging.config +import threading +import ConfigParser +import socket +import requests +import os +from time import sleep +import sys +import argparse +import shutil + +# Start logging after importing modules +relpath1 = os.path.join('etc', 'faraday') +relpath2 = os.path.join('..', 'etc', 'faraday') +setuppath = os.path.join(sys.prefix, 'etc', 'faraday') +userpath = os.path.join(os.path.expanduser('~'), '.faraday') +path = '' + +for location in os.curdir, relpath1, relpath2, setuppath, userpath: + try: + logging.config.fileConfig(os.path.join(location, "loggingConfig.ini")) + path = location + break + except ConfigParser.NoSectionError: + pass + +logger = logging.getLogger('BSL') + +#Create APRS configuration file path +bslConfigPath = os.path.join(path, "bsl.ini") +logger.debug('bsl.ini PATH: ' + bslConfigPath) + +bslConfig = ConfigParser.RawConfigParser() +bslConfig.read(bslConfigPath) + +# Command line input +parser = argparse.ArgumentParser(description='BSL will Boostrap load firmware onto Faraday via USB connection') +parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize BSL configuration file') +parser.add_argument('--start', action='store_true', help='Start APRS server') + +# Parse the arguments +args = parser.parse_args() + +def initializeBSLConfig(): + ''' + Initialize BSL configuration file from bsl.sample.ini + + :return: None, exits program + ''' + + logger.info("Initializing BSL") + shutil.copy(os.path.join(path, "bsl.sample.ini"), os.path.join(path, "bsl.ini")) + logger.info("Initialization complete") + sys.exit(0) + + +def configureBSL(args, bslConfigPath): + ''' + Configure BSL configuration file from command line + + :param args: argparse arguments + :param bslConfigPath: Path to bsl.ini file + :return: None + ''' + + config = ConfigParser.RawConfigParser() + config.read(os.path.join(path, "bsl.ini")) + + # if args.callsign is not None: + # config.set('APRSIS', 'CALLSIGN', args.callsign) + + with open(bslConfigPath, 'wb') as configfile: + config.write(configfile) + +# Now act upon the command line arguments +# Initialize and configure bsl +if args.init: + initializeBSLConfig() +configureBSL(args, bslConfigPath) + +# Read in BSL configuration parameters +bslFile = bslConfig.read(bslConfigPath) + +# Check for --start option and exit if not present +if not args.start: + logger.warning("--start option not present, exiting BSL server!") + sys.exit(0) diff --git a/setup.cfg b/setup.cfg index e8f2f137..1abdfaa4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,7 +51,7 @@ data_files = etc/faraday/deviceconfiguration.sample.ini etc/faraday/faraday_config.sample.ini etc/faraday/data.sample.ini - + [entry_points] console_scripts = faraday-proxy = faraday.proxy:main @@ -60,4 +60,5 @@ console_scripts = faraday-simpleui = faraday.simpleui:main faraday-deviceconfiguration = faraday.deviceconfiguration:main faraday-simpleconfig = faraday.simpleconfig:main - faraday-data = faraday.data:main \ No newline at end of file + faraday-data = faraday.data:main + faraday-bsl = faraday.bootstrap:main From 634ed0113e1b9d0a0d9e63cf37da3aa50d8f1b34 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 08:03:45 -0700 Subject: [PATCH 02/24] Moved createtiscripter.py into faraday/classes/ Moved to createtiscript.py and also created new folder classes in the faraday folder. --- .../createtiscripter.py => faraday/classes/createtiscript.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Firmware_Bootstrap_Loader/faradaybsl/createtiscripter.py => faraday/classes/createtiscript.py (100%) diff --git a/Firmware_Bootstrap_Loader/faradaybsl/createtiscripter.py b/faraday/classes/createtiscript.py similarity index 100% rename from Firmware_Bootstrap_Loader/faradaybsl/createtiscripter.py rename to faraday/classes/createtiscript.py From a9d56ad1157f2ac771d16b3c3a28fc1916ce82a5 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 08:05:44 -0700 Subject: [PATCH 03/24] Added main() to bootstrap.py --- faraday/bootstrap.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 7d72c467..ea520264 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -95,3 +95,23 @@ def configureBSL(args, bslConfigPath): if not args.start: logger.warning("--start option not present, exiting BSL server!") sys.exit(0) + +def main(): + """ + Main function which starts the Boostrap Loader. + + :return: None + """ + + logger.info('Starting Faraday Bootstrap Loader application') + + # Initialize local variables + threads = [] + + # t = threading.Thread(target=aprs_worker, args=(aprsConfig, sock)) + # threads.append(t) + # t.start() + + +if __name__ == '__main__': + main() From 25d32f963fa209344315ec30b38dc504510c2ed0 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 08:08:15 -0700 Subject: [PATCH 04/24] Added __init__.py to classes and imported class Imported createtiscript.py as a module from the bootstrap loader application. --- faraday/bootstrap.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index ea520264..ee888534 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -19,6 +19,8 @@ import argparse import shutil +from classes import createtiscript + # Start logging after importing modules relpath1 = os.path.join('etc', 'faraday') relpath2 = os.path.join('..', 'etc', 'faraday') @@ -105,6 +107,10 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') + test = createtiscript.CreateTiBslScript(filename, comport) + + test.createscript() + # Initialize local variables threads = [] From ac956721c691bda7c503743ef7473d4c141ad284 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 08:11:36 -0700 Subject: [PATCH 05/24] Fixed up some PEP8 issues, not all --- faraday/bootstrap.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index ee888534..14ce77f9 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -9,12 +9,12 @@ #------------------------------------------------------------------------------- import logging.config -import threading +#import threading import ConfigParser -import socket -import requests +#import socket +#import requests import os -from time import sleep +#from time import sleep import sys import argparse import shutil @@ -53,6 +53,7 @@ # Parse the arguments args = parser.parse_args() + def initializeBSLConfig(): ''' Initialize BSL configuration file from bsl.sample.ini @@ -84,6 +85,7 @@ def configureBSL(args, bslConfigPath): with open(bslConfigPath, 'wb') as configfile: config.write(configfile) + # Now act upon the command line arguments # Initialize and configure bsl if args.init: @@ -98,6 +100,7 @@ def configureBSL(args, bslConfigPath): logger.warning("--start option not present, exiting BSL server!") sys.exit(0) + def main(): """ Main function which starts the Boostrap Loader. @@ -109,10 +112,10 @@ def main(): test = createtiscript.CreateTiBslScript(filename, comport) - test.createscript() + #test.createscript() # Initialize local variables - threads = [] + #threads = [] # t = threading.Thread(target=aprs_worker, args=(aprsConfig, sock)) # threads.append(t) From 200f25c85539b0b16adc6f3eb5446b9b15b11875 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 22:55:45 -0700 Subject: [PATCH 06/24] Full operation of TI scripts working I can get to the end of creating TI scripts. This required some hard coding of file locations and moving some .txt files into /etc/faraday. --- .../faradaybsl/Program_CRC_Calculations.txt | 15 --------------- .../faraday/faradayFirmwareUpgradeScript.txt | 8 ++++---- etc/faraday/programCRCCalculations.txt | 15 +++++++++++++++ faraday/bootstrap.py | 6 ++++-- faraday/classes/createtiscript.py | 11 +++++++---- 5 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 Firmware_Bootstrap_Loader/faradaybsl/Program_CRC_Calculations.txt rename Firmware_Bootstrap_Loader/faradaybsl/FaradayFirmwareUpgradeScript.txt => etc/faraday/faradayFirmwareUpgradeScript.txt (51%) create mode 100644 etc/faraday/programCRCCalculations.txt diff --git a/Firmware_Bootstrap_Loader/faradaybsl/Program_CRC_Calculations.txt b/Firmware_Bootstrap_Loader/faradaybsl/Program_CRC_Calculations.txt deleted file mode 100644 index 73046ff8..00000000 --- a/Firmware_Bootstrap_Loader/faradaybsl/Program_CRC_Calculations.txt +++ /dev/null @@ -1,15 +0,0 @@ -Memory Address: 0x8000 -Data Length: 0x4999 -CRC: 0x88b2 -CRC_CHECK 0x8000 0x4999 0x88b2 - -Memory Address: 0xc99a -Data Length: 0x60 -CRC: 0x1ca6 -CRC_CHECK 0xc99a 0x60 0x1ca6 - -Memory Address: 0xffda -Data Length: 0x26 -CRC: 0xbc88 -CRC_CHECK 0xffda 0x26 0xbc88 - diff --git a/Firmware_Bootstrap_Loader/faradaybsl/FaradayFirmwareUpgradeScript.txt b/etc/faraday/faradayFirmwareUpgradeScript.txt similarity index 51% rename from Firmware_Bootstrap_Loader/faradaybsl/FaradayFirmwareUpgradeScript.txt rename to etc/faraday/faradayFirmwareUpgradeScript.txt index 10bb1e45..24a0823e 100644 --- a/Firmware_Bootstrap_Loader/faradaybsl/FaradayFirmwareUpgradeScript.txt +++ b/etc/faraday/faradayFirmwareUpgradeScript.txt @@ -1,9 +1,9 @@ -MODE 6xx UART 9600 COM112 PARITY +MODE 6xx UART 9600 COM24 PARITY CHANGE_BAUD_RATE 115200 VERBOSE RX_PASSWORD pass32_wrong.txt RX_PASSWORD pass32_default.txt RX_DATA_BLOCK ../Faraday_D1_Release.txt -CRC_CHECK 0x8000 0x4999 0x88b2 -CRC_CHECK 0xc99a 0x60 0x1ca6 -CRC_CHECK 0xffda 0x26 0xbc88 +CRC_CHECK 0x8000 0x4b51 0xbef +CRC_CHECK 0xcb52 0x60 0x4068 +CRC_CHECK 0xffda 0x26 0x5c7d diff --git a/etc/faraday/programCRCCalculations.txt b/etc/faraday/programCRCCalculations.txt new file mode 100644 index 00000000..1c9ebd22 --- /dev/null +++ b/etc/faraday/programCRCCalculations.txt @@ -0,0 +1,15 @@ +Memory Address: 0x8000 +Data Length: 0x4b51 +CRC: 0xbef +CRC_CHECK 0x8000 0x4b51 0xbef + +Memory Address: 0xcb52 +Data Length: 0x60 +CRC: 0x4068 +CRC_CHECK 0xcb52 0x60 0x4068 + +Memory Address: 0xffda +Data Length: 0x26 +CRC: 0x5c7d +CRC_CHECK 0xffda 0x26 0x5c7d + diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 14ce77f9..3d5de4ed 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -110,9 +110,11 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') - test = createtiscript.CreateTiBslScript(filename, comport) + print os.path.join(path, 'Faraday_D1_Release.txt') - #test.createscript() + test = createtiscript.CreateTiBslScript(path, 'Faraday_D1_Release.txt', 'COM24') + + test.createscript() # Initialize local variables #threads = [] diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 54505baa..3b299f96 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -9,6 +9,7 @@ # Licence: #------------------------------------------------------------------------------- import array +import os #filename = sys.argv[1] # filename = 'RF_Test_Firmware_1-17-17.txt' @@ -25,14 +26,15 @@ class CreateTiBslScript(object): - def __init__(self, filename, comport): + def __init__(self, path, filename, comport): + self.path = path self.filename = filename self.comport = comport self.mem_addr_index = [] self.section_data_index = [] def createscript(self): - f = open(self.filename, 'r') + f = open(os.path.join(self.path,self.filename), 'r') file_program_hex = f.read() self.ParseTiTxtHexFile(file_program_hex) self.CreateOutputFile() @@ -71,7 +73,7 @@ def CalcTiTxtCrc16(self, databytes): crc_script_index = [] def CreateOutputFile(self): - textfile = open("faradaybsl/Program_CRC_Calculations.txt", 'w') + textfile = open(os.path.join(self.path,'programCRCCalculations.txt'), 'w') for i in range(0, len(self.mem_addr_index)): final_addr = self.mem_addr_index[i].encode('hex') final_len = hex(len(self.section_data_index[i])) @@ -90,7 +92,7 @@ def CreateOutputFile(self): def CreateBslScript(self): #global device_com_port #com_string = 'MODE 6xx UART 9600 COM%d PARITY' % device_com_port - textfile = open("faradaybsl/FaradayFirmwareUpgradeScript.txt", 'w') + textfile = open(os.path.join(self.path,'faradayFirmwareUpgradeScript.txt'), 'w') textfile.writelines(("MODE 6xx UART 9600 ", str(self.comport), " PARITY", '\n')) textfile.writelines(("CHANGE_BAUD_RATE 115200", '\n')) textfile.writelines(("VERBOSE", '\n')) @@ -100,6 +102,7 @@ def CreateBslScript(self): textfile.writelines(("RX_DATA_BLOCK ", "../", self.filename, '\n')) for i in range(0, len(self.crc_script_index)): textfile.writelines((str(self.crc_script_index[i]), '\n')) + print 'test' #ParseTiTxtHexFile(file_program_hex) #CreateOutputFile() From 116bddcf4e732a976a97c2ed58f5028be5983ad0 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 23:05:40 -0700 Subject: [PATCH 07/24] Removed unecessary .txt file and added ignore Removed file that is created everytime bootstrap loader is used. Then I added it to the .gitignore file so we won't accidentally add it later. --- .gitignore | 5 ++++- etc/faraday/faradayFirmwareUpgradeScript.txt | 9 --------- 2 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 etc/faraday/faradayFirmwareUpgradeScript.txt diff --git a/.gitignore b/.gitignore index f218698c..d2e9c7e7 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ faradayenv/ # Developer Tutorials Tutorials\Python_Developer_Tutorials\foundation\Commanding-Local\command_local.ini -Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding-remote.ini \ No newline at end of file +Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding-remote.ini + +# Bootstrap Loader +etc/faraday/faradayFirmwareUpgradeScript.txt' diff --git a/etc/faraday/faradayFirmwareUpgradeScript.txt b/etc/faraday/faradayFirmwareUpgradeScript.txt deleted file mode 100644 index 24a0823e..00000000 --- a/etc/faraday/faradayFirmwareUpgradeScript.txt +++ /dev/null @@ -1,9 +0,0 @@ -MODE 6xx UART 9600 COM24 PARITY -CHANGE_BAUD_RATE 115200 -VERBOSE -RX_PASSWORD pass32_wrong.txt -RX_PASSWORD pass32_default.txt -RX_DATA_BLOCK ../Faraday_D1_Release.txt -CRC_CHECK 0x8000 0x4b51 0xbef -CRC_CHECK 0xcb52 0x60 0x4068 -CRC_CHECK 0xffda 0x26 0x5c7d From fc2543f3d2ef28e2a3350554595898f861ba5f86 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 23:11:36 -0700 Subject: [PATCH 08/24] Added some missed files and updated gitignore revamped a decent amount of .gitignore for all applications. Also updated filenames in bootstrap.py --- faraday/classes/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 faraday/classes/__init__.py diff --git a/faraday/classes/__init__.py b/faraday/classes/__init__.py new file mode 100644 index 00000000..e69de29b From 3630c4c42d349dc8a54791aa5b69756e218983a8 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 23:20:07 -0700 Subject: [PATCH 09/24] Straggler .gitignore + importing faradayFTDI importing faradyFTDI class now after moving it into the project. --- .gitignore | 29 +++++++++---------- faraday/bootstrap.py | 13 +++++++-- faraday/classes/createtiscript.py | 1 - .../classes/faradayFTDI.py | 0 4 files changed, 24 insertions(+), 19 deletions(-) rename Firmware_Bootstrap_Loader/faradaybsl/faradayftdi.py => faraday/classes/faradayFTDI.py (100%) diff --git a/.gitignore b/.gitignore index d2e9c7e7..0fbdcd4b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,23 +7,20 @@ __pycache__/ # Sphinx documentation docs/_build/ -# Telemetry Application -Applications/Telemetry/telemetry.ini -Applications/Telemetry/*.db -Applications/Telemetry/*.db-journal - -# APRS Application -Applications/APRS/aprs.ini - -# Device Configuration -Applications/deviceconfiguration/deviceconfiguration.ini -Applications/deviceconfiguration/faraday_config.ini +# Application Configuration files +etc/faraday/telemetry.ini +etc/faraday/aprs.ini +etc/faraday/deviceconfiguration.ini +etc/faraday/faraday_config.ini +etc/faraday/simpleui.ini +etc/faraday/proxy.ini +etc/faraday/bsl.ini +etc/faraday/firmware.txt # Hermes Application Applications/Hermes/hermes.ini # SimpleUI Application -Applications/SimpleUI/simpleui.ini Applications/SimpleUI/node_modules/ #IDE (Pycharm) @@ -31,10 +28,6 @@ Applications/SimpleUI/node_modules/ .idea/* Tutorials/Tutorials/2-Advanced_Proxy_Programs/Simple_Text_Messaging/Engineering_Documents/~$Packets.xlsx -# Proxy -proxy/proxy.ini -proxy/*.db - #Virtualenv faradayenv/ @@ -44,3 +37,7 @@ Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding- # Bootstrap Loader etc/faraday/faradayFirmwareUpgradeScript.txt' + +#Setuptools +build/ +dist/ diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 3d5de4ed..4d67411b 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -20,6 +20,7 @@ import shutil from classes import createtiscript +from classes import faradayFTDI # Start logging after importing modules relpath1 = os.path.join('etc', 'faraday') @@ -110,12 +111,20 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') - print os.path.join(path, 'Faraday_D1_Release.txt') + print os.path.join(path, 'firmware.txt') - test = createtiscript.CreateTiBslScript(path, 'Faraday_D1_Release.txt', 'COM24') + test = createtiscript.CreateTiBslScript(path, 'firmware.txt', 'COM24') test.createscript() + #Enable BSL Mode + device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() + # + device_bsl.EnableBslMode() + # subprocess.call(['faradaybsl/bsl-scripter-windows.exe', 'faradaybsl/FaradayFirmwareUpgradeScript.txt']) + # device_bsl.DisableBslMode() + + # Initialize local variables #threads = [] diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 3b299f96..53f1fc1f 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -102,7 +102,6 @@ def CreateBslScript(self): textfile.writelines(("RX_DATA_BLOCK ", "../", self.filename, '\n')) for i in range(0, len(self.crc_script_index)): textfile.writelines((str(self.crc_script_index[i]), '\n')) - print 'test' #ParseTiTxtHexFile(file_program_hex) #CreateOutputFile() diff --git a/Firmware_Bootstrap_Loader/faradaybsl/faradayftdi.py b/faraday/classes/faradayFTDI.py similarity index 100% rename from Firmware_Bootstrap_Loader/faradaybsl/faradayftdi.py rename to faraday/classes/faradayFTDI.py From e4eca5c306524027981d00ba66c18e65d686496d Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 23:34:26 -0700 Subject: [PATCH 10/24] Loaded firmware on with faraday-bsl! First time completely working through load of firware with new packaged command. Still need to correct loading of files from setup.cfg. Also updated .gitignore to remove a filename error. --- .gitignore | 2 +- .../faraday}/bsl-scripter-windows.exe | Bin .../faradaybsl => etc/faraday}/pass32_default.txt | 0 .../faradaybsl => etc/faraday}/pass32_wrong.txt | 0 faraday/bootstrap.py | 7 ++++--- faraday/classes/createtiscript.py | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) rename {Firmware_Bootstrap_Loader/faradaybsl => etc/faraday}/bsl-scripter-windows.exe (100%) rename {Firmware_Bootstrap_Loader/faradaybsl => etc/faraday}/pass32_default.txt (100%) rename {Firmware_Bootstrap_Loader/faradaybsl => etc/faraday}/pass32_wrong.txt (100%) diff --git a/.gitignore b/.gitignore index 0fbdcd4b..5ab36f45 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ Tutorials\Python_Developer_Tutorials\foundation\Commanding-Local\command_local.i Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding-remote.ini # Bootstrap Loader -etc/faraday/faradayFirmwareUpgradeScript.txt' +etc/faraday/faradayFirmwareUpgradeScript.txt #Setuptools build/ diff --git a/Firmware_Bootstrap_Loader/faradaybsl/bsl-scripter-windows.exe b/etc/faraday/bsl-scripter-windows.exe similarity index 100% rename from Firmware_Bootstrap_Loader/faradaybsl/bsl-scripter-windows.exe rename to etc/faraday/bsl-scripter-windows.exe diff --git a/Firmware_Bootstrap_Loader/faradaybsl/pass32_default.txt b/etc/faraday/pass32_default.txt similarity index 100% rename from Firmware_Bootstrap_Loader/faradaybsl/pass32_default.txt rename to etc/faraday/pass32_default.txt diff --git a/Firmware_Bootstrap_Loader/faradaybsl/pass32_wrong.txt b/etc/faraday/pass32_wrong.txt similarity index 100% rename from Firmware_Bootstrap_Loader/faradaybsl/pass32_wrong.txt rename to etc/faraday/pass32_wrong.txt diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 4d67411b..23fa0a7e 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -18,6 +18,7 @@ import sys import argparse import shutil +import subprocess from classes import createtiscript from classes import faradayFTDI @@ -111,7 +112,7 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') - print os.path.join(path, 'firmware.txt') + #print os.path.join(path, 'firmware.txt') test = createtiscript.CreateTiBslScript(path, 'firmware.txt', 'COM24') @@ -121,8 +122,8 @@ def main(): device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() # device_bsl.EnableBslMode() - # subprocess.call(['faradaybsl/bsl-scripter-windows.exe', 'faradaybsl/FaradayFirmwareUpgradeScript.txt']) - # device_bsl.DisableBslMode() + subprocess.call([os.path.join(path, 'bsl-scripter-windows.exe'), os.path.join(path, 'faradayFirmwareUpgradeScript.txt')]) + device_bsl.DisableBslMode() # Initialize local variables diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 53f1fc1f..dd632b0b 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -99,7 +99,7 @@ def CreateBslScript(self): textfile.writelines(("RX_PASSWORD pass32_wrong.txt", '\n')) #gives the wrong password to mass erase the memory textfile.writelines(("RX_PASSWORD pass32_default.txt", '\n')) print "Script file:", self.filename - textfile.writelines(("RX_DATA_BLOCK ", "../", self.filename, '\n')) + textfile.writelines(("RX_DATA_BLOCK ", self.filename, '\n')) for i in range(0, len(self.crc_script_index)): textfile.writelines((str(self.crc_script_index[i]), '\n')) From 95aa4c34f3643719101a54525f57bf05f7b32b8b Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 12 Jul 2017 23:37:14 -0700 Subject: [PATCH 11/24] Added necessary files to setup.cfg Also added sample INI file. This now completes obtaining most data from the package. Including a prior commit that added an EXE file (oh god...). A must for now. Still need to automate obtaining latest firmware file and starting to use the INI configuration to remove the hard-coding. --- etc/faraday/bsl.sample.ini | 0 setup.cfg | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 etc/faraday/bsl.sample.ini diff --git a/etc/faraday/bsl.sample.ini b/etc/faraday/bsl.sample.ini new file mode 100644 index 00000000..e69de29b diff --git a/setup.cfg b/setup.cfg index 1abdfaa4..02a5ccfa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,6 +51,8 @@ data_files = etc/faraday/deviceconfiguration.sample.ini etc/faraday/faraday_config.sample.ini etc/faraday/data.sample.ini + etc/faraday/programCRCCalculations.txt + etc/faraday/bsl.sample.ini [entry_points] console_scripts = From 299161ef2851e47854a1c05cf08a7cedf2724259 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 21:36:40 -0700 Subject: [PATCH 12/24] Added config sections and config read Boostrap.py now reads in the filename and com port from bsl.ini. --- etc/faraday/bsl.sample.ini | 3 +++ faraday/bootstrap.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/etc/faraday/bsl.sample.ini b/etc/faraday/bsl.sample.ini index e69de29b..86554772 100644 --- a/etc/faraday/bsl.sample.ini +++ b/etc/faraday/bsl.sample.ini @@ -0,0 +1,3 @@ +[BOOTSTRAP] +FILENAME = Faraday_D1_Release.txt +PORT = REPLACEME diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 23fa0a7e..9681fe6a 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -114,7 +114,10 @@ def main(): #print os.path.join(path, 'firmware.txt') - test = createtiscript.CreateTiBslScript(path, 'firmware.txt', 'COM24') + filename = bslConfig.get("BOOTSTRAP", "FILENAME") + port = bslConfig.get("BOOTSTRAP", "PORT") + + test = createtiscript.CreateTiBslScript(path, filename, port) test.createscript() From 78fe42f680570815ae360f6a9f3a30967779fca1 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 21:50:35 -0700 Subject: [PATCH 13/24] Pull in most filenames from INI config file Most of the filenames needed are now pulled in from the configuration INI file. --- faraday/bootstrap.py | 11 +++++++++-- faraday/classes/createtiscript.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 9681fe6a..b6ae31d1 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -115,9 +115,16 @@ def main(): #print os.path.join(path, 'firmware.txt') filename = bslConfig.get("BOOTSTRAP", "FILENAME") + outputFilename = bslConfig.get("BOOTSTRAP", "OUTPUTFILENAME") + upgradeScript = bslConfig.get("BOOTSTRAP", "FIRMWAREUPGRADESCRIPT") + bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") port = bslConfig.get("BOOTSTRAP", "PORT") - test = createtiscript.CreateTiBslScript(path, filename, port) + test = createtiscript.CreateTiBslScript(path, + filename, + port, + outputFilename, + upgradeScript) test.createscript() @@ -125,7 +132,7 @@ def main(): device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() # device_bsl.EnableBslMode() - subprocess.call([os.path.join(path, 'bsl-scripter-windows.exe'), os.path.join(path, 'faradayFirmwareUpgradeScript.txt')]) + subprocess.call([os.path.join(path, bslExecutable), os.path.join(path, upgradeScript)]) device_bsl.DisableBslMode() diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index dd632b0b..2d429d51 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -26,19 +26,21 @@ class CreateTiBslScript(object): - def __init__(self, path, filename, comport): + def __init__(self, path, filename, comport, outputfilename, upgradeScript): self.path = path self.filename = filename self.comport = comport self.mem_addr_index = [] self.section_data_index = [] + self._outputfilename = outputfilename + self._upgradeScript = upgradeScript def createscript(self): f = open(os.path.join(self.path,self.filename), 'r') file_program_hex = f.read() self.ParseTiTxtHexFile(file_program_hex) - self.CreateOutputFile() - self.CreateBslScript() + self.CreateOutputFile(self._outputfilename) + self.CreateBslScript(self._upgradeScript) # ParseTiTxtHexFile(file_program_hex) # CreateOutputFile() @@ -72,8 +74,8 @@ def CalcTiTxtCrc16(self, databytes): crc_script_index = [] - def CreateOutputFile(self): - textfile = open(os.path.join(self.path,'programCRCCalculations.txt'), 'w') + def CreateOutputFile(self, filename): + textfile = open(os.path.join(self.path,filename), 'w') for i in range(0, len(self.mem_addr_index)): final_addr = self.mem_addr_index[i].encode('hex') final_len = hex(len(self.section_data_index[i])) @@ -89,10 +91,10 @@ def CreateOutputFile(self): textfile.writelines(('\n', script_index_crc)) textfile.writelines('\n\n') - def CreateBslScript(self): + def CreateBslScript(self, filename): #global device_com_port #com_string = 'MODE 6xx UART 9600 COM%d PARITY' % device_com_port - textfile = open(os.path.join(self.path,'faradayFirmwareUpgradeScript.txt'), 'w') + textfile = open(os.path.join(self.path,filename), 'w') textfile.writelines(("MODE 6xx UART 9600 ", str(self.comport), " PARITY", '\n')) textfile.writelines(("CHANGE_BAUD_RATE 115200", '\n')) textfile.writelines(("VERBOSE", '\n')) From 2f79bba7f49a2ccc52b0663cbd05319d57f36060 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 21:56:47 -0700 Subject: [PATCH 14/24] Changed creatscripts variable name Didn't want it to be test so I changed it to script. --- faraday/bootstrap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index b6ae31d1..d3e714b4 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -120,13 +120,13 @@ def main(): bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") port = bslConfig.get("BOOTSTRAP", "PORT") - test = createtiscript.CreateTiBslScript(path, + script = createtiscript.CreateTiBslScript(path, filename, port, outputFilename, upgradeScript) - test.createscript() + script.createscript() #Enable BSL Mode device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() From 71bd116f4a7885c3cb04dad08e1456e632c34a55 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 21:58:14 -0700 Subject: [PATCH 15/24] Updated help to indicate needed drivers Indicated required FTDI drivers. --- faraday/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index d3e714b4..b8a5898d 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -48,7 +48,7 @@ bslConfig.read(bslConfigPath) # Command line input -parser = argparse.ArgumentParser(description='BSL will Boostrap load firmware onto Faraday via USB connection') +parser = argparse.ArgumentParser(description='BSL will Boostrap load firmware onto Faraday via USB connection. Requires http://www.ftdichip.com/Drivers/D2XX.htm') parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize BSL configuration file') parser.add_argument('--start', action='store_true', help='Start APRS server') From faff453b1faa4a8fb87953bdd6826dfff8e4428f Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 22:56:39 -0700 Subject: [PATCH 16/24] Basic getMaster() command option The getMaster command option downloads the latest master firmware and places it in /.faraday/firmware/master.txt --- faraday/bootstrap.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index b8a5898d..063024a4 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -19,6 +19,7 @@ import argparse import shutil import subprocess +import urllib2 from classes import createtiscript from classes import faradayFTDI @@ -51,6 +52,7 @@ parser = argparse.ArgumentParser(description='BSL will Boostrap load firmware onto Faraday via USB connection. Requires http://www.ftdichip.com/Drivers/D2XX.htm') parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize BSL configuration file') parser.add_argument('--start', action='store_true', help='Start APRS server') +parser.add_argument('--getmaster', action='store_true', help='Download newest firmware from master firmware repository') # Parse the arguments args = parser.parse_args() @@ -87,6 +89,37 @@ def configureBSL(args, bslConfigPath): with open(bslConfigPath, 'wb') as configfile: config.write(configfile) +def getMaster(): + ''' + Downloads latest firmware from master github repo + + :return: None, exits program + ''' + + url = bslConfig.get("BOOTSTRAP", "MASTERURL") + logger.info("Downloading latest Master firmware...") + + # Download latest firmware from url + response = urllib2.urlopen(url) + data = response.read() + logger.debug(data) + + firmwarePath = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware') + + # Create folders if not present + try: + os.makedirs(firmwarePath) + except: + pass + + # Create master.txt if it doesn't exist, otherwise write over it + firmware = os.path.join(firmwarePath, 'master.txt') + f = open(firmware, 'w+') + f.write(data) + f.close() + + logger.info("Download complete") + # Now act upon the command line arguments # Initialize and configure bsl @@ -97,6 +130,10 @@ def configureBSL(args, bslConfigPath): # Read in BSL configuration parameters bslFile = bslConfig.read(bslConfigPath) +# Check for --getmaster +if args.getmaster: + getMaster() + # Check for --start option and exit if not present if not args.start: logger.warning("--start option not present, exiting BSL server!") From c4f64dfc09625363cbf795fc066e403229c7f88b Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 23:09:37 -0700 Subject: [PATCH 17/24] Updated bsl.sample.ini and using downloaded fw Updated bsl.sample.ini with all fields currently in use. Also started using downloaded firmware located in /.faraday/firmware/master.txt --- etc/faraday/bsl.sample.ini | 6 +++++- faraday/classes/createtiscript.py | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/etc/faraday/bsl.sample.ini b/etc/faraday/bsl.sample.ini index 86554772..f88626fe 100644 --- a/etc/faraday/bsl.sample.ini +++ b/etc/faraday/bsl.sample.ini @@ -1,3 +1,7 @@ [BOOTSTRAP] -FILENAME = Faraday_D1_Release.txt +FILENAME = master.txt PORT = REPLACEME +OUTPUTFILENAME = programCRCCalculations.txt +FIRMWAREUPGRADESCRIPT = faradayFirmwareUpgradeScript.txt +BSLEXECUTABLE = bsl-scripter-windows.exe +MASTERURL = https://raw.githubusercontent.com/FaradayRF/Faraday-Firmware/master/Debug/Faraday_D1_Release.txt diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 2d429d51..a6842c18 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -28,7 +28,7 @@ class CreateTiBslScript(object): def __init__(self, path, filename, comport, outputfilename, upgradeScript): self.path = path - self.filename = filename + self._filename = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware', filename) self.comport = comport self.mem_addr_index = [] self.section_data_index = [] @@ -36,7 +36,7 @@ def __init__(self, path, filename, comport, outputfilename, upgradeScript): self._upgradeScript = upgradeScript def createscript(self): - f = open(os.path.join(self.path,self.filename), 'r') + f = open(os.path.join(self.path,self._filename), 'r') file_program_hex = f.read() self.ParseTiTxtHexFile(file_program_hex) self.CreateOutputFile(self._outputfilename) @@ -100,8 +100,8 @@ def CreateBslScript(self, filename): textfile.writelines(("VERBOSE", '\n')) textfile.writelines(("RX_PASSWORD pass32_wrong.txt", '\n')) #gives the wrong password to mass erase the memory textfile.writelines(("RX_PASSWORD pass32_default.txt", '\n')) - print "Script file:", self.filename - textfile.writelines(("RX_DATA_BLOCK ", self.filename, '\n')) + print "Script file:", self._filename + textfile.writelines(("RX_DATA_BLOCK ", self._filename, '\n')) for i in range(0, len(self.crc_script_index)): textfile.writelines((str(self.crc_script_index[i]), '\n')) From a404bb10006b2005aec50907760136ed92937129 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 23:14:36 -0700 Subject: [PATCH 18/24] Updated COM Port configuration Now using --port to set the UART port in bsl.ini. Also, changed the ini file to match proxy terminology for ports in INI file. --- etc/faraday/bsl.sample.ini | 2 +- faraday/bootstrap.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/etc/faraday/bsl.sample.ini b/etc/faraday/bsl.sample.ini index f88626fe..d46aece4 100644 --- a/etc/faraday/bsl.sample.ini +++ b/etc/faraday/bsl.sample.ini @@ -1,6 +1,6 @@ [BOOTSTRAP] FILENAME = master.txt -PORT = REPLACEME +COM = REPLACEME OUTPUTFILENAME = programCRCCalculations.txt FIRMWAREUPGRADESCRIPT = faradayFirmwareUpgradeScript.txt BSLEXECUTABLE = bsl-scripter-windows.exe diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 063024a4..c4b0a735 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -53,6 +53,7 @@ parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize BSL configuration file') parser.add_argument('--start', action='store_true', help='Start APRS server') parser.add_argument('--getmaster', action='store_true', help='Download newest firmware from master firmware repository') +parser.add_argument('--port', help='Set UART port to bootstrap load firmware') # Parse the arguments args = parser.parse_args() @@ -83,6 +84,9 @@ def configureBSL(args, bslConfigPath): config = ConfigParser.RawConfigParser() config.read(os.path.join(path, "bsl.ini")) + if args.port is not None: + config.set('BOOTSTRAP', 'COM', args.port) + # if args.callsign is not None: # config.set('APRSIS', 'CALLSIGN', args.callsign) @@ -155,7 +159,7 @@ def main(): outputFilename = bslConfig.get("BOOTSTRAP", "OUTPUTFILENAME") upgradeScript = bslConfig.get("BOOTSTRAP", "FIRMWAREUPGRADESCRIPT") bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") - port = bslConfig.get("BOOTSTRAP", "PORT") + port = bslConfig.get("BOOTSTRAP", "COM") script = createtiscript.CreateTiBslScript(path, filename, From 273449e4a77bd8c0da72504fa85f2c5307c9841f Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 23:25:50 -0700 Subject: [PATCH 19/24] Added exception for firmware load Added a try/except for firmware master.txt opening. --- faraday/bootstrap.py | 3 ++- faraday/classes/createtiscript.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index c4b0a735..1581967e 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -165,7 +165,8 @@ def main(): filename, port, outputFilename, - upgradeScript) + upgradeScript, + logger) script.createscript() diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index a6842c18..c591da1d 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -10,6 +10,7 @@ #------------------------------------------------------------------------------- import array import os +import sys #filename = sys.argv[1] # filename = 'RF_Test_Firmware_1-17-17.txt' @@ -26,7 +27,7 @@ class CreateTiBslScript(object): - def __init__(self, path, filename, comport, outputfilename, upgradeScript): + def __init__(self, path, filename, comport, outputfilename, upgradeScript, logger): self.path = path self._filename = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware', filename) self.comport = comport @@ -34,10 +35,19 @@ def __init__(self, path, filename, comport, outputfilename, upgradeScript): self.section_data_index = [] self._outputfilename = outputfilename self._upgradeScript = upgradeScript + self.logger = logger def createscript(self): - f = open(os.path.join(self.path,self._filename), 'r') - file_program_hex = f.read() + try: + f = open(os.path.join(self.path,self._filename), 'r') + file_program_hex = f.read() + + except: + # File likely doesn't exist, warn user and exit + self.logger.error('{0} doesn\'t exist!'.format(self._filename)) + self.logger.error('try --getmaster') + sys.exit(1) + self.ParseTiTxtHexFile(file_program_hex) self.CreateOutputFile(self._outputfilename) self.CreateBslScript(self._upgradeScript) From 3b785547061d40bf670a346b3bb49748f5059207 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 23:32:52 -0700 Subject: [PATCH 20/24] CLeaned up bootstrap.py Cleaned up commented out code, updated comments, and added a try/except statement for the FTDI drivers. --- faraday/bootstrap.py | 45 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index 1581967e..cdd807ba 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -4,17 +4,13 @@ # # Author: Bryce Salmi # -# Created: 7/12/2017 +# Created: 7/18/2017 # Licence: GPLv3 #------------------------------------------------------------------------------- import logging.config -#import threading import ConfigParser -#import socket -#import requests import os -#from time import sleep import sys import argparse import shutil @@ -41,7 +37,7 @@ logger = logging.getLogger('BSL') -#Create APRS configuration file path +#Create bsl configuration file path bslConfigPath = os.path.join(path, "bsl.ini") logger.debug('bsl.ini PATH: ' + bslConfigPath) @@ -51,14 +47,13 @@ # Command line input parser = argparse.ArgumentParser(description='BSL will Boostrap load firmware onto Faraday via USB connection. Requires http://www.ftdichip.com/Drivers/D2XX.htm') parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize BSL configuration file') -parser.add_argument('--start', action='store_true', help='Start APRS server') +parser.add_argument('--start', action='store_true', help='Start Boostrap loader') parser.add_argument('--getmaster', action='store_true', help='Download newest firmware from master firmware repository') parser.add_argument('--port', help='Set UART port to bootstrap load firmware') # Parse the arguments args = parser.parse_args() - def initializeBSLConfig(): ''' Initialize BSL configuration file from bsl.sample.ini @@ -87,15 +82,12 @@ def configureBSL(args, bslConfigPath): if args.port is not None: config.set('BOOTSTRAP', 'COM', args.port) - # if args.callsign is not None: - # config.set('APRSIS', 'CALLSIGN', args.callsign) - with open(bslConfigPath, 'wb') as configfile: config.write(configfile) def getMaster(): ''' - Downloads latest firmware from master github repo + Downloads latest firmware from master github repo, save to userspace :return: None, exits program ''' @@ -108,9 +100,8 @@ def getMaster(): data = response.read() logger.debug(data) + # Save to file, create folders if not present firmwarePath = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware') - - # Create folders if not present try: os.makedirs(firmwarePath) except: @@ -153,37 +144,31 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') - #print os.path.join(path, 'firmware.txt') - + # Read in configuration parameters filename = bslConfig.get("BOOTSTRAP", "FILENAME") outputFilename = bslConfig.get("BOOTSTRAP", "OUTPUTFILENAME") upgradeScript = bslConfig.get("BOOTSTRAP", "FIRMWAREUPGRADESCRIPT") bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") port = bslConfig.get("BOOTSTRAP", "COM") + # Create TI BSL script script = createtiscript.CreateTiBslScript(path, filename, port, outputFilename, upgradeScript, logger) - script.createscript() - #Enable BSL Mode - device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() - # - device_bsl.EnableBslMode() - subprocess.call([os.path.join(path, bslExecutable), os.path.join(path, upgradeScript)]) - device_bsl.DisableBslMode() - - - # Initialize local variables - #threads = [] + # Enable BSL Mode using FTDI drivers + try: + device_bsl = faradayFTDI.FtdiD2xxCbusControlObject() + device_bsl.EnableBslMode() + subprocess.call([os.path.join(path, bslExecutable), os.path.join(path, upgradeScript)]) + device_bsl.DisableBslMode() - # t = threading.Thread(target=aprs_worker, args=(aprsConfig, sock)) - # threads.append(t) - # t.start() + except: + logger.error("FTDI driver failure, make sure FTDI drivers are installed!") if __name__ == '__main__': From 7022e28f1a7a609cbe60d586cd6f344eaf2be43d Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Tue, 18 Jul 2017 23:50:18 -0700 Subject: [PATCH 21/24] Updated createtiscript.py Removed commented out code, commented where appropriate, and generally cleaned up the file. Also added docstrings. --- faraday/classes/createtiscript.py | 80 +++++++++++++++++++------------ 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index c591da1d..0d7684a5 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -1,33 +1,27 @@ #------------------------------------------------------------------------------- -# Name: module1 -# Purpose: +# Name: /faraday/classes/createtiscript.py +# Purpose: Texas Instruments bootloader script creation class # -# Author: Brent +# Author: Brenton Salmi, Bryce Salmi # # Created: 03/08/2016 -# Copyright: (c) Brent 2016 -# Licence: +# Licence: GPLv3 #------------------------------------------------------------------------------- + import array import os import sys -#filename = sys.argv[1] -# filename = 'RF_Test_Firmware_1-17-17.txt' -# device_com_port = 32 -# -# f = open(filename, 'r') -# -# mem_addr_index = [] -# section_data_index = [] -# file_program_hex = f.read() - -#print "Arguement 0:", argument1 - - class CreateTiBslScript(object): + ''' + This class creates a TI Bootstrap Loader script file from a text file of Faraday firmware + ''' def __init__(self, path, filename, comport, outputfilename, upgradeScript, logger): + """ + initialize the class and variables + """ + self.path = path self._filename = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware', filename) self.comport = comport @@ -38,6 +32,12 @@ def __init__(self, path, filename, comport, outputfilename, upgradeScript, logge self.logger = logger def createscript(self): + """ + Create the TI Boostrap loader script + + :return: None + """ + try: f = open(os.path.join(self.path,self._filename), 'r') file_program_hex = f.read() @@ -52,26 +52,37 @@ def createscript(self): self.CreateOutputFile(self._outputfilename) self.CreateBslScript(self._upgradeScript) - # ParseTiTxtHexFile(file_program_hex) - # CreateOutputFile() - # CreateBslScript() def ParseTiTxtHexFile(self, input_file): + """ + Parse the hex text file properly + + :param input_file: File object to parse + :return: None + """ + datasections = input_file.split('@') datasections.pop(0) #remove empty first index - #remove memory addresses and separate data in each section + # Remove memory addresses and separate data in each section for i in range(0, len(datasections)): - #Parse and strip TI-TXT format + # Parse and strip TI-TXT format a = datasections[i].replace('\n', '') a = a.replace(' ', '') mem_addr = str(a[0:4]).decode('hex') section_data = str(a[4:]).replace('q', '') #remove end of file - #Ouput + # Output self.mem_addr_index.append(mem_addr) self.section_data_index.append(section_data.decode('hex')) def CalcTiTxtCrc16(self, databytes): + """ + Check text file CRC16 value + + :param databytes: data to perform CRC on + :return: CRC value + """ + data_array = array.array('B', databytes) chk = 0xffff for item in data_array: @@ -85,6 +96,13 @@ def CalcTiTxtCrc16(self, databytes): crc_script_index = [] def CreateOutputFile(self, filename): + """ + Create output TI bootstrap loader file from firmware text data + + :param filename: Bootstrap loader output data filename + :return: CRC value + """ + textfile = open(os.path.join(self.path,filename), 'w') for i in range(0, len(self.mem_addr_index)): final_addr = self.mem_addr_index[i].encode('hex') @@ -102,19 +120,19 @@ def CreateOutputFile(self, filename): textfile.writelines('\n\n') def CreateBslScript(self, filename): - #global device_com_port - #com_string = 'MODE 6xx UART 9600 COM%d PARITY' % device_com_port + """ + Create output TI bootstrap loader script from firmware text data + + :param filename: Bootstrap loader update script filename + :return: CRC value + """ + textfile = open(os.path.join(self.path,filename), 'w') textfile.writelines(("MODE 6xx UART 9600 ", str(self.comport), " PARITY", '\n')) textfile.writelines(("CHANGE_BAUD_RATE 115200", '\n')) textfile.writelines(("VERBOSE", '\n')) textfile.writelines(("RX_PASSWORD pass32_wrong.txt", '\n')) #gives the wrong password to mass erase the memory textfile.writelines(("RX_PASSWORD pass32_default.txt", '\n')) - print "Script file:", self._filename textfile.writelines(("RX_DATA_BLOCK ", self._filename, '\n')) for i in range(0, len(self.crc_script_index)): textfile.writelines((str(self.crc_script_index[i]), '\n')) - -#ParseTiTxtHexFile(file_program_hex) -#CreateOutputFile() -#CreateBslScript() From 8329c48ca7a41d4d0d02f2cbdcdd7a71af68eea7 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 19 Jul 2017 00:07:13 -0700 Subject: [PATCH 22/24] Update faradayFTDI.py and createtiscript.py Quick docstring fix on createtiscript.py and a big commenting/cleanup of faradayFTDI.py. Ideally there were no functional changes in this commit. --- faraday/classes/createtiscript.py | 4 +- faraday/classes/faradayFTDI.py | 91 +++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 19 deletions(-) diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 0d7684a5..311e0d85 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -13,9 +13,9 @@ import sys class CreateTiBslScript(object): - ''' + """ This class creates a TI Bootstrap Loader script file from a text file of Faraday firmware - ''' + """ def __init__(self, path, filename, comport, outputfilename, upgradeScript, logger): """ diff --git a/faraday/classes/faradayFTDI.py b/faraday/classes/faradayFTDI.py index 17140b9f..ff399978 100644 --- a/faraday/classes/faradayFTDI.py +++ b/faraday/classes/faradayFTDI.py @@ -1,10 +1,26 @@ +#------------------------------------------------------------------------------- +# Name: /faraday/classes/faradayFTDI.py +# Purpose: Control FTDI chip during Bootstrap Loader operation +# +# Author: Brenton Salmi, Bryce Salmi +# +# Created: 07/19/2017 +# Licence: GPLv3 +#------------------------------------------------------------------------------- + import ctypes import ctypes.wintypes import time - class FtdiD2xxCbusControlObject(object): + """ + This class controls the FTDI FT230X during bootloading + """ + def __init__(self): + """ + initialize the class and variables + """ self.BITMASK_IO_OUTPUTS = 0xF0 self.BITMASK_IO_OUTPUTS_RESET = 0x40 self.BITMASK_IO_INPUTS = 0x00 @@ -15,14 +31,22 @@ def __init__(self): self.ftd2xxDll = '' def ResetToggle(self): - #Currently Not working? + """ + Toggle reset IO + + :return: None + """ ##RESET LOW self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS_RESET | self.BITMASK_RST, 0x20) ##Wait x time.sleep(10) def BslModeToggle(self): - #Toggle CBUS to enter BSL mode + """ + Toggle CBUS to enter BSL mode + + :return: None + """ ##RESET LOW self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS, 0x20) ##Wait x @@ -48,13 +72,27 @@ def BslModeToggle(self): time.sleep(self.DELAY_TIME) def NominalModeToggle(self): + """ + Toggle FTDI IC into nominal mode + + :return: None + """ self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_INPUTS, 0x20) def NominalForcedToggle(self): + """ + Force FTDI IC into nominal mode + + :return: None + """ self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20) def DisableBslToggle(self): - #Toggle CBUS to leave BSL mode per Errata (Reset won't work) + """ + Disable FTDI IC Bootstrap loader toggling. Toggle CBUS to leave BSL mode per Errata (Reset won't work) + + :return: None + """ ##RESET HIGH TEST LOW self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20) ##Wait x @@ -83,6 +121,11 @@ def DisableBslToggle(self): self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20) def Connect(self): + """ + Use FTDI dll files to connect to IC + + :return: None + """ self.ftd2xxDll = ctypes.windll.LoadLibrary('ftd2xx.dll') self.handle = ctypes.wintypes.DWORD() assert self.ftd2xxDll.FT_Open(0, ctypes.byref(self.handle)) == 0 @@ -94,6 +137,11 @@ def Connect(self): assert self.ftd2xxDll.FT_Purge(self.handle, 3) == 0 def Disconnect(self): + """ + Use FTDI dll files to disconnect from IC + + :return: None + """ self.ftd2xxDll.FT_Close(self.handle) try: ctypes.windll.kernel32.FreeLibrary(self.ftd2xxDll._handle) @@ -103,6 +151,11 @@ def Disconnect(self): return True def EnableBslMode(self): + """ + Enable FTDI IC bootstrap loader mode + + :return: None + """ self.Connect() self.BslModeToggle() self.NominalModeToggle() @@ -110,6 +163,11 @@ def EnableBslMode(self): return True def DisableBslMode(self): + """ + Disable FTDI IC bootstrap loader mode + + :return: None + """ self.Connect() self.DisableBslToggle() self.NominalModeToggle() @@ -117,23 +175,22 @@ def DisableBslMode(self): return True def PerformStandardReset(self): + """ + Perform reset with FTDI IC + + :return: None + """ self.Connect() self.ResetToggle() self.NominalModeToggle() self.Disconnect() return True - def SetResetHigh(self): - ##RESET HIGH TEST LOW - self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20) - -#Action -#BslMode() -#NominalMode() -#NominalForced() -#DisableBsl() + def SetResetHigh(self): + """ + Set FTDI IC reset pin to high -#writeBuffer = ctypes.create_string_buffer("abcdefghijklmnopqrstuvwxyz") -#bytesWritten = ctypes.wintypes.DWORD() -#assert self.ftd2xxDll.FT_Write(self.handle, writeBuffer, len(writeBuffer)-1, ctypes.byref(bytesWritten)) == 0 -#print bytesWritten.value + :return: None + """ + ##RESET HIGH TEST LOW + self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20) From 5a0a29372b4bdf9416fa3fc96585123fc59cf9a9 Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 19 Jul 2017 00:11:46 -0700 Subject: [PATCH 23/24] Pytest Update for Bootstrap Loader package Passes pytest after these commits. --- faraday/bootstrap.py | 12 +++++++----- faraday/classes/createtiscript.py | 8 ++++---- faraday/classes/faradayFTDI.py | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index cdd807ba..cad9a284 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -54,6 +54,7 @@ # Parse the arguments args = parser.parse_args() + def initializeBSLConfig(): ''' Initialize BSL configuration file from bsl.sample.ini @@ -85,6 +86,7 @@ def configureBSL(args, bslConfigPath): with open(bslConfigPath, 'wb') as configfile: config.write(configfile) + def getMaster(): ''' Downloads latest firmware from master github repo, save to userspace @@ -153,11 +155,11 @@ def main(): # Create TI BSL script script = createtiscript.CreateTiBslScript(path, - filename, - port, - outputFilename, - upgradeScript, - logger) + filename, + port, + outputFilename, + upgradeScript, + logger) script.createscript() # Enable BSL Mode using FTDI drivers diff --git a/faraday/classes/createtiscript.py b/faraday/classes/createtiscript.py index 311e0d85..e0c729d4 100644 --- a/faraday/classes/createtiscript.py +++ b/faraday/classes/createtiscript.py @@ -12,6 +12,7 @@ import os import sys + class CreateTiBslScript(object): """ This class creates a TI Bootstrap Loader script file from a text file of Faraday firmware @@ -39,7 +40,7 @@ def createscript(self): """ try: - f = open(os.path.join(self.path,self._filename), 'r') + f = open(os.path.join(self.path, self._filename), 'r') file_program_hex = f.read() except: @@ -52,7 +53,6 @@ def createscript(self): self.CreateOutputFile(self._outputfilename) self.CreateBslScript(self._upgradeScript) - def ParseTiTxtHexFile(self, input_file): """ Parse the hex text file properly @@ -103,7 +103,7 @@ def CreateOutputFile(self, filename): :return: CRC value """ - textfile = open(os.path.join(self.path,filename), 'w') + textfile = open(os.path.join(self.path, filename), 'w') for i in range(0, len(self.mem_addr_index)): final_addr = self.mem_addr_index[i].encode('hex') final_len = hex(len(self.section_data_index[i])) @@ -127,7 +127,7 @@ def CreateBslScript(self, filename): :return: CRC value """ - textfile = open(os.path.join(self.path,filename), 'w') + textfile = open(os.path.join(self.path, filename), 'w') textfile.writelines(("MODE 6xx UART 9600 ", str(self.comport), " PARITY", '\n')) textfile.writelines(("CHANGE_BAUD_RATE 115200", '\n')) textfile.writelines(("VERBOSE", '\n')) diff --git a/faraday/classes/faradayFTDI.py b/faraday/classes/faradayFTDI.py index ff399978..17d45ab2 100644 --- a/faraday/classes/faradayFTDI.py +++ b/faraday/classes/faradayFTDI.py @@ -12,6 +12,7 @@ import ctypes.wintypes import time + class FtdiD2xxCbusControlObject(object): """ This class controls the FTDI FT230X during bootloading From a404998a826de1a5ba1b5a5980b59a4f6769793e Mon Sep 17 00:00:00 2001 From: kb1lqc Date: Wed, 19 Jul 2017 00:37:37 -0700 Subject: [PATCH 24/24] Fixed error states Try and excepts now work better and the package is cleaned up from a command line and config operational flow. --- faraday/bootstrap.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/faraday/bootstrap.py b/faraday/bootstrap.py index cad9a284..8f4c316a 100644 --- a/faraday/bootstrap.py +++ b/faraday/bootstrap.py @@ -94,7 +94,14 @@ def getMaster(): :return: None, exits program ''' - url = bslConfig.get("BOOTSTRAP", "MASTERURL") + try: + url = bslConfig.get("BOOTSTRAP", "MASTERURL") + + except ConfigParser.Error as e: + logger.error(e) + logger.error("You must initialize faraday-bsl with --init-config!") + sys.exit(1) + logger.info("Downloading latest Master firmware...") # Download latest firmware from url @@ -147,11 +154,21 @@ def main(): logger.info('Starting Faraday Bootstrap Loader application') # Read in configuration parameters - filename = bslConfig.get("BOOTSTRAP", "FILENAME") - outputFilename = bslConfig.get("BOOTSTRAP", "OUTPUTFILENAME") - upgradeScript = bslConfig.get("BOOTSTRAP", "FIRMWAREUPGRADESCRIPT") - bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") - port = bslConfig.get("BOOTSTRAP", "COM") + try: + filename = bslConfig.get("BOOTSTRAP", "FILENAME") + outputFilename = bslConfig.get("BOOTSTRAP", "OUTPUTFILENAME") + upgradeScript = bslConfig.get("BOOTSTRAP", "FIRMWAREUPGRADESCRIPT") + bslExecutable = bslConfig.get("BOOTSTRAP", "BSLEXECUTABLE") + port = bslConfig.get("BOOTSTRAP", "COM") + + except ConfigParser.Error as e: + logger.error(e) + logger.error("You must initialize faraday-bsl with --init-config!") + sys.exit(1) + + if port == "REPLACEME": + logger.error("You must set the UART port with --port PORT!") + sys.exit(1) # Create TI BSL script script = createtiscript.CreateTiBslScript(path,