Skip to content

Commit

Permalink
device.hardware, cli: unbreak factory --force.
Browse files Browse the repository at this point in the history
Before this commit, the `factory` command would ignore already
factory-programmed devices during enumeration (even if the device was
in recovery mode). This defeated the purpose of the `--force` flag.

After this commit, the `factory` command would discover any devices,
whether factory-programmed or not, such that `--force` works on any
device in any state.

Closes #236.
  • Loading branch information
whitequark committed Nov 21, 2020
1 parent 8728433 commit a0dbdff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
17 changes: 11 additions & 6 deletions software/glasgow/cli.py
Expand Up @@ -797,12 +797,14 @@ def startTest(test):

logger.info("reading device configuration")
header = await device.read_eeprom("fx2", 0, 8 + 4 + GlasgowConfig.size)
if not re.match(rb"^\xff+$", header):
if args.force:
logger.warning("device already factory-programmed, proceeding anyway")
else:
logger.error("device already factory-programmed")
return 1
if re.match(rb"^\xff+$", header):
needs_power_cycle = False
elif args.force:
logger.warning("device already factory-programmed, proceeding anyway")
needs_power_cycle = True
else:
logger.error("device already factory-programmed")
return 1

fx2_config = FX2Config(vendor_id=VID_QIHW, product_id=PID_GLASGOW,
device_id=GlasgowConfig.encode_revision(args.factory_rev),
Expand All @@ -824,6 +826,9 @@ def startTest(test):
logger.critical("factory programming failed")
return 1

if needs_power_cycle:
logger.warning("power-cycle the device for the changes to take effect")

if args.action == "list":
for serial in sorted(GlasgowHardwareDevice.enumerate_serials()):
print(serial)
Expand Down
17 changes: 12 additions & 5 deletions software/glasgow/device/hardware.py
Expand Up @@ -74,14 +74,21 @@ def _enumerate_devices(cls, usb_context, _factory_rev=None):
vendor_id = device.getVendorID()
product_id = device.getProductID()
device_id = device.getbcdDevice()
if _factory_rev is None:
if (vendor_id, product_id) != (VID_QIHW, PID_GLASGOW):
if (vendor_id, product_id) == (VID_CYPRESS, PID_FX2):
if _factory_rev is None:
logger.debug("found bare FX2 device %03d/%03d",
device.getBusNumber(), device.getDeviceAddress())
continue
else:
logger.debug("found bare FX2 device %03d/%03d to be factory flashed",
device.getBusNumber(), device.getDeviceAddress())
vendor_id = VID_QIHW
product_id = PID_GLASGOW
revision = _factory_rev
elif (vendor_id, product_id) == (VID_QIHW, PID_GLASGOW):
revision = GlasgowConfig.decode_revision(device_id & 0xFF)
else:
if (vendor_id, product_id) != (VID_CYPRESS, PID_FX2):
continue
revision = _factory_rev
continue

handle = device.open()
if device_id & 0xFF00 in (0x0000, 0xA000):
Expand Down

0 comments on commit a0dbdff

Please sign in to comment.