mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-26 22:52:34 +02:00
Remove more exit calls
This patch removes the remaining exit calls from - sp_openserport - sp_opensocket - sp_docommand - internal_init Almost all of this was done by Niklas. Corresponding to flashrom svn r1557. Signed-off-by: Niklas Söderlund <niso@kth.se> Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
This commit is contained in:
parent
00ec027368
commit
2a95e8713b
@ -39,7 +39,8 @@ static int buspirate_serialport_setup(char *dev)
|
|||||||
{
|
{
|
||||||
/* 115200bps, 8 databits, no parity, 1 stopbit */
|
/* 115200bps, 8 databits, no parity, 1 stopbit */
|
||||||
sp_fd = sp_openserport(dev, 115200);
|
sp_fd = sp_openserport(dev, 115200);
|
||||||
/* FIXME: Error checking */
|
if (sp_fd < 0)
|
||||||
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -299,7 +299,7 @@ int internal_init(void)
|
|||||||
msg_perr("Proceeding anyway because user forced us to.\n");
|
msg_perr("Proceeding anyway because user forced us to.\n");
|
||||||
} else {
|
} else {
|
||||||
msg_perr("Aborting.\n");
|
msg_perr("Aborting.\n");
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,10 @@ int pony_spi_init(void)
|
|||||||
|
|
||||||
if (arg && strlen(arg)) {
|
if (arg && strlen(arg)) {
|
||||||
sp_fd = sp_openserport( arg, 9600 );
|
sp_fd = sp_openserport( arg, 9600 );
|
||||||
|
if (sp_fd < 0) {
|
||||||
|
free(arg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
have_device++;
|
have_device++;
|
||||||
}
|
}
|
||||||
free(arg);
|
free(arg);
|
||||||
|
29
serial.c
29
serial.c
@ -113,8 +113,10 @@ fdtype sp_openserport(char *dev, unsigned int baud)
|
|||||||
(tolower((unsigned char)dev[1]) == 'o') &&
|
(tolower((unsigned char)dev[1]) == 'o') &&
|
||||||
(tolower((unsigned char)dev[2]) == 'm')) {
|
(tolower((unsigned char)dev[2]) == 'm')) {
|
||||||
dev2 = malloc(strlen(dev) + 5);
|
dev2 = malloc(strlen(dev) + 5);
|
||||||
if (!dev2)
|
if (!dev2) {
|
||||||
sp_die("Error: Out of memory");
|
msg_perr("Error: Out of memory: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
strcpy(dev2, "\\\\.\\");
|
strcpy(dev2, "\\\\.\\");
|
||||||
strcpy(dev2 + 4, dev);
|
strcpy(dev2 + 4, dev);
|
||||||
}
|
}
|
||||||
@ -123,11 +125,13 @@ fdtype sp_openserport(char *dev, unsigned int baud)
|
|||||||
if (dev2 != dev)
|
if (dev2 != dev)
|
||||||
free(dev2);
|
free(dev2);
|
||||||
if (fd == INVALID_HANDLE_VALUE) {
|
if (fd == INVALID_HANDLE_VALUE) {
|
||||||
sp_die("Error: cannot open serial port");
|
msg_perr("Error: cannot open serial port: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
DCB dcb;
|
DCB dcb;
|
||||||
if (!GetCommState(fd, &dcb)) {
|
if (!GetCommState(fd, &dcb)) {
|
||||||
sp_die("Error: Could not fetch serial port configuration");
|
msg_perr("Error: Could not fetch serial port configuration: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
switch (baud) {
|
switch (baud) {
|
||||||
case 9600: dcb.BaudRate = CBR_9600; break;
|
case 9600: dcb.BaudRate = CBR_9600; break;
|
||||||
@ -135,29 +139,32 @@ fdtype sp_openserport(char *dev, unsigned int baud)
|
|||||||
case 38400: dcb.BaudRate = CBR_38400; break;
|
case 38400: dcb.BaudRate = CBR_38400; break;
|
||||||
case 57600: dcb.BaudRate = CBR_57600; break;
|
case 57600: dcb.BaudRate = CBR_57600; break;
|
||||||
case 115200: dcb.BaudRate = CBR_115200; break;
|
case 115200: dcb.BaudRate = CBR_115200; break;
|
||||||
default: sp_die("Error: Could not set baud rate");
|
default: msg_perr("Error: Could not set baud rate: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
dcb.ByteSize = 8;
|
dcb.ByteSize = 8;
|
||||||
dcb.Parity = NOPARITY;
|
dcb.Parity = NOPARITY;
|
||||||
dcb.StopBits = ONESTOPBIT;
|
dcb.StopBits = ONESTOPBIT;
|
||||||
if (!SetCommState(fd, &dcb)) {
|
if (!SetCommState(fd, &dcb)) {
|
||||||
sp_die("Error: Could not change serial port configuration");
|
msg_perr("Error: Could not change serial port configuration: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
#else
|
#else
|
||||||
struct termios options;
|
struct termios options;
|
||||||
int fd, i;
|
int fd, i;
|
||||||
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
|
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
sp_die("Error: cannot open serial port");
|
msg_perr("Error: cannot open serial port: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
fcntl(fd, F_SETFL, 0);
|
fcntl(fd, F_SETFL, 0);
|
||||||
tcgetattr(fd, &options);
|
tcgetattr(fd, &options);
|
||||||
for (i = 0;; i++) {
|
for (i = 0;; i++) {
|
||||||
if (sp_baudtable[i].baud == 0) {
|
if (sp_baudtable[i].baud == 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
msg_perr("Error: cannot configure for baudrate %d\n",
|
msg_perr("Error: cannot configure for baudrate %d\n", baud);
|
||||||
baud);
|
return -1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (sp_baudtable[i].baud == baud) {
|
if (sp_baudtable[i].baud == baud) {
|
||||||
cfsetispeed(&options, sp_baudtable[i].flag);
|
cfsetispeed(&options, sp_baudtable[i].flag);
|
||||||
|
57
serprog.c
57
serprog.c
@ -110,20 +110,25 @@ static int sp_opensocket(char *ip, unsigned int port)
|
|||||||
int sock;
|
int sock;
|
||||||
msg_pdbg(MSGHEADER "IP %s port %d\n", ip, port);
|
msg_pdbg(MSGHEADER "IP %s port %d\n", ip, port);
|
||||||
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (sock < 0)
|
if (sock < 0) {
|
||||||
sp_die("Error: serprog cannot open socket");
|
msg_perr("Error: serprog cannot open socket: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
hostPtr = gethostbyname(ip);
|
hostPtr = gethostbyname(ip);
|
||||||
if (NULL == hostPtr) {
|
if (NULL == hostPtr) {
|
||||||
hostPtr = gethostbyaddr(ip, strlen(ip), AF_INET);
|
hostPtr = gethostbyaddr(ip, strlen(ip), AF_INET);
|
||||||
if (NULL == hostPtr)
|
if (NULL == hostPtr) {
|
||||||
sp_die("Error: cannot resolve");
|
msg_perr("Error: cannot resolve %s\n", ip);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sp.si.sin_family = AF_INET;
|
sp.si.sin_family = AF_INET;
|
||||||
sp.si.sin_port = htons(port);
|
sp.si.sin_port = htons(port);
|
||||||
(void)memcpy(&sp.si.sin_addr, hostPtr->h_addr, hostPtr->h_length);
|
(void)memcpy(&sp.si.sin_addr, hostPtr->h_addr, hostPtr->h_length);
|
||||||
if (connect(sock, &sp.s, sizeof(sp.si)) < 0) {
|
if (connect(sock, &sp.s, sizeof(sp.si)) < 0) {
|
||||||
close(sock);
|
close(sock);
|
||||||
sp_die("Error: serprog cannot connect");
|
msg_perr("Error: serprog cannot connect: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
/* We are latency limited, and sometimes do write-write-read *
|
/* We are latency limited, and sometimes do write-write-read *
|
||||||
* (write-n) - so enable TCP_NODELAY. */
|
* (write-n) - so enable TCP_NODELAY. */
|
||||||
@ -233,17 +238,23 @@ static int sp_docommand(uint8_t command, uint32_t parmlen,
|
|||||||
unsigned char c;
|
unsigned char c;
|
||||||
if (sp_automatic_cmdcheck(command))
|
if (sp_automatic_cmdcheck(command))
|
||||||
return 1;
|
return 1;
|
||||||
if (write(sp_fd, &command, 1) != 1)
|
if (write(sp_fd, &command, 1) != 1) {
|
||||||
sp_die("Error: cannot write op code");
|
msg_perr("Error: cannot write op code: %s\n", strerror(errno));
|
||||||
if (write(sp_fd, params, parmlen) != (parmlen))
|
return 1;
|
||||||
sp_die("Error: cannot write parameters");
|
}
|
||||||
if (read(sp_fd, &c, 1) != 1)
|
if (write(sp_fd, params, parmlen) != (parmlen)) {
|
||||||
sp_die("Error: cannot read from device");
|
msg_perr("Error: cannot write parameters: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (read(sp_fd, &c, 1) != 1) {
|
||||||
|
msg_perr("Error: cannot read from device: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (c == S_NAK)
|
if (c == S_NAK)
|
||||||
return 1;
|
return 1;
|
||||||
if (c != S_ACK) {
|
if (c != S_ACK) {
|
||||||
msg_perr("Error: invalid response 0x%02X from device\n",c);
|
msg_perr("Error: invalid response 0x%02X from device\n", c);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
if (retlen) {
|
if (retlen) {
|
||||||
int rd_bytes = 0;
|
int rd_bytes = 0;
|
||||||
@ -251,8 +262,10 @@ static int sp_docommand(uint8_t command, uint32_t parmlen,
|
|||||||
int r;
|
int r;
|
||||||
r = read(sp_fd, retparms + rd_bytes,
|
r = read(sp_fd, retparms + rd_bytes,
|
||||||
retlen - rd_bytes);
|
retlen - rd_bytes);
|
||||||
if (r <= 0)
|
if (r <= 0) {
|
||||||
sp_die("Error: cannot read return parameters");
|
msg_perr("Error: cannot read return parameters: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
rd_bytes += r;
|
rd_bytes += r;
|
||||||
} while (rd_bytes != retlen);
|
} while (rd_bytes != retlen);
|
||||||
}
|
}
|
||||||
@ -362,6 +375,10 @@ int serprog_init(void)
|
|||||||
}
|
}
|
||||||
if (strlen(device)) {
|
if (strlen(device)) {
|
||||||
sp_fd = sp_openserport(device, atoi(baudport));
|
sp_fd = sp_openserport(device, atoi(baudport));
|
||||||
|
if (sp_fd < 0) {
|
||||||
|
free(device);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
have_device++;
|
have_device++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,6 +412,10 @@ int serprog_init(void)
|
|||||||
}
|
}
|
||||||
if (strlen(device)) {
|
if (strlen(device)) {
|
||||||
sp_fd = sp_opensocket(device, atoi(baudport));
|
sp_fd = sp_opensocket(device, atoi(baudport));
|
||||||
|
if (sp_fd < 0) {
|
||||||
|
free(device);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
have_device++;
|
have_device++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -466,11 +487,12 @@ int serprog_init(void)
|
|||||||
"bustype is SPI\n");
|
"bustype is SPI\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL))
|
||||||
|
return 1;
|
||||||
/* Success of any of these commands is optional. We don't need
|
/* Success of any of these commands is optional. We don't need
|
||||||
the programmer to tell us its limits, but if it doesn't, we
|
the programmer to tell us its limits, but if it doesn't, we
|
||||||
will assume stuff, so it's in the programmers best interest
|
will assume stuff, so it's in the programmers best interest
|
||||||
to tell us. */
|
to tell us. */
|
||||||
sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL);
|
|
||||||
if (!sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) {
|
if (!sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) {
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
v = ((unsigned int)(rbuf[0]) << 0);
|
v = ((unsigned int)(rbuf[0]) << 0);
|
||||||
@ -492,7 +514,8 @@ int serprog_init(void)
|
|||||||
msg_pdbg(MSGHEADER "Maximum read-n length is %d\n", v);
|
msg_pdbg(MSGHEADER "Maximum read-n length is %d\n", v);
|
||||||
}
|
}
|
||||||
bt = serprog_buses_supported;
|
bt = serprog_buses_supported;
|
||||||
sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL);
|
if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL))
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serprog_buses_supported & BUS_NONSPI) {
|
if (serprog_buses_supported & BUS_NONSPI) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user