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: timvideos/HDMI2USB-mode-switch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ee969c4c6dae
Choose a base ref
...
head repository: timvideos/HDMI2USB-mode-switch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a2d4457f053
Choose a head ref
  • 20 commits
  • 3 files changed
  • 1 contributor

Commits on Feb 26, 2017

  1. Copy the full SHA
    0f46ad2 View commit details
  2. Copy the full SHA
    59a8544 View commit details
  3. Copy the full SHA
    4e1dc86 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    1b15440 View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    186a768 View commit details
  6. Fixing unicode.

    mithro committed Feb 26, 2017
    Copy the full SHA
    167f328 View commit details
  7. Adding more verbosity output.

    mithro committed Feb 26, 2017
    Copy the full SHA
    1cee446 View commit details
  8. Copy the full SHA
    8d8037b View commit details
  9. Copy the full SHA
    1468a4b View commit details
  10. Always probe the DNA.

    mithro committed Feb 26, 2017
    Copy the full SHA
    61b7253 View commit details
  11. Fixing PEP8 issues.

    mithro committed Feb 26, 2017
    Copy the full SHA
    076b412 View commit details
  12. Copy the full SHA
    a5771b6 View commit details
  13. Copy the full SHA
    33328fc View commit details
  14. Splitting up main() function.

    mithro committed Feb 26, 2017
    Copy the full SHA
    7d65c33 View commit details
  15. p.returncode not p.retcode.

    mithro committed Feb 26, 2017
    Copy the full SHA
    f23999c View commit details
  16. Try lsusb multiple times.

    mithro committed Feb 26, 2017
    Copy the full SHA
    8cbc5dc View commit details
  17. Copy the full SHA
    d425460 View commit details
  18. Small refactor.

    mithro committed Feb 26, 2017
    Copy the full SHA
    6b81368 View commit details
  19. Fixing PEP8

    mithro committed Feb 26, 2017
    Copy the full SHA
    6442fc9 View commit details

Commits on Mar 22, 2017

  1. Merge pull request #54 from mithro/reset-gateware

    Add --reset-gateware
    mithro authored Mar 22, 2017
    Copy the full SHA
    6a2d445 View commit details
Showing with 247 additions and 178 deletions.
  1. +116 −80 hdmi2usb/modeswitch/boards.py
  2. +123 −97 hdmi2usb/modeswitch/cli.py
  3. +8 −1 hdmi2usb/modeswitch/lsusb.py
196 changes: 116 additions & 80 deletions hdmi2usb/modeswitch/boards.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import sys
import time
import subprocess
import re

from collections import namedtuple

@@ -126,8 +127,10 @@ def load_fx2(board, mode=None, filename=None, verbose=False):
env['PATH'] = env['PATH'] + ':/usr/sbin:/sbin'

try:
output = subprocess.check_output(cmdline, stderr=subprocess.STDOUT,
env=env)
output = subprocess.check_output(
cmdline, stderr=subprocess.STDOUT, env=env)
if verbose > 2:
sys.stderr.write(output.decode('utf-8'))
except subprocess.CalledProcessError as e:
if b"can't modify CPUCS: Protocol error\n" not in e.output:
print(e.output)
@@ -142,57 +145,98 @@ def flash_fx2(board, filename, verbose=False):
"Only support flashing the Opsis for now (not %s)." % board.type)


def load_gateware(board, filename, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING
class OpenOCDError(subprocess.CalledProcessError):
def __init__(self, msg, returncode, cmd, output):
subprocess.CalledProcessError.__init__(
self, returncode, cmd, output)
self.message = """\
OpenOCD run failure: {msg}.
filepath = firmware_path(filename)
assert os.path.exists(filepath), filepath
assert filename.endswith(".bit"), "Loading requires a .bit file"
xfile = files.XilinxBitFile(filepath)
assert xfile.part == BOARD_FPGA[board.type], (
"Bit file must be for {} (not {})".format(
BOARD_FPGA[board.type], xfile.part))
OpenOCD command line resulted in {returncode}
-----
{cmd}
-----
script = ["init"]
if verbose:
script += ["xc6s_print_dna xc6s.tap"]
OpenOCD output:
-----
{output}
-----
""".format(msg=msg, returncode=returncode, cmd=cmd, output=output)

script += ["pld load 0 {}".format(filepath)]
script += ["exit"]
def __str__(self):
return self.message


def _openocd_script(board, script, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING
if verbose > 1:
sys.stderr.write(
"Using OpenOCD script:\n{}\n".format(";\n".join(script)))

cmdline = ["openocd"]
cmdline += ["-f", OPENOCD_MAPPING[board.type]]
cmdline += ["-c", "; ".join(script)]
if verbose > 1:
cmdline += ["--debug={}".format(verbose - 2)]

if verbose == 0:
subprocess.check_output(cmdline, stderr=subprocess.STDOUT)
else:
if verbose > 1:
cmdline += ["--debug={}".format(verbose - 2)]
if verbose:
sys.stderr.write("Running %r\n" % cmdline)
subprocess.check_call(cmdline)

p = subprocess.Popen(
cmdline,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if not verbose:
output, _ = p.communicate()
output = output.decode('utf-8')
else:
output = []
while True:
output.append(p.stdout.readline().decode('utf-8'))
sys.stdout.write(output[-1])
if p.poll() is not None:
break
output = "".join(output)

if p.returncode != 0:
raise OpenOCDError(
"Returned {}".format(p.returncode),
p.returncode,
cmdline,
output)

# Look for common errors in the OpenOCD output
error_strings = [
# DNA Failed to read correctly if this error is seen.
"DNA = [01]+ \\(0x18181818.*\\)",

# JTAG Errors
"Info : TAP xc6s.tap does not have IDCODE",
"Warn : Bypassing JTAG setup events due to errors",
"Error: Trying to use configured scan chain anyway...",
]

def flash_gateware(board, filename, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING
errors_found = set()
for err in error_strings:
found = re.search(err, output)
if not found:
continue
errors_found.add("- " + found.group(0))
if errors_found:
raise OpenOCDError(
"Found following errors in output;\n" +
"\n".join(errors_found), p.returncode, cmdline, output)

filepath = firmware_path(filename)
assert os.path.exists(filepath), filepath
assert filename.endswith(".bin"), "Flashing requires a .bin file"
xfile = files.XilinxBinFile(filepath)

def _openocd_flash(board, filepath, location, verbose=False):
assert board.type in OPENOCD_FLASHPROXY
proxypath = os.path.abspath(OPENOCD_FLASHPROXY[board.type])
assert os.path.exists(proxypath), proxypath

script = ["init"]
if verbose:
script += ["xc6s_print_dna xc6s.tap"]

script += ["xc6s_print_dna xc6s.tap"]
script += ["jtagspi_init 0 {}".format(proxypath)]

if verbose > 1:
@@ -204,22 +248,47 @@ def flash_gateware(board, filename, verbose=False):
# script += ["flash read_bank 0 backup.bit 0 0x01000000"]

script += [
"jtagspi_program {} 0x{:x}".format(filepath, 0),
"jtagspi_program {} 0x{:x}".format(filepath, location),
"exit"
]

cmdline = ["openocd"]
return _openocd_script(board, script, verbose=verbose)

cmdline += ["-f", OPENOCD_MAPPING[board.type]]
cmdline += ["-c", "; ".join(script)]

if verbose == 0:
subprocess.check_output(cmdline, stderr=subprocess.STDOUT)
else:
if verbose > 1:
cmdline += ["--debug={}".format(verbose - 2)]
sys.stderr.write("Running %r\n" % cmdline)
subprocess.check_call(cmdline)
def reset_gateware(board, verbose=False):
script = ["init"]
script += ["xc6s_print_dna xc6s.tap"]
script += ["reset halt"]
script += ["exit"]

return _openocd_script(board, script, verbose=verbose)


def load_gateware(board, filename, verbose=False):
filepath = firmware_path(filename)
assert os.path.exists(filepath), filepath
assert filename.endswith(".bit"), "Loading requires a .bit file"
xfile = files.XilinxBitFile(filepath)
assert xfile.part == BOARD_FPGA[board.type], (
"Bit file must be for {} (not {})".format(
BOARD_FPGA[board.type], xfile.part))

script = ["init"]
script += ["xc6s_print_dna xc6s.tap"]
script += ["pld load 0 {}".format(filepath)]
script += ["reset halt"]
script += ["exit"]

return _openocd_script(board, script, verbose=verbose)


def flash_gateware(board, filename, verbose=False):
filepath = firmware_path(filename)
assert os.path.exists(filepath), filepath
assert filename.endswith(".bin"), "Flashing requires a .bin file"
xfile = files.XilinxBinFile(filepath)

_openocd_flash(board, filepath, 0, verbose=verbose)


def flash_lm32_firmware(board, filename, verbose=False):
@@ -235,40 +304,7 @@ def flash_lm32_firmware(board, filename, verbose=False):
else:
filepath = firmware_path("zero.bin")

assert board.type in OPENOCD_FLASHPROXY
proxypath = os.path.abspath(OPENOCD_FLASHPROXY[board.type])
assert os.path.exists(proxypath), proxypath

script = ["init"]
if verbose:
script += ["xc6s_print_dna xc6s.tap"]

script += ["jtagspi_init 0 {}".format(proxypath)]

if verbose > 1:
script += ["flash banks"]
script += ["flash list"]
if verbose > 2:
script += ["flash info 0"]

# FIXME: This is hard coded...
script += [
"jtagspi_program {} 0x{:x}".format(filepath, 0x200000),
"exit"
]

cmdline = ["openocd"]

cmdline += ["-f", OPENOCD_MAPPING[board.type]]
cmdline += ["-c", "; ".join(script)]

if verbose == 0:
subprocess.check_output(cmdline, stderr=subprocess.STDOUT)
else:
if verbose > 1:
cmdline += ["--debug={}".format(verbose - 2)]
sys.stderr.write("Running %r\n" % cmdline)
subprocess.check_call(cmdline)
_openocd_flash(board, filepath, 0x200000, verbose=verbose)


def find_boards(prefer_hardware_serial=True, verbose=False):
Loading