Unable to update bootloader on BX


#1

Hi all, I just got my TinyFPGA BX and I’ve run into a few issues while trying to update the bootloader. I’ve pasted the stack traces and my setup below. Any guidance would be much appreciated. I’ve tried a few different cables and ports on a few different machines, all running a fairly recent version of Arch.

Also: I’ve noticed that the bootloader light stops blinking after a few seconds when connected to my computer, which appears to be contrary to the behavior described in the guide.

Apologies if I’m missing something, and thanks for the help!

Setup:

$ apio install system scons icestorm iverilog
Installing system package:
Already installed. Version 1.1.1
Installing scons package:
Already installed. Version 3.0.1
Installing icestorm package:
Already installed. Version 1.11.1
Installing iverilog package:
Already installed. Version 1.1.1
$ apio drivers --serial-enable
Configure Serial drivers for FPGA
Already enabled
$ sudo usermod -a -G dialout $USER
$ apio --version
apio, version 0.4.0b5

Error #1 (b"" passed to ord)

$ sudo tinyprog --update-bootloader

    TinyProg CLI
    ------------
    Using device id 1d50:6130
    Only one board with active bootloader, using it.

    The following update:

        New Version: 1.0.1
        Notes: Updates USB VID:PID to fix issues with APIO not recognizing the board.

    is available for this board:

        /dev/ttyACM0: TinyFPGA BX 1.0.0
            UUID: d0bb0a28-89bb-47bc-b987-472a0cc72c04
            FPGA: ice40lp8k-cm81

    Would you like to perform the update? [y/N] ^[[A
Please respond with 'yes' or 'no' (or 'y' or 'n').
    Would you like to perform the update? [y/N] y
    Fetching stage one...
    Programming stage one...
    Erasing:   0%|                                                                                                                                                                       | 0.00/135k [00:00<?, ?B/s]
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 19, in to_int
    return ord(value)
TypeError: ord() expected a character, but string of length 0 found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/tinyprog", line 10, in <module>
    sys.exit(main())
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 314, in main
    perform_bootloader_update(port)
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 150, in perform_bootloader_update
    if p.program_bitstream(userimage_addr, bitstream):
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 419, in program_bitstream
    return self.program(addr, bitstream)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 375, in program
    self.erase(addr, len(data), disable_progress=False)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 347, in erase
    self._erase(addr, erase_length)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 301, in _erase
    self.wait_while_busy()
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 290, in wait_while_busy
    while to_int(self.read_sts()) & 1:
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 21, in to_int
    return int(value)
ValueError: invalid literal for int() with base 10: b''

Error #2 (device reports readiness to read but no data)

$ sudo tinyprog --update-bootloader

    TinyProg CLI
    ------------
    Using device id 1d50:6130
    Only one board with active bootloader, using it.
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/serial/serialposix.py", line 501, in read
    'device reports readiness to read but returned no data '
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/tinyprog", line 10, in <module>
    sys.exit(main())
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 306, in main
    check_for_wrong_tinyfpga_bx_vidpid() +
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 89, in check_for_wrong_tinyfpga_bx_vidpid
    p = TinyProg(port)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 227, in __init__
    self.meta = TinyMeta(self)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 141, in __init__
    self.root = self._read_metadata()
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 169, in _read_metadata
    [self._parse_json(self.prog.read_security_register_page(p).replace(b"\x00", b"").replace(b"\xff", b"")) for p in [1, 2, 3]] +
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 169, in <listcomp>
    [self._parse_json(self.prog.read_security_register_page(p).replace(b"\x00", b"").replace(b"\xff", b"")) for p in [1, 2, 3]] +
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 269, in read_security_register_page
    return self.cmd(self.security_page_read_cmd, addr=page << (8 + self.security_page_bit_offset), data=b'\x00', read_len=255)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 244, in cmd
    return self.ser.read(read_len)
  File "/usr/lib/python3.7/site-packages/tinyprog/__init__.py", line 72, in read
    return self.ser.read(length)
  File "/usr/lib/python3.7/site-packages/serial/serialposix.py", line 509, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

Error #3 (missing boardmeta)

$ sudo tinyprog --update-bootloader

TinyProg CLI
------------
Using device id 1d50:6130
Only one board with active bootloader, using it.
Traceback (most recent call last):
  File "/usr/bin/tinyprog", line 10, in <module>
sys.exit(main())
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 306, in main
check_for_wrong_tinyfpga_bx_vidpid() +
  File "/usr/lib/python3.7/site-packages/tinyprog/__main__.py", line 91, in check_for_wrong_tinyfpga_bx_vidpid
if m[u"boardmeta"][u"name"] == u"TinyFPGA BX":
KeyError: 'boardmeta'

#2

Quick update: after some reading I’ve tried the latest git master (a77f828), which appears to get a bit further before crashing with similar errors

Since this one appears to work, somewhat, I’m not super keen on running it again lest I brick my board.

[programmer]$ python -m tinyprog --update-bootloader

    TinyProg CLI
    ------------
    Using device id 1d50:6130
    Only one board with active bootloader, using it.


    The following update:

        New Version: 1.0.1
        Notes: Updates USB VID:PID to fix issues with APIO not recognizing the board.

    is available for this board:

        /dev/ttyACM0: TinyFPGA BX 1.0.0
            UUID: d0bb0a28-89bb-47bc-b987-472a0cc72c04
            FPGA: ice40lp8k-cm81

    Would you like to perform the update? [y/N] y
    Fetching stage one...
    Programming stage one...
    Programming and Verifying:   6%|▍       | 8.19k/135k [00:02<00:33, 3.74kB/s]
Traceback (most recent call last):
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 65, in to_int
    return ord(value)
TypeError: ord() expected a character, but string of length 0 found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__main__.py", line 518, in <module>
    main()
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__main__.py", line 377, in main
    perform_bootloader_update(port)
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__main__.py", line 160, in perform_bootloader_update
    if p.program_bitstream(userimage_addr, bitstream):
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 613, in program_bitstream
    return self.program_sectors(addr, bitstream)
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 521, in program_sectors
    self.erase(current_addr, sector_size, disable_progress=True)
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 455, in erase
    self._erase(addr, erase_length)
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 407, in _erase
    self.wait_while_busy()
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 396, in wait_while_busy
    while to_int(self.read_sts()) & 1:
  File "/TinyFPGA-Bootloader/programmer/tinyprog/__init__.py", line 67, in to_int
    return int(value)
ValueError: invalid literal for int() with base 10: b''

#3

Hi,

I had nearly the same problem you were using. Turns out it was because ModemManager was running on my Ubuntu 18.04 system and interfering with communications on /dev/ttyACM0. To see if this is also your problem, try issuing the command:

$ systemctl stop ModemManger.service

From the command line and then try tinyprog --update-bootloader again.

Also, thanks to Luke for pointing this out to me via email. If it wasn’t for his help, I’d still be stuck on this.

Good luck,

  • Bill

#4

Thank you so much! Disabling ModemManager and upgrading the bootloader using the latest git master worked on the first try. Programming the user and program flash is also much more reliable now.

To anybody else who runs into this issue but still wants ModemManager running on their system: I was able to disable probing of /dev/ttyACM by settings the MM_FILTER_RULE_TTY_ACM_INTERFACE environment variable to 0 in my systemd service file like so:

[Service]
Type=dbus
[snip...]
Environment="MM_FILTER_RULE_TTY_ACM_INTERFACE=0"