[flashrom] [commit] r831 - trunk
svn at flashrom.org
svn at flashrom.org
Wed Jan 6 20:09:41 CET 2010
Author: oxygene
Date: 2010-01-06 20:09:40 +0100 (Wed, 06 Jan 2010)
New Revision: 831
Modified:
trunk/buspirate_spi.c
trunk/flash.h
trunk/serial.c
Log:
- replace the hand written serial input flush routine with the termios one.
- serialport_discard_read isn't necessary anymore - it just wrapped
sp_flush_incoming with no extra value.
- serialport_read and serialport_write would misbehave if read or write
didn't process everything in one go.
- sp_flush_incoming should be #define'd out for FAKE_COMMUNICATION like
serialport_discard_read was
Signed-off-by: Patrick Georgi <patrick.georgi at coresystems.de>
Acked-by: Sean Nelson <audiohacked at gmail.com>
Modified: trunk/buspirate_spi.c
===================================================================
--- trunk/buspirate_spi.c 2010-01-06 16:09:10 UTC (rev 830)
+++ trunk/buspirate_spi.c 2010-01-06 19:09:40 UTC (rev 831)
@@ -40,7 +40,7 @@
#define serialport_shutdown(...) 0
#define serialport_write(...) 0
#define serialport_read(...) 0
-#define serialport_discard_read(...) 0
+#define sp_flush_incoming(...) 0
#endif
int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int readcnt)
@@ -144,9 +144,7 @@
if (ret)
return ret;
/* Read any response and discard it. */
- ret = serialport_discard_read();
- if (ret)
- return ret;
+ sp_flush_incoming();
}
/* Enter raw bitbang mode */
buf[0] = 0x00;
Modified: trunk/flash.h
===================================================================
--- trunk/flash.h 2010-01-06 16:09:10 UTC (rev 830)
+++ trunk/flash.h 2010-01-06 19:09:40 UTC (rev 831)
@@ -598,7 +598,6 @@
int serialport_shutdown(void);
int serialport_write(unsigned char *buf, unsigned int writecnt);
int serialport_read(unsigned char *buf, unsigned int readcnt);
-int serialport_discard_read(void);
#include "chipdrivers.h"
Modified: trunk/serial.c
===================================================================
--- trunk/serial.c 2010-01-06 16:09:10 UTC (rev 830)
+++ trunk/serial.c 2010-01-06 19:09:40 UTC (rev 831)
@@ -129,16 +129,7 @@
void sp_flush_incoming(void)
{
- int i;
- for (i=0;i<100;i++) { /* In case the device doesnt do EAGAIN, just read 0 */
- unsigned char flush[16];
- ssize_t rv;
- rv = read(sp_fd, flush, sizeof(flush));
- if ((rv == -1) && (errno == EAGAIN))
- break;
- if (rv == -1)
- sp_die("flush read");
- }
+ tcflush(sp_fd, TCIFLUSH);
return;
}
@@ -152,12 +143,14 @@
{
int tmp = 0;
- while (tmp != writecnt) {
- tmp = write(sp_fd, buf + tmp, writecnt - tmp);
+ while (writecnt > 0) {
+ tmp = write(sp_fd, buf, writecnt);
if (tmp == -1)
return 1;
if (!tmp)
printf_debug("Empty write\n");
+ writecnt -= tmp;
+ buf += tmp;
}
return 0;
@@ -167,28 +160,15 @@
{
int tmp = 0;
- while (tmp != readcnt) {
- tmp = read(sp_fd, buf + tmp, readcnt - tmp);
+ while (readcnt > 0) {
+ tmp = read(sp_fd, buf, readcnt);
if (tmp == -1)
return 1;
if (!tmp)
printf_debug("Empty read\n");
+ readcnt -= tmp;
+ buf += tmp;
}
return 0;
}
-
-int serialport_discard_read(void)
-{
- int flags;
-
- printf_debug("%s\n", __func__);
- flags = fcntl(sp_fd, F_GETFL);
- flags |= O_NONBLOCK;
- fcntl(sp_fd, F_SETFL, flags);
- sp_flush_incoming();
- flags &= ~O_NONBLOCK;
- fcntl(sp_fd, F_SETFL, flags);
-
- return 0;
-}
More information about the flashrom
mailing list