From 744132af4b9f629716394f9c22f6add71cc73ef9 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Tue, 6 Jul 2010 09:55:48 +0000 Subject: 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 Acked-by: Michael Karcher --- ft2232_spi.c | 59 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'ft2232_spi.c') diff --git a/ft2232_spi.c b/ft2232_spi.c index c45bb1f..0245c53 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) { -- cgit v1.1