serprog hangs under FreeBSD

Submitted by Michael Zhilin on Dec. 2, 2016, 3:41 p.m.

Details

Message ID CAF19XBJdoObDe9=pqM3dPUkxCjK21yc1bYV4GYTkmsh3WBAamQ@mail.gmail.com
State New
Headers show

Commit Message

Michael Zhilin Dec. 2, 2016, 3:41 p.m.
Hi,

This is attached patch to avoid hang of serprog under FreeBSD. Patch is
against trunk (r1955, 10 context lines).

My use case is flashrom+serprog to read SPI flash (MX25L6406) via Arduino
Nano V3. Actual command is:
 /usr/local/bin/flashrom -p serprog:dev=/dev/cuaU0:57600 -c
MX25L6406E/MX25L6408E -r tcw770.dump

Using flashrom 0.9.9 it hangs after 5 seconds on read from tty ("ttyin").
The problem is that kernel method "ttydisc_rint" ignore same bytes. It
happens due to enabled IEXTEN local flag of termios. TTY cuts few bytes,
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. But I didn't check
compilation on other BSD / Linux distros. Could you please test it and let
me know results?

Signed-off-by: Michael Zhilin <mizhka@gmail.com>
I've added signed-off-by here, because I don't know how to add it into svn
patch.
It's my first patch, so please let me know if i miss anything.

Thanks,
  Michael!

Comments

Stefan Tauner Dec. 4, 2016, 1:48 a.m.
On Fri, 2 Dec 2016 18:41:26 +0300
Michael Zhilin <mizhka@gmail.com> wrote:

> Hi,
> 
> This is attached patch to avoid hang of serprog under FreeBSD. Patch is
> against trunk (r1955, 10 context lines).
> 
> My use case is flashrom+serprog to read SPI flash (MX25L6406) via Arduino
> Nano V3. Actual command is:
>  /usr/local/bin/flashrom -p serprog:dev=/dev/cuaU0:57600 -c
> MX25L6406E/MX25L6408E -r tcw770.dump
> 
> Using flashrom 0.9.9 it hangs after 5 seconds on read from tty ("ttyin").
> The problem is that kernel method "ttydisc_rint" ignore same bytes. It
> happens due to enabled IEXTEN local flag of termios. TTY cuts few bytes,
> 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. But I didn't check
> compilation on other BSD / Linux distros. Could you please test it and let
> me know results?
> 
> Signed-off-by: Michael Zhilin <mizhka@gmail.com>
> I've added signed-off-by here, because I don't know how to add it into svn
> patch.
> It's my first patch, so please let me know if i miss anything.

Thank you Michael! I have verified that it builds fine:
http://buildbot.flashrom.org/buildresults/flashrom-000559-9j8/results.html
I will merge it as soon as we finished migrating to git (and
gerrit+jenkins).

Patch hide | download patch | download mbox

Index: serial.c
===================================================================
--- serial.c	(revision 1955)
+++ serial.c	(working copy)
@@ -196,21 +196,21 @@ 
 	wanted = observed;
 	if (baud >= 0) {
 		const struct baudentry *entry = round_baud(baud);
 		if (cfsetispeed(&wanted, entry->flag) != 0 || cfsetospeed(&wanted, entry->flag) != 0) {
 			msg_perr_strerror("Could not set serial baud rate: ");
 			return 1;
 		}
 	}
 	wanted.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS);
 	wanted.c_cflag |= (CS8 | CLOCAL | CREAD);
-	wanted.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+	wanted.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG | IEXTEN);
 	wanted.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | IGNCR | INLCR);
 	wanted.c_oflag &= ~OPOST;
 	if (tcsetattr(fd, TCSANOW, &wanted) != 0) {
 		msg_perr_strerror("Could not change serial port configuration: ");
 		return 1;
 	}
 	if (tcgetattr(fd, &observed) != 0) {
 		msg_perr_strerror("Could not fetch new serial port configuration: ");
 		return 1;
 	}