Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c0820b64dcee
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 661a85c038d1
Choose a head ref
  • 2 commits
  • 10 files changed
  • 1 contributor

Commits on Jul 29, 2019

  1. cli: allow replacing interact stage of every applet with a REPL.

    And remove most repl subcommands (though, keep the customized ones,
    and add some logic to steer people towards them, if they exist).
    whitequark committed Jul 29, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    dariakp Daria Pardue
    Copy the full SHA
    2a31c97 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    dariakp Daria Pardue
    Copy the full SHA
    661a85c View commit details
2 changes: 1 addition & 1 deletion software/glasgow/access/direct/demultiplexer.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
# In other words, there is be a platform-specific limit for USB I/O size, which is not
# discoverable via libusb, and hitting which does not result in a sensible error returned
# from libusb (it returns LIBUSB_ERROR_IO even though USBDEVFS_SUBMITURB ioctl correctly
# returns -ENOMEM, so it is not even possible to be optimistic and back off after hitting it.
# returns -ENOMEM), so it is not even possible to be optimistic and back off after hitting it.
#
# To deal with this, use requests of at most 1024 EP buffer sizes (512 KiB with the FX2) as
# an arbitrary cutoff, and hope for the best.
1 change: 1 addition & 0 deletions software/glasgow/applet/__init__.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ def __init_subclass__(cls, name, **kwargs):
help = "applet help missing"
description = "applet description missing"
required_revision = "A0"
has_custom_repl = False

@classmethod
def add_build_arguments(cls, parser, access):
11 changes: 0 additions & 11 deletions software/glasgow/applet/debug/arc/__init__.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import logging
import argparse

from ....support.pyrepl import *
from ....arch.jtag import *
from ....arch.arc import *
from ....database.arc import *
@@ -140,20 +139,10 @@ async def run(self, device, args):

return ARCDebugInterface(tap_iface, self.logger)

@classmethod
def add_interact_arguments(cls, parser):
p_operation = parser.add_subparsers(dest="operation", metavar="OPERATION")

p_repl = p_operation.add_parser(
"repl", help="drop into Python shell; use `arc_iface` to communicate")

async def interact(self, device, args, arc_iface):
idcode, device = await arc_iface.identify()
if device is None:
raise GlasgowAppletError("cannot operate on unknown device IDCODE=%08x"
% idcode.to_int())
self.logger.info("IDCODE=%08x device=%s rev=%d",
idcode.to_int(), device.name, idcode.version)

if args.operation == "repl":
await AsyncInteractiveConsole(locals={"arc_iface":arc_iface}).interact()
4 changes: 0 additions & 4 deletions software/glasgow/applet/debug/arm/swd.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
from migen import *

from ....gateware.pads import *
from ....support.pyrepl import *
from ... import *


@@ -386,9 +385,6 @@ async def run(self, device, args):
iface = await device.demultiplexer.claim_interface(self, self.mux_interface, args)
return SWDInterface(iface, self.logger)

async def interact(self, device, args, swd_iface):
await AsyncInteractiveConsole(locals={"swd_iface": swd_iface}).interact()

# -------------------------------------------------------------------------------------------------

class DebugARMSWDAppletTestCase(GlasgowAppletTestCase, applet=DebugARMSWDApplet):
5 changes: 3 additions & 2 deletions software/glasgow/applet/debug/mips/__init__.py
Original file line number Diff line number Diff line change
@@ -827,6 +827,7 @@ class DebugMIPSApplet(JTAGProbeApplet, name="debug-mips"):
Other configurations might or might not work. In particular, it certainly does not currently
work on little-endian CPUs. Sorry about that.
"""
has_custom_repl = True

@classmethod
def add_run_arguments(cls, parser, access):
@@ -860,7 +861,7 @@ def add_interact_arguments(cls, parser):
ServerEndpoint.add_argument(p_gdb, "gdb_endpoint", default="tcp::1234")

p_repl = p_operation.add_parser(
"repl", help="drop into Python shell; use `ejtag_iface` to communicate")
"repl", help="drop into Python REPL and detach before exit")

async def interact(self, device, args, ejtag_iface):
if args.operation == "dump-state":
@@ -884,7 +885,7 @@ async def interact(self, device, args, ejtag_iface):
await ejtag_iface.target_detach()

if args.operation == "repl":
await AsyncInteractiveConsole(locals={"ejtag_iface":ejtag_iface}).interact()
await AsyncInteractiveConsole(locals={"iface":ejtag_iface}).interact()

# Same as above.
if ejtag_iface.target_attached():
4 changes: 0 additions & 4 deletions software/glasgow/applet/interface/i2c_master/__init__.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import math
from migen import *

from ....support.pyrepl import *
from ....gateware.pads import *
from ....gateware.i2c import I2CMaster
from ... import *
@@ -332,9 +331,6 @@ async def interact(self, device, args, i2c_iface):
self.logger.info("device %s ID: manufacturer %s, part %s, revision %s",
bin(addr), bin(manufacturer), bin(part_ident), bin(revision))

if args.operation == "repl":
await AsyncInteractiveConsole(locals={"i2c_iface":i2c_iface}).interact()

# -------------------------------------------------------------------------------------------------

class I2CMasterAppletTestCase(GlasgowAppletTestCase, applet=I2CMasterApplet):
11 changes: 7 additions & 4 deletions software/glasgow/applet/interface/jtag_probe/__init__.py
Original file line number Diff line number Diff line change
@@ -658,6 +658,7 @@ class JTAGProbeApplet(GlasgowApplet, name="jtag-probe"):
description = """
Identify, test and debug integrated circuits and board assemblies via IEEE 1149.1 JTAG.
"""
has_custom_repl = True

__pins = ("tck", "tms", "tdi", "tdo", "trst")

@@ -734,11 +735,13 @@ def add_interact_arguments(cls, parser):
"tap_indexes", metavar="INDEX", type=int, nargs="+",
help="enumerate IR values for TAP #INDEX")

# This one is identical to run-repl, and is just for consistency when using the subcommands
# tap-repl and jtag-repl alternately.
p_jtag_repl = p_operation.add_parser(
"jtag-repl", help="drop into Python shell; use `jtag_iface` to communicate")
"jtag-repl", help="drop into Python REPL")

p_tap_repl = p_operation.add_parser(
"tap-repl", help="drop into Python shell; use `tap_iface` to communicate")
"tap-repl", help="select a TAP and drop into Python REPL")
p_tap_repl.add_argument(
"tap_index", metavar="INDEX", type=int, default=0, nargs="?",
help="select TAP #INDEX for communication (default: %(default)s)")
@@ -819,7 +822,7 @@ async def interact(self, device, args, jtag_iface):
self.logger.log(level, " IR=%s DR[%s]", ir_value.to01(), dr_length)

if args.operation == "jtag-repl":
await AsyncInteractiveConsole(locals={"jtag_iface":jtag_iface}).interact()
await AsyncInteractiveConsole(locals={"iface":jtag_iface}).interact()

if args.operation == "tap-repl":
tap_iface = await jtag_iface.select_tap(args.tap_index,
@@ -828,7 +831,7 @@ async def interact(self, device, args, jtag_iface):
self.logger.error("cannot select TAP #%d" % args.tap_index)
return

await AsyncInteractiveConsole(locals={"tap_iface":tap_iface}).interact()
await AsyncInteractiveConsole(locals={"iface":tap_iface}).interact()

# -------------------------------------------------------------------------------------------------

7 changes: 0 additions & 7 deletions software/glasgow/applet/memory/onfi/__init__.py
Original file line number Diff line number Diff line change
@@ -82,7 +82,6 @@
from migen import *
from migen.genlib.cdc import MultiReg

from ....support.pyrepl import *
from ....support.logging import *
from ....database.jedec import *
from ....protocol.onfi import *
@@ -542,9 +541,6 @@ def count(arg):
"count", metavar="COUNT", type=count, nargs="?", default=1,
help="erase blocks containing the next COUNT pages")

p_operation.add_parser(
"repl", help="drop into Python shell; use `onfi_iface` to communicate")

async def interact(self, device, args, onfi_iface):
manufacturer_id, device_id = await onfi_iface.read_jedec_id()
if manufacturer_id in (0x00, 0xff):
@@ -760,9 +756,6 @@ async def interact(self, device, args, onfi_iface):
row += block_size
count -= block_size

if args.operation == "repl":
await AsyncInteractiveConsole(locals={"onfi_iface":onfi_iface}).interact()

# -------------------------------------------------------------------------------------------------

class MemoryONFIAppletTestCase(GlasgowAppletTestCase, applet=MemoryONFIApplet):
7 changes: 0 additions & 7 deletions software/glasgow/applet/program/mec16xx/__init__.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
import struct

from ....support.aobject import *
from ....support.pyrepl import *
from ....arch.arc import *
from ....arch.arc.mec16xx import *
from ...debug.arc import DebugARCApplet
@@ -190,9 +189,6 @@ def add_interact_arguments(cls, parser):
"file", metavar="FILE", type=argparse.FileType("rb"),
help="read EC firmware from FILE")

p_repl = p_operation.add_parser(
"repl", help="drop into Python shell; use `mec_iface` to communicate")

async def interact(self, device, args, mec_iface):
if args.operation == "read":
await mec_iface.enable_flash_access(enabled=True)
@@ -215,6 +211,3 @@ async def interact(self, device, args, mec_iface):

if args.operation == "emergency-erase":
await mec_iface.emergency_flash_erase()

if args.operation == "repl":
await AsyncInteractiveConsole(locals={"mec_iface":mec_iface}).interact()
51 changes: 34 additions & 17 deletions software/glasgow/cli.py
Original file line number Diff line number Diff line change
@@ -134,19 +134,20 @@ def add_applet_arg(parser, mode, required=False):
"tests", metavar="TEST", nargs="*",
help="test cases to run")

if mode in ("build", "run"):
if mode in ("build", "run", "run-repl"):
access_args = DirectArguments(applet_name=applet_name,
default_port="AB",
pin_count=16)
if mode == "run":
if mode in ("run", "run-repl"):
g_applet_build = p_applet.add_argument_group("build arguments")
applet.add_build_arguments(g_applet_build, access_args)
g_applet_run = p_applet.add_argument_group("run arguments")
applet.add_run_arguments(g_applet_run, access_args)
# FIXME: this makes it impossiblt to add subparsers in applets
# g_applet_interact = p_applet.add_argument_group("interact arguments")
# applet.add_interact_arguments(g_applet_interact)
applet.add_interact_arguments(p_applet)
if mode != "run-repl":
# FIXME: this makes it impossible to add subparsers in applets
# g_applet_interact = p_applet.add_argument_group("interact arguments")
# applet.add_interact_arguments(g_applet_interact)
applet.add_interact_arguments(p_applet)
if mode == "build":
applet.add_build_arguments(p_applet, access_args)

@@ -193,18 +194,27 @@ def add_toolchain_args(parser):
"--synthesis-opts", metavar="OPTIONS", type=str, default="",
help="(advanced) pass OPTIONS to FPGA synthesis toolchain")

def add_run_args(parser):
add_toolchain_args(parser)
parser.add_argument(
"--rebuild", default=False, action="store_true",
help="rebuild bitstream even if an identical one is already loaded")
parser.add_argument(
"--trace", metavar="FILENAME", type=argparse.FileType("wt"), default=None,
help="trace applet I/O to FILENAME")

p_run = subparsers.add_parser(
"run", formatter_class=TextHelpFormatter,
help="load an applet bitstream and run applet code")
add_toolchain_args(p_run)
p_run.add_argument(
"--rebuild", default=False, action="store_true",
help="rebuild bitstream even if an identical one is already loaded")
p_run.add_argument(
"--trace", metavar="FILENAME", type=argparse.FileType("wt"), default=None,
help="trace applet I/O to FILENAME")
help="run an applet and interact through its command-line interface")
add_run_args(p_run)
add_applet_arg(p_run, mode="run")

p_run_repl = subparsers.add_parser(
"run-repl", formatter_class=TextHelpFormatter,
help="run an applet and open a REPL to use its low-level interface")
add_run_args(p_run_repl)
add_applet_arg(p_run_repl, mode="run-repl")

p_run_prebuilt = subparsers.add_parser(
"run-prebuilt", formatter_class=TextHelpFormatter,
help="(advanced) load a prebuilt applet bitstream and run applet code")
@@ -436,11 +446,11 @@ async def _main():
print("{}\t{:.2}\t{:.2}"
.format(port, vio, vlimit))

if args.action in ("run", "run-prebuilt"):
if args.action in ("run", "run-repl", "run-prebuilt"):
target, applet = _applet(device.revision, args)
device.demultiplexer = DirectDemultiplexer(device, target.multiplexer.pipe_count)

if args.action == "run":
if args.action in ("run", "run-repl"):
await device.download_target(target, rebuild=args.rebuild,
toolchain_opts=_toolchain_opts(args))
if args.action == "run-prebuilt":
@@ -522,7 +532,14 @@ async def run_applet():
logger.warn("applet %r is PREVIEW QUALITY and may CORRUPT DATA", args.applet)
try:
iface = await applet.run(device, args)
await applet.interact(device, args, iface)
if args.action == "run":
await applet.interact(device, args, iface)
if args.action == "run-repl":
if applet.has_custom_repl:
logger.warn("applet provides customized REPL(s); consider using `run "
"{} ...-repl` subcommands".format(applet.name))
logger.info("dropping to REPL; use 'help(iface)' to see available APIs")
await AsyncInteractiveConsole(locals={"iface":iface}).interact()
except GlasgowAppletError as e:
applet.logger.error(str(e))
finally: