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: 465b25830b93
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: c5544d5281d5
Choose a head ref
  • 7 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 17, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    de5b199 View commit details

Commits on Dec 18, 2016

  1. Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    76ce832 View commit details

Commits on Jan 10, 2017

  1. Adding fbi file support.

    mithro committed Jan 10, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5681fa0 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    60f8adf View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    81f35c1 View commit details
  4. Fix pep8 errors.

    mithro committed Jan 10, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    08f44b2 View commit details
  5. Merge pull request #46 from mithro/flash-lm32-support

    Flash lm32 support
    mithro authored Jan 10, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    c5544d5 View commit details
Showing with 146 additions and 9 deletions.
  1. BIN hdmi2usb/firmware/zero.bin
  2. +51 −2 hdmi2usb/modeswitch/boards.py
  3. +30 −5 hdmi2usb/modeswitch/cli.py
  4. +53 −0 hdmi2usb/modeswitch/files.py
  5. +10 −0 udev/99-mimasv2-blacklist.rules
  6. +2 −2 udev/Makefile
Binary file added hdmi2usb/firmware/zero.bin
Binary file not shown.
53 changes: 51 additions & 2 deletions hdmi2usb/modeswitch/boards.py
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ def flash_fx2(board, filename, verbose=False):
"Only support flashing the Opsis for now (not %s)." % board.type)


def load_fpga(board, filename, verbose=False):
def load_gateware(board, filename, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING
@@ -175,7 +175,7 @@ def load_fpga(board, filename, verbose=False):
subprocess.check_call(cmdline)


def flash_fpga(board, filename, verbose=False):
def flash_gateware(board, filename, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING
@@ -222,6 +222,55 @@ def flash_fpga(board, filename, verbose=False):
subprocess.check_call(cmdline)


def flash_lm32_firmware(board, filename, verbose=False):
assert board.state == "jtag", board
assert not board.dev.inuse()
assert board.type in OPENOCD_MAPPING

if filename is not None:
filepath = firmware_path(filename)
assert os.path.exists(filepath), filepath
assert filename.endswith(".fbi"), "Flashing requires a .fbi file"
fbifile = files.FlashBootImageFile(filepath)
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)


def find_boards(prefer_hardware_serial=True, verbose=False):
all_boards = []
exart_uarts = []
35 changes: 30 additions & 5 deletions hdmi2usb/modeswitch/cli.py
Original file line number Diff line number Diff line change
@@ -116,6 +116,17 @@ def args_parser(board, mode):
'--load-lm32-firmware',
help="""\
Load firmware file onto the lm32 Soft-Core running inside the FPGA.
""")
parser.add_argument(
'--flash-lm32-firmware',
help="""\
Flash the firmware file for the lm32 Soft-Core onto the SPI flash.
""")
parser.add_argument(
'--clear-lm32-firmware',
action='store_true',
help="""\
Clear the firmware file for the lm32 Soft-Core on the SPI flash.
""")

parser.add_argument(
@@ -189,7 +200,10 @@ def main():
if mode == 'mode-switch':
assert len(found_boards) == 1
for board in found_boards:
if (args.load_gateware or args.flash_gateware) and not args.mode:
if not args.mode and (args.load_gateware or
args.flash_gateware or
args.flash_lm32_firmware or
args.clear_lm32_firmware):
args.mode = 'jtag'

# Switch modes
@@ -256,12 +270,13 @@ def main():

# Load gateware onto the FPGA
elif args.load_gateware:
boards.load_fpga(board, args.load_gateware,
verbose=args.verbose)
boards.load_gateware(board, args.load_gateware,
verbose=args.verbose)

# Flash the gateware into the SPI flash on the board.
elif args.flash_gateware:
boards.flash_fpga(board, args.flash_gateware,
verbose=args.verbose)
boards.flash_gateware(board, args.flash_gateware,
verbose=args.verbose)

# Load firmware onto the lm32
elif args.load_lm32_firmware:
@@ -271,6 +286,16 @@ def main():
print("flterm something....")
raise NotImplemented("Not yet finished...")

# Flash the firmware into the SPI flash on the board.
elif args.flash_lm32_firmware:
boards.flash_lm32_firmware(board, args.flash_lm32_firmware,
verbose=args.verbose)

# Clear the firmware into the SPI flash on the board.
elif args.clear_lm32_firmware:
boards.flash_lm32_firmware(board, filename=None,
verbose=args.verbose)

found_boards = find_boards(args)

for board in found_boards:
53 changes: 53 additions & 0 deletions hdmi2usb/modeswitch/files.py
Original file line number Diff line number Diff line change
@@ -6,12 +6,63 @@
"""

import struct
import binascii


def assert_eq(a, b):
assert a == b, "'%s' (%r) != '%s' (%r)" % (a, a, b, b)


class FlashBootImageFile(object):
"""
FlashBootImage (.fbi) file.
Used for firmware loaded from flash into main memory by the MiSoC/LiteX
BIOS.
Generate with something like;
mkmscimg -f firmware.bin -o firmware.fbi
python3 -m litex.soc.tools.mkmscimg -f firmware.bin -o firmware.fbi
Consists of;
* File Length - 32bits
* File CRC - 32bits
* File Data - bytes
"""
header = struct.Struct(
">" # big endian
"I" # flength
"I" # fcrc
)

def __init__(self, filename):
try:
assert filename.endswith('.fbi'), "Filename should end in .fbi"
f = open(filename, 'rb')

# Read the header
data = f.read(self.header.size)
flength, fcrc = self.header.unpack_from(data)

fdata = f.read(flength)
extradata = f.read()
assert len(extradata) == 0, "Extra data found ({} bytes)".format(
len(extradata))

ccrc = binascii.crc32(fdata)

assert_eq(fcrc, ccrc)

self.len = flength
self.crc = ccrc
except AssertionError as e:
raise TypeError(e)

def __str__(self):
return "{}(len={}, crc=0x{:x})".format(
self.__class__.__name__, self.len, self.crc)


class XilinxBitFile(object):
"""
This page describes the format
@@ -126,5 +177,7 @@ def __init__(self, filename):
print(XilinxBinFile(fname))
elif fname.endswith('.bit'):
print(XilinxBitFile(fname))
elif fname.endswith('.fbi'):
print(FlashBootImageFile(fname))
else:
sys.exit(1)
10 changes: 10 additions & 0 deletions udev/99-mimasv2-blacklist.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Make modem manager ignore the mimasv2
#
# It should be enough to set ID_MM_DEVICE_IGNORE:="1" but it seems many
# versions of modem manager have a bug which makes them ignore that value.
#
# Setting ID_MM_CANDIDATE:="0" has the same effect but is an "internal
# implementation detail" of modem manager.
SUBSYSTEM=="*", ATTRS{idVendor}=="2a19", ATTRS{idProduct}=="1002", \
ENV{ID_MM_DEVICE_IGNORE}:="1", \
ENV{ID_MM_CANDIDATE}:="0"
4 changes: 2 additions & 2 deletions udev/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# udev rules
install:
@for RULE in *-hdmi2usb*.rules; do \
@for RULE in *.rules; do \
echo "Installing $$RULE to /etc/udev/rules.d/$$RULE"; \
sudo cp $$RULE /etc/udev/rules.d/$$RULE; \
sudo chmod 644 /etc/udev/rules.d/$$RULE; \
@@ -23,7 +23,7 @@ install-reload:
make reload

check:
@for RULE in *-hdmi2usb*.rules; do \
@for RULE in *.rules; do \
echo -n "Checking installed $$RULE.."; \
[ -e /etc/udev/rules.d/$$RULE ] || exit 1; \
diff -u $$RULE /etc/udev/rules.d/$$RULE || exit 1; \