Bug 214637 - [patch] sysutils/flashrom: serprog hangs
Summary: [patch] sysutils/flashrom: serprog hangs
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Tobias Kortkamp
URL: https://patchwork.coreboot.org/patch/...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-11-18 20:06 UTC by Michael Zhilin
Modified: 2017-02-20 20:31 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (nukama+maintainer)


Attachments
SVN patch file (1.41 KB, patch)
2016-11-18 20:06 UTC, Michael Zhilin
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Zhilin freebsd_committer 2016-11-18 20:06:17 UTC
Created attachment 177152 [details]
SVN patch file

Hi,

Use case:
 flashrom is used to read SPI flash (MX25L6406) via Arduino Nano V3. 

Command: 
 /usr/local/bin/flashrom -p serprog:dev=/dev/cuaU0:57600 -c MX25L6406E/MX25L6408E -r tcw770.dump

It hangs after 5 seconds on read from tty ("ttyin"):
(gdb) bt
#0  _read () at _read.S:3
#1  0x00000008014ae736 in __thr_read (fd=3, buf=0x801c02bec, nbytes=20) at /builds/FreeBSD-src-head/lib/libthr/thread/thr_syscalls.c:402
#2  0x000000000042cd73 in serialport_read (buf=0x801c02bec "", readcnt=<value optimized out>) at serial.c:422
#3  0x000000000041d239 in sp_docommand (command=<value optimized out>, parmlen=10, params=0x801a27010 "\004", retlen=11264, retparms=0x801c00000) at serprog.c:239
#4  0x000000000041d6b1 in serprog_spi_send_command (flash=<value optimized out>, writecnt=<value optimized out>, readcnt=<value optimized out>, 
    writearr=0x7fffffffe35c "\003", readarr=<value optimized out>) at serprog.c:930
#5  0x000000000040a8a4 in spi_nbyte_read (flash=0x3, address=<value optimized out>, bytes=0xffffffff81918118 <Error reading address 0xffffffff81918118: Bad address>, 
    len=20) at spi25.c:937
#6  0x000000000041d73a in serprog_spi_read (flash=<value optimized out>, buf=0x801c00000 "\v�\002�", start=0, len=<value optimized out>) at serprog.c:948
#7  0x000000000042a1fd in read_flash_to_file (flash=0x7fffffffe460, filename=0x801a27000 "tcw770.dump") at flashrom.c:1383
#8  0x000000000040430a in main (argc=0, argv=0x7fffffffe670) at cli_classic.c:545
(gdb) kill

The problem is that ttydisc_rint ignore same bytes. It happens due to enable IEXTEN local flag of termios. As results Arduino reads 11264 bytes, but flashrom gets 11244 bytes (corrupted) and waits for remaining 20 bytes.

The fix is simple: turn off IEXTEN local flag.

Tested on Arduino Nano V3 + FreeBSD 12-CURRENT. 
Portlint looks fine.
Comment 1 Michael Zhilin freebsd_committer 2016-12-14 14:53:10 UTC
Update: patch has been sent to upstream & accepted (flashrom team is moving from SVN to GIT and doesn't yet published last commits).

Could you please commit it to ports tree?

Thanks!
Comment 2 Tobias Kortkamp freebsd_committer 2017-02-20 19:46:00 UTC
Maintainer timeout
Comment 3 commit-hook freebsd_committer 2017-02-20 20:24:48 UTC
A commit references this bug:

Author: tobik
Date: Mon Feb 20 20:24:12 UTC 2017
New revision: 434487
URL: https://svnweb.freebsd.org/changeset/ports/434487

Log:
  Add patch to turn off the IEXTEN local flag and fix serprog hangs

  PR:	214637
  Submitted by:	Michael Zhiling <mizhka@gmail.com>
  Approved by:	lme (mentor), maintainer timeout (nukama+maintainer@gmail.com, 3 months)
  Differential Revision:	https://reviews.freebsd.org/D9696

Changes:
  head/sysutils/flashrom/Makefile
  head/sysutils/flashrom/files/
  head/sysutils/flashrom/files/patch-serial.c
Comment 4 Tobias Kortkamp freebsd_committer 2017-02-20 20:31:13 UTC
Committed, thanks.