From d2f007f98b64969bf788d251377c41e75abb69b1 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Thu, 16 Sep 2010 22:34:25 +0000 Subject: Handle Bus Pirates already in bit banging mode correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Johannes Sjölund for reporting that the Bus Pirate init could not deal with a Bus Pirate which is already in binary Bitbang mode. This is caused by a combination of the slowness of the Bus Pirate, the slowness of USB and a fast serial port flush routine which just flushes the buffer contents and does not wait until data arrival stops. Make the Bus Pirate init more robust by running the flush command 10 times with 1.5 ms delay in between. This code development was sponsored by Mattias Mattsson. Thanks! Tested a few dozen times, should work reliably. Corresponding to flashrom svn r1178. Signed-off-by: Carl-Daniel Hailfinger Acked-by: Mattias Mattsson --- serial.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'serial.c') diff --git a/serial.c b/serial.c index caf9389..9957fb4 100644 --- a/serial.c +++ b/serial.c @@ -200,8 +200,10 @@ int serialport_write(unsigned char *buf, unsigned int writecnt) #else tmp = write(sp_fd, buf, writecnt); #endif - if (tmp == -1) + if (tmp == -1) { + msg_perr("Serial port write error!\n"); return 1; + } if (!tmp) msg_pdbg("Empty write\n"); writecnt -= tmp; @@ -221,8 +223,10 @@ int serialport_read(unsigned char *buf, unsigned int readcnt) #else tmp = read(sp_fd, buf, readcnt); #endif - if (tmp == -1) + if (tmp == -1) { + msg_perr("Serial port read error!\n"); return 1; + } if (!tmp) msg_pdbg("Empty read\n"); readcnt -= tmp; -- cgit v1.1