Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in Windows Bootstrap Loader Python Package #249

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e361c73
First commit of faraday-bsl program
kb1lqc Jul 12, 2017
634ed01
Moved createtiscripter.py into faraday/classes/
kb1lqc Jul 12, 2017
a9d56ad
Added main() to bootstrap.py
kb1lqc Jul 12, 2017
25d32f9
Added __init__.py to classes and imported class
kb1lqc Jul 12, 2017
ac95672
Fixed up some PEP8 issues, not all
kb1lqc Jul 12, 2017
200f25c
Full operation of TI scripts working
kb1lqc Jul 13, 2017
116bddc
Removed unecessary .txt file and added ignore
kb1lqc Jul 13, 2017
fc2543f
Added some missed files and updated gitignore
kb1lqc Jul 13, 2017
3630c4c
Straggler .gitignore + importing faradayFTDI
kb1lqc Jul 13, 2017
e4eca5c
Loaded firmware on with faraday-bsl!
kb1lqc Jul 13, 2017
95aa4c3
Added necessary files to setup.cfg
kb1lqc Jul 13, 2017
299161e
Added config sections and config read
kb1lqc Jul 19, 2017
78fe42f
Pull in most filenames from INI config file
kb1lqc Jul 19, 2017
2f79bba
Changed creatscripts variable name
kb1lqc Jul 19, 2017
71bd116
Updated help to indicate needed drivers
kb1lqc Jul 19, 2017
faff453
Basic getMaster() command option
kb1lqc Jul 19, 2017
c4f64df
Updated bsl.sample.ini and using downloaded fw
kb1lqc Jul 19, 2017
a404bb1
Updated COM Port configuration
kb1lqc Jul 19, 2017
273449e
Added exception for firmware load
kb1lqc Jul 19, 2017
3b78554
CLeaned up bootstrap.py
kb1lqc Jul 19, 2017
7022e28
Updated createtiscript.py
kb1lqc Jul 19, 2017
8329c48
Update faradayFTDI.py and createtiscript.py
kb1lqc Jul 19, 2017
5a0a293
Pytest Update for Bootstrap Loader package
kb1lqc Jul 19, 2017
a404998
Fixed error states
kb1lqc Jul 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ __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)
.idea*
.idea/*
Tutorials/Tutorials/2-Advanced_Proxy_Programs/Simple_Text_Messaging/Engineering_Documents/~$Packets.xlsx

# Proxy
proxy/proxy.ini
proxy/*.db

#Virtualenv
faradayenv/

# Developer Tutorials
Tutorials\Python_Developer_Tutorials\foundation\Commanding-Local\command_local.ini
Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding-remote.ini
Tutorials\Python_Developer_Tutorials\foundation\Commanding-Remote-RF\commanding-remote.ini

# Bootstrap Loader
etc/faraday/faradayFirmwareUpgradeScript.txt

#Setuptools
build/
dist/

This file was deleted.

15 changes: 0 additions & 15 deletions Firmware_Bootstrap_Loader/faradaybsl/Program_CRC_Calculations.txt

This file was deleted.

7 changes: 7 additions & 0 deletions etc/faraday/bsl.sample.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[BOOTSTRAP]
FILENAME = master.txt
COM = 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
15 changes: 15 additions & 0 deletions etc/faraday/programCRCCalculations.txt
Original file line number Diff line number Diff line change
@@ -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

194 changes: 194 additions & 0 deletions faraday/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#-------------------------------------------------------------------------------
# Name: /faraday/bootstrap.py
# Purpose: Bootstrap loads firmware onto the Faraday Wireless Node via USB
#
# Author: Bryce Salmi
#
# Created: 7/18/2017
# Licence: GPLv3
#-------------------------------------------------------------------------------

import logging.config
import ConfigParser
import os
import sys
import argparse
import shutil
import subprocess
import urllib2

from classes import createtiscript
from classes import faradayFTDI

# 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 bsl 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. 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 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

: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.port is not None:
config.set('BOOTSTRAP', 'COM', args.port)

with open(bslConfigPath, 'wb') as configfile:
config.write(configfile)


def getMaster():
'''
Downloads latest firmware from master github repo, save to userspace

:return: None, exits program
'''

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
response = urllib2.urlopen(url)
data = response.read()
logger.debug(data)

# Save to file, create folders if not present
firmwarePath = os.path.join(os.path.expanduser('~'), '.faraday', 'firmware')
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
if args.init:
initializeBSLConfig()
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!")
sys.exit(0)


def main():
"""
Main function which starts the Boostrap Loader.

:return: None
"""

logger.info('Starting Faraday Bootstrap Loader application')

# Read in configuration parameters
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,
filename,
port,
outputFilename,
upgradeScript,
logger)
script.createscript()

# 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()

except:
logger.error("FTDI driver failure, make sure FTDI drivers are installed!")


if __name__ == '__main__':
main()
Empty file added faraday/classes/__init__.py
Empty file.
Loading