summaryrefslogtreecommitdiff
path: root/ft2232_spi.c
diff options
context:
space:
mode:
authorhailfinger <hailfinger@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2010-07-06 09:55:48 +0000
committerhailfinger <hailfinger@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2010-07-06 09:55:48 +0000
commit2147cd8d74457918a12cc92d282557f254cfca59 (patch)
tree46de6c5dc108fc2868603fdc606e7328a83f1703 /ft2232_spi.c
parent18d526136bbbe8ca443da212fd678de94a97fe8e (diff)
downloadflashrom-2147cd8d74457918a12cc92d282557f254cfca59.tar.gz
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! Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1070 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'ft2232_spi.c')
-rw-r--r--ft2232_spi.c59
1 files changed, 31 insertions, 28 deletions
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) {