blob: f0ce2d23cedea05ade8b9691db3ad4c2bc423831 [file] [log] [blame]
#!/usr/bin/python3
import time
import argparse
import pyftdi
from pyftdi.ftdi import Ftdi
from pyftdi.gpio import GpioController
parser = argparse.ArgumentParser()
parser.add_argument("--rom", help="reboot into rom",
action="store_true", default=False)
parser.add_argument("--fastboot", help="reboot into fastboot",
action="store_true", default=False)
class DebugBoard(object):
"""DebugBoard is used to control excelsior reset."""
GPIO_MASK = 0xc0
RESET_OUTPINS = 0xc0
BOOT_NORMAL_OUTPINS = 0x0
BOOT_ROM_OUTPINS = 0x40
def __init__(self, url ='ftdi://0x0403:0x6011/2'):
"""Create gpio controller and select device."""
self._gpio = GpioController()
self._url = url
def _write(self, value):
"""Set the direction on the GPIOs
Since the GPIO to control the Excelsior or pullup,
simply enabling the GPIO has the result of pulling them low.
Setting the GPIO to input allows them to be pulled up.
"""
self._gpio.set_direction(self.GPIO_MASK, value)
def _reset(self):
"""Set the GPIO to hold the board in reset."""
self._write(self.RESET_OUTPINS)
def _boot_normal(self):
"""Set the gpio to boot the board."""
self._write(self.BOOT_NORMAL_OUTPINS)
def _boot_rom(self):
"""Set the gpio to boot the board to the ROM."""
self._write(self.BOOT_ROM_OUTPINS)
def __enter__(self):
"""Connect to the FTDI interface."""
self._gpio.open_from_url(self._url, self.BOOT_NORMAL_OUTPINS)
return self
def reset(self, boot_rom=False, fastboot=False):
"""Reset the excelsior, and boot normal or to the ROM."""
self._reset()
time.sleep(0.1)
if boot_rom:
print("Booting ROM")
self._boot_rom()
time.sleep(5.0)
elif fastboot:
print("Booting fastboot")
self._boot_rom()
time.sleep(10.0)
else:
print("Booting LK")
self._boot_normal()
time.sleep(0.1)
def __exit__(self, exc_type, value, traceback):
"""On exit close the connection to the FTDI device."""
self._gpio.close()
if __name__ == "__main__":
args = parser.parse_args()
try:
with DebugBoard() as board:
board.reset(boot_rom=args.rom, fastboot=args.fastboot)
except pyftdi.usbtools.UsbToolsError:
print("*" * 70)
print("Unable to connect to debug board, check connection or manually toggle GPIO.")
print("*" * 70)
time.sleep(5)