diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-07-06 09:55:48 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-07-06 09:55:48 +0000 |
commit | 744132af4b9f629716394f9c22f6add71cc73ef9 (patch) | |
tree | 46de6c5dc108fc2868603fdc606e7328a83f1703 /ft2232_spi.c | |
parent | d1be52d545329debd2128c1aa8685b31dfaa0a0e (diff) | |
download | flashrom-744132af4b9f629716394f9c22f6add71cc73ef9.tar.gz flashrom-744132af4b9f629716394f9c22f6add71cc73ef9.tar.bz2 flashrom-744132af4b9f629716394f9c22f6add71cc73ef9.zip |
Various places in the flashrom source feature custom parameter extraction from programmer_param
This led to wildly differing syntax for programmer parameters, and
it also voids pretty much every assumption you could make about
programmer_param. The latter is a problem for libflashrom.
Use extract_param everywhere, clean up related code and make it more
foolproof. Add two instances of exit(1) where we have no option to
return an error. Remove six instances of exit(1) where returning an
error was possible.
WARNING: This changes programmer parameter syntax for a few programmers!
Corresponding to flashrom svn r1070.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
Diffstat (limited to 'ft2232_spi.c')
-rw-r--r-- | ft2232_spi.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/ft2232_spi.c b/ft2232_spi.c index c45bb1fd7..0245c532e 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -76,46 +76,49 @@ int ft2232_spi_init(void) int f; struct ftdi_context *ftdic = &ftdic_context; unsigned char buf[512]; - char *portpos = NULL; int ft2232_type = FTDI_FT4232H; enum ftdi_interface ft2232_interface = INTERFACE_B; + char *arg; - if (ftdi_init(ftdic) < 0) { - msg_perr("ftdi_init failed\n"); - return EXIT_FAILURE; // TODO - } - - if (programmer_param && !strlen(programmer_param)) { - free(programmer_param); - programmer_param = NULL; - } - if (programmer_param) { - if (strstr(programmer_param, "2232")) + arg = extract_param(&programmer_param, "type", ",:"); + if (arg) { + if (!strcasecmp(arg, "2232H")) ft2232_type = FTDI_FT2232H; - if (strstr(programmer_param, "4232")) + else if (!strcasecmp(arg, "4232H")) ft2232_type = FTDI_FT4232H; - portpos = strstr(programmer_param, "port="); - if (portpos) { - portpos += 5; - switch (toupper(*portpos)) { - case 'A': - ft2232_interface = INTERFACE_A; - break; - case 'B': - ft2232_interface = INTERFACE_B; - break; - default: - msg_perr("Invalid interface specified, " - "using default.\n"); - } + else { + msg_perr("Error: Invalid device type specified.\n"); + free(arg); + return 1; } - free(programmer_param); } + free(arg); + arg = extract_param(&programmer_param, "port", ",:"); + if (arg) { + switch (toupper(*arg)) { + case 'A': + ft2232_interface = INTERFACE_A; + break; + case 'B': + ft2232_interface = INTERFACE_B; + break; + default: + msg_perr("Error: Invalid port/interface specified.\n"); + free(arg); + return 1; + } + } + free(arg); msg_pdbg("Using device type %s ", (ft2232_type == FTDI_FT2232H) ? "2232H" : "4232H"); msg_pdbg("interface %s\n", (ft2232_interface == INTERFACE_A) ? "A" : "B"); + if (ftdi_init(ftdic) < 0) { + msg_perr("ftdi_init failed\n"); + return EXIT_FAILURE; // TODO + } + f = ftdi_usb_open(ftdic, 0x0403, ft2232_type); if (f < 0 && f != -5) { |