Commit 72587f85 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

serprog: allow to omit specifying a baud rate


On USB-based serial connections (VCP) the requested baud rate usually
does not matter (much). Remove the arbitrary restriction and use whatever
default values the OS/hardware provides.

Corresponding to flashrom svn r1907.
Signed-off-by: default avatarStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: default avatarUrja Rannikko <urjaman@gmail.com>
parent 631bb021
...@@ -203,10 +203,9 @@ JTAGkey/JTAGkey-tiny/JTAGkey-2, Dangerous Prototypes Bus Blaster, \ ...@@ -203,10 +203,9 @@ JTAGkey/JTAGkey-tiny/JTAGkey-2, Dangerous Prototypes Bus Blaster, \
Olimex ARM-USB-TINY/-H, Olimex ARM-USB-OCD/-H, TIAO/DIYGADGET USB Olimex ARM-USB-TINY/-H, Olimex ARM-USB-OCD/-H, TIAO/DIYGADGET USB
Multi-Protocol Adapter (TUMPA), TUMPA Lite, and GOEPEL PicoTAP. Multi-Protocol Adapter (TUMPA), TUMPA Lite, and GOEPEL PicoTAP.
.sp .sp
.BR "* serprog" " (for flash ROMs attached to a programmer speaking serprog), \ .BR "* serprog" " (for flash ROMs attached to a programmer speaking serprog, \
including AVR flasher by Urja Rannikko, AVR flasher by eightdot, \ including Arduino-based devices as well as various programmers by Urja Rannikko, \
Arduino Mega flasher by fritz, InSystemFlasher by Juhana Helovuo, and \ Juhana Helovuo, Stefan Tauner and others)."
atmegaXXu2-flasher by Stefan Tauner."
.sp .sp
.BR "* buspirate_spi" " (for SPI flash ROMs attached to a Bus Pirate)" .BR "* buspirate_spi" " (for SPI flash ROMs attached to a Bus Pirate)"
.sp .sp
...@@ -683,19 +682,22 @@ parameter with the ...@@ -683,19 +682,22 @@ parameter with the
syntax. syntax.
.SS .SS
.BR "serprog " programmer .BR "serprog " programmer
A mandatory parameter specifies either a serial A mandatory parameter specifies either a serial device (and baud rate) or an IP/port combination for
device/baud combination or an IP/port combination for communication with the communicating with the programmer.
programmer. In the device/baud combination, the device has to start with a The device/baud combination has to start with
slash. For serial, you have to use the .B dev=
and separate the optional baud rate with a colon.
For example
.sp .sp
.B " flashrom \-p serprog:dev=/dev/device:baud" .B " flashrom \-p serprog:dev=/dev/ttyS0:115200"
.sp .sp
syntax and for IP, you have to use If no baud rate is given the default values by the operating system/hardware will be used.
For IP connections you have to use the
.sp .sp
.B " flashrom \-p serprog:ip=ipaddr:port" .B " flashrom \-p serprog:ip=ipaddr:port"
.sp .sp
instead. In case the device supports it, you can set the SPI clock frequency syntax.
with the optional In case the device supports it, you can set the SPI clock frequency with the optional
.B spispeed .B spispeed
parameter. The frequency is parsed as hertz, unless an parameter. The frequency is parsed as hertz, unless an
.BR M ", or " k .BR M ", or " k
......
...@@ -719,10 +719,8 @@ typedef int fdtype; ...@@ -719,10 +719,8 @@ typedef int fdtype;
#endif #endif
void sp_flush_incoming(void); void sp_flush_incoming(void);
fdtype sp_openserport(char *dev, unsigned int baud); fdtype sp_openserport(char *dev, int baud);
int serialport_config(fdtype fd, unsigned int baud);
extern fdtype sp_fd; extern fdtype sp_fd;
/* expose serialport_shutdown as it's currently used by buspirate */
int serialport_shutdown(void *data); int serialport_shutdown(void *data);
int serialport_write(const unsigned char *buf, unsigned int writecnt); int serialport_write(const unsigned char *buf, unsigned int writecnt);
int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote); int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
......
...@@ -116,7 +116,7 @@ static const struct baudentry sp_baudtable[] = { ...@@ -116,7 +116,7 @@ static const struct baudentry sp_baudtable[] = {
{0, 0} /* Terminator */ {0, 0} /* Terminator */
}; };
const struct baudentry *round_baud(unsigned int baud) static const struct baudentry *round_baud(unsigned int baud)
{ {
int i; int i;
/* Round baud rate to next lower entry in sp_baudtable if it exists, else use the lowest entry. */ /* Round baud rate to next lower entry in sp_baudtable if it exists, else use the lowest entry. */
...@@ -125,11 +125,12 @@ const struct baudentry *round_baud(unsigned int baud) ...@@ -125,11 +125,12 @@ const struct baudentry *round_baud(unsigned int baud)
return &sp_baudtable[i]; return &sp_baudtable[i];
if (sp_baudtable[i].baud < baud) { if (sp_baudtable[i].baud < baud) {
msg_pinfo("Warning: given baudrate %d rounded down to %d.\n", msg_pwarn("Warning: given baudrate %d rounded down to %d.\n",
baud, sp_baudtable[i].baud); baud, sp_baudtable[i].baud);
return &sp_baudtable[i]; return &sp_baudtable[i];
} }
} }
msg_pinfo("Using slowest possible baudrate: %d.\n", sp_baudtable[0].baud);
return &sp_baudtable[0]; return &sp_baudtable[0];
} }
...@@ -154,7 +155,7 @@ static void msg_perr_strerror(const char *msg) ...@@ -154,7 +155,7 @@ static void msg_perr_strerror(const char *msg)
#endif #endif
} }
int serialport_config(fdtype fd, unsigned int baud) int serialport_config(fdtype fd, int baud)
{ {
if (fd == SER_INV_FD) { if (fd == SER_INV_FD) {
msg_perr("%s: File descriptor is invalid.\n", __func__); msg_perr("%s: File descriptor is invalid.\n", __func__);
...@@ -167,8 +168,10 @@ int serialport_config(fdtype fd, unsigned int baud) ...@@ -167,8 +168,10 @@ int serialport_config(fdtype fd, unsigned int baud)
msg_perr_strerror("Could not fetch original serial port configuration: "); msg_perr_strerror("Could not fetch original serial port configuration: ");
return 1; return 1;
} }
const struct baudentry *entry = round_baud(baud); if (baud >= 0) {
dcb.BaudRate = entry->flag; const struct baudentry *entry = round_baud(baud);
dcb.BaudRate = entry->flag;
}
dcb.ByteSize = 8; dcb.ByteSize = 8;
dcb.Parity = NOPARITY; dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT; dcb.StopBits = ONESTOPBIT;
...@@ -188,10 +191,12 @@ int serialport_config(fdtype fd, unsigned int baud) ...@@ -188,10 +191,12 @@ int serialport_config(fdtype fd, unsigned int baud)
return 1; return 1;
} }
wanted = observed; wanted = observed;
const struct baudentry *entry = round_baud(baud); if (baud >= 0) {
if (cfsetispeed(&wanted, entry->flag) != 0 || cfsetospeed(&wanted, entry->flag) != 0) { const struct baudentry *entry = round_baud(baud);
msg_perr_strerror("Could not set serial baud rate: "); if (cfsetispeed(&wanted, entry->flag) != 0 || cfsetospeed(&wanted, entry->flag) != 0) {
return 1; msg_perr_strerror("Could not set serial baud rate: ");
return 1;
}
} }
wanted.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS); wanted.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS);
wanted.c_cflag |= (CS8 | CLOCAL | CREAD); wanted.c_cflag |= (CS8 | CLOCAL | CREAD);
...@@ -232,7 +237,7 @@ int serialport_config(fdtype fd, unsigned int baud) ...@@ -232,7 +237,7 @@ int serialport_config(fdtype fd, unsigned int baud)
return 0; return 0;
} }
fdtype sp_openserport(char *dev, unsigned int baud) fdtype sp_openserport(char *dev, int baud)
{ {
fdtype fd; fdtype fd;
#if IS_WINDOWS #if IS_WINDOWS
......
...@@ -342,26 +342,28 @@ int serprog_init(void) ...@@ -342,26 +342,28 @@ int serprog_init(void)
unsigned char rbuf[3]; unsigned char rbuf[3];
unsigned char c; unsigned char c;
char *device; char *device;
char *baudport;
int have_device = 0; int have_device = 0;
/* the parameter is either of format "dev=/dev/device:baud" or "ip=ip:port" */ /* the parameter is either of format "dev=/dev/device[:baud]" or "ip=ip:port" */
device = extract_programmer_param("dev"); device = extract_programmer_param("dev");
if (device && strlen(device)) { if (device && strlen(device)) {
baudport = strstr(device, ":"); char *baud_str = strstr(device, ":");
if (baudport) { if (baud_str != NULL) {
/* Split device from baudrate. */ /* Split device from baudrate. */
*baudport = '\0'; *baud_str = '\0';
baudport++; baud_str++;
} }
if (!baudport || !strlen(baudport)) { int baud;
msg_perr("Error: No baudrate specified.\n" /* Convert baud string to value.
"Use flashrom -p serprog:dev=/dev/device:baud\n"); * baud_str is either NULL (if strstr can't find the colon), points to the \0 after the colon
free(device); * if no characters where given after the colon, or a string to convert... */
return 1; if (baud_str == NULL || *baud_str == '\0') {
} baud = -1;
if (strlen(device)) { msg_pdbg("No baudrate specified, using the hardware's defaults.\n");
sp_fd = sp_openserport(device, atoi(baudport)); } else
baud = atoi(baud_str); // FIXME: replace atoi with strtoul
if (strlen(device) > 0) {
sp_fd = sp_openserport(device, baud);
if (sp_fd == SER_INV_FD) { if (sp_fd == SER_INV_FD) {
free(device); free(device);
return 1; return 1;
...@@ -371,7 +373,7 @@ int serprog_init(void) ...@@ -371,7 +373,7 @@ int serprog_init(void)
} }
if (device && !strlen(device)) { if (device && !strlen(device)) {
msg_perr("Error: No device specified.\n" msg_perr("Error: No device specified.\n"
"Use flashrom -p serprog:dev=/dev/device:baud\n"); "Use flashrom -p serprog:dev=/dev/device[:baud]\n");
free(device); free(device);
return 1; return 1;
} }
...@@ -386,20 +388,20 @@ int serprog_init(void) ...@@ -386,20 +388,20 @@ int serprog_init(void)
return 1; return 1;
} }
if (device && strlen(device)) { if (device && strlen(device)) {
baudport = strstr(device, ":"); char *port = strstr(device, ":");
if (baudport) { if (port != NULL) {
/* Split host from port. */ /* Split host from port. */
*baudport = '\0'; *port = '\0';
baudport++; port++;
} }
if (!baudport || !strlen(baudport)) { if (!port || !strlen(port)) {
msg_perr("Error: No port specified.\n" msg_perr("Error: No port specified.\n"
"Use flashrom -p serprog:ip=ipaddr:port\n"); "Use flashrom -p serprog:ip=ipaddr:port\n");
free(device); free(device);
return 1; return 1;
} }
if (strlen(device)) { if (strlen(device)) {
sp_fd = sp_opensocket(device, atoi(baudport)); sp_fd = sp_opensocket(device, atoi(port)); // FIXME: replace atoi with strtoul
if (sp_fd < 0) { if (sp_fd < 0) {
free(device); free(device);
return 1; return 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment