mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-26 22:52:34 +02:00
serprog: clear NDELAY flag only once after opening the port
Change sp_openserport() to directly clear the O_NONBLOCK flag that is potentially set by opening the device with O_NDELAY instead of clearing ALL flags in serialport_config() unconditionally. Corresponding to flashrom svn r1905. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Urja Rannikko <urjaman@gmail.com>
This commit is contained in:
parent
3d06abef13
commit
a4d60f3101
18
serial.c
18
serial.c
@ -183,10 +183,6 @@ int serialport_config(fdtype fd, unsigned int baud)
|
|||||||
msg_pdbg("Baud rate is %ld.\n", dcb.BaudRate);
|
msg_pdbg("Baud rate is %ld.\n", dcb.BaudRate);
|
||||||
#else
|
#else
|
||||||
struct termios wanted, observed;
|
struct termios wanted, observed;
|
||||||
if (fcntl(fd, F_SETFL, 0) != 0) {
|
|
||||||
msg_perr_strerror("Could not clear serial port mode: ");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (tcgetattr(fd, &observed) != 0) {
|
if (tcgetattr(fd, &observed) != 0) {
|
||||||
msg_perr_strerror("Could not fetch original serial port configuration: ");
|
msg_perr_strerror("Could not fetch original serial port configuration: ");
|
||||||
return 1;
|
return 1;
|
||||||
@ -254,11 +250,23 @@ fdtype sp_openserport(char *dev, unsigned int baud)
|
|||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
#else
|
#else
|
||||||
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
|
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY); // Use O_NDELAY to ignore DCD state
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
msg_perr_strerror("Cannot open serial port: ");
|
msg_perr_strerror("Cannot open serial port: ");
|
||||||
return SER_INV_FD;
|
return SER_INV_FD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ensure that we use blocking I/O */
|
||||||
|
const int flags = fcntl(fd, F_GETFL);
|
||||||
|
if (flags == -1) {
|
||||||
|
msg_perr_strerror("Could not get serial port mode: ");
|
||||||
|
return SER_INV_FD;
|
||||||
|
}
|
||||||
|
if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) != 0) {
|
||||||
|
msg_perr_strerror("Could not set serial port mode to blocking: ");
|
||||||
|
return SER_INV_FD;
|
||||||
|
}
|
||||||
|
|
||||||
if (serialport_config(fd, baud) != 0) {
|
if (serialport_config(fd, baud) != 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return SER_INV_FD;
|
return SER_INV_FD;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user