Bug 251533

Summary: devel/urjtag: core dumps with Altera USB Blaster when libftdi1 is used in the async USB mode
Product: Ports & Packages Reporter: Torfinn Ingolfsen <tingox+freebsd>
Component: Individual Port(s)Assignee: Yuri Victorovich <yuri>
Status: New ---    
Severity: Affects Only Me Flags: bugzilla: maintainer-feedback? (yuri)
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   

Description Torfinn Ingolfsen 2020-12-02 15:56:27 UTC
urjtag core dumps when trying to use it with an Altera USB Blaster. Installed from ports on a FreeBSD 11.4-stable machine:
root@kg-core1# uname -a
FreeBSD kg-core1.kg4.no 11.4-STABLE FreeBSD 11.4-STABLE #3 r362432: Sat Jun 20 12:51:06 CEST 2020     root@kg-core1.kg4.no:/zs/usr/obj/usr/src/sys/GENERIC  amd64

root@kg-core1# pkg info urjtag*
urjtag-2019.12_1
root@kg-core1# pkg options urjtag
urjtag - FTDI: on
urjtag - JEDEC: on
urjtag - NLS: on
urjtag - PYTHON: off
urjtag - USB: on

The USB Blaster is correctly identified:
root@kg-core1# usbconfig -d ugen3.3
ugen3.3: <Altera USB-Blaster> at usbus3, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (80mA)
root@kg-core1# ls -l /dev/ugen3.3 /dev/usb/3.3.0
lrw-rw----  1 root  cups     9 Dec  2 16:29 /dev/ugen3.3 -> usb/3.3.0
crw-rw----  1 root  cups  0x61 Dec  2 16:29 /dev/usb/3.3.0

and my user has permissions to access it:
tingo@kg-core1$ groups tingo
tingo wheel operator video dialer cups

tingo@kg-core1$ jtag

UrJTAG 2019.12 #
Copyright (C) 2002, 2003 ETC s.r.o.
Copyright (C) 2007, 2008, 2009 Kolja Waschk and the respective authors

UrJTAG is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for UrJTAG.

warning: UrJTAG may damage your hardware!
Type "quit" to exit, "help" for help.

jtag> cable usbblaster
Connected to libftdi driver.
jtag> detect
Segmentation fault (core dumped)

if I run jtag in gdb ('gdb jtag', then 'run'), I get a bit more info:
(gdb) run
Starting program: /usr/local/bin/jtag 
(no debugging symbols found)...(no debugging symbols found)...
UrJTAG 2019.12 #
Copyright (C) 2002, 2003 ETC s.r.o.
Copyright (C) 2007, 2008, 2009 Kolja Waschk and the respective authors

UrJTAG is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for UrJTAG.

warning: UrJTAG may damage your hardware!
Type "quit" to exit, "help" for help.

jtag> cable usbblaster
Connected to libftdi driver.
jtag> detect

Program received signal SIGSEGV, Segmentation fault.
0x000000080175f7e0 in ftdi_transfer_data_done () from /usr/local/lib/libftdi1.so.2
Current language:  auto; currently minimal

The hardware (including usb cable and device under test) is tested as working on another machine (running Linux).
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2020-12-02 19:53:39 UTC
(In reply to Torfinn Ingolfsen from comment #0)

Hi Torfinn,

Thank you for your report.

Are you able to run under the debugger and post a stack trace here?

The easiest way to do this is:
> sudo pkg delete libftdi1 urjtag && cd /usr/ports/devel/urjtag && WITH_DEBUG=yes make install
> sudo pkg install gdb

Then re-run the same urjtag command that crashes prefixed with /usr/local/bin/gdb and when it would crash type 'bt<Enter>' and post the stack trace here.


Thank you,
Yuri
Comment 2 Torfinn Ingolfsen 2020-12-02 20:04:24 UTC
Here you go, one backtrace:
jtag> cable usbblaster
Connected to libftdi driver.
jtag> detect

Program received signal SIGSEGV, Segmentation fault.
0x0000000801783f31 in ftdi_transfer_data_done (tc=0x241c3f0) at src/ftdi.c:1888
1888	src/ftdi.c: No such file or directory.
(gdb) bt
#0  0x0000000801783f31 in ftdi_transfer_data_done (tc=0x241c3f0) at src/ftdi.c:1888
#1  0x0000000800a75390 in usbconn_ftdi_flush (p=0x8024362d0) at usbconn/libftdi.c:143
#2  0x0000000800a742ba in usbconn_ftdi_read (conn=0x80241fec0, buf=0x0, len=0) at usbconn/libftdi.c:180
#3  0x0000000800a5bdbd in urj_tap_usbconn_read (conn=0x80241fec0, buf=0x0, len=0) at usbconn.c:56
#4  0x0000000800a60380 in urj_tap_cable_cx_xfer (cmd_root=0x8024a1150, out_cmd=0x0, cable=0x80243b060, 
    how_much=URJ_TAP_CABLE_TO_OUTPUT) at cable/cmd_xfer.c:336
#5  0x0000000800a67d24 in usbblaster_flush (cable=0x80243b060, how_much=URJ_TAP_CABLE_TO_OUTPUT)
    at cable/usbblaster.c:431
#6  0x0000000800a5c0d3 in urj_tap_cable_flush (cable=0x80243b060, how_much=URJ_TAP_CABLE_TO_OUTPUT) at cable.c:111
#7  0x0000000800a5d08e in urj_tap_cable_transfer_late (cable=0x80243b060, out=0x8024a1180 "") at cable.c:439
#8  0x0000000800a562a8 in urj_tap_shift_register_output (chain=0x80241b040, in=0x80241ff80, out=0x80241ff60, 
    tap_exit=0) at tap.c:141
#9  0x0000000800a55faf in urj_tap_shift_register (chain=0x80241b040, in=0x80241ff80, out=0x80241ff60, tap_exit=0)
    at tap.c:152
#10 0x0000000800a5b3da in urj_tap_detect_register_size (chain=0x80241b040, maxlen=1024) at discovery.c:81
#11 0x0000000800a59347 in urj_tap_detect_parts (chain=0x80241b040, db_path=0x800b0ad98 "/usr/local/share/urjtag", 
    maxirlen=0) at detect.c:197
#12 0x0000000800a5afc9 in urj_tap_detect (chain=0x80241b040, maxirlen=0) at detect.c:549
#13 0x0000000800ab60cb in cmd_detect_run (chain=0x80241b040, params=0x8024a1170) at cmd_detect.c:52
#14 0x0000000800abefa5 in urj_cmd_run (chain=0x80241b040, params=0x8024a1170) at cmd_cmd.c:276
#15 0x0000000800ac6a3f in urj_parse_line (chain=0x80241b040, line=0x802420178 "detect") at parse.c:165
#16 0x0000000000402929 in jtag_readline_multiple_commands_support (chain=0x80241b040, line=0x802420178 "detect")
    at jtag.c:249
#17 0x00000000004024f5 in jtag_readline_loop (chain=0x80241b040, prompt=0x403159 "jtag> ") at jtag.c:271
#18 0x00000000004021b5 in main (argc=1, argv=0x7fffffffeb10) at jtag.c:573
(gdb)
Comment 3 Yuri Victorovich freebsd_committer freebsd_triage 2020-12-02 20:11:16 UTC
What version of libftdi do you have?
Comment 4 commit-hook freebsd_committer freebsd_triage 2020-12-02 21:06:37 UTC
A commit references this bug:

Author: yuri
Date: Wed Dec  2 21:05:56 UTC 2020
New revision: 556853
URL: https://svnweb.freebsd.org/changeset/ports/556853

Log:
  devel/urjtag: Add the NOASYNC option to possibly work around bugs like bug#251533

  PR:		251533
  Reported by:	Torfinn Ingolfsen <tingox+freebsd@gmail.com>

Changes:
  head/devel/urjtag/Makefile
Comment 5 Yuri Victorovich freebsd_committer freebsd_triage 2020-12-02 21:09:57 UTC
Torfinn,

I added the new option NOASYNC to devel/urjtag.

Could you please update this port, select this option (NOASYNC=ON), rebuild, and see if it still crashes?

This option is not made user-choosable by urjtag, but they test if it is supported in libftdi and enable it internally. The code that crashes for you is conditional on this option.

Thank you,
Yuri
Comment 6 Torfinn Ingolfsen 2020-12-02 21:22:41 UTC
(In reply to Yuri Victorovich from comment #3)

root@kg-core1# pkg info libftdi*
libftdi-0.20_16
libftdi1-1.5_1
Comment 7 Torfinn Ingolfsen 2020-12-02 21:54:02 UTC
(In reply to Yuri Victorovich from comment #5)

with updated port and NOASYNC ON:
root@kg-core1# pkg info urjtag*
urjtag-2019.12_2
root@kg-core1# pkg options urjtag
urjtag - FTDI: on
urjtag - JEDEC: on
urjtag - NLS: on
urjtag - NOASYNC: on
urjtag - PYTHON: off
urjtag - USB: on

tingo@kg-core1$ jtag

UrJTAG 2019.12 #
Copyright (C) 2002, 2003 ETC s.r.o.
Copyright (C) 2007, 2008, 2009 Kolja Waschk and the respective authors

UrJTAG is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for UrJTAG.

warning: UrJTAG may damage your hardware!
Type "quit" to exit, "help" for help.

jtag> cable usbblaster
Connected to libftdi driver.
jtag> bsdl path /home/tingo/doc/Altera/docs/fpga/bsdl/
jtag> detect
IR length: 10
Chain length: 1
Device Id: 00000010000010110001000011011101 (0x020B10DD)
  Filename:     /home/tingo/doc/Altera/docs/fpga/bsdl//EP2C5T144.BSD
jtag> 

urjtag now works. Thank you, very fast response and work.
Comment 8 Yuri Victorovich freebsd_committer freebsd_triage 2020-12-02 21:58:46 UTC
(In reply to Torfinn Ingolfsen from comment #7)

> urjtag now works. Thank you, very fast response and work.

My pleasure!
Comment 9 Yuri Victorovich freebsd_committer freebsd_triage 2020-12-03 02:10:53 UTC
Notified the upstream mailing list libftdi@developer.intra2net.com on Dec 02, 2020.