mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +02:00
ft2232_spi: Allow runtime selection of FT2232H vs. FT4232H and interface A vs
B. Corresponding to flashrom svn r638. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Tested-by: Jakob Bornecrantz <wallbraker@gmail.com> Acked-by: Jakob Bornecrantz <wallbraker@gmail.com>
This commit is contained in:
parent
9cb867b571
commit
feea272228
3
flash.h
3
flash.h
@ -368,6 +368,9 @@ uint8_t satasii_chip_readb(const chipaddr addr);
|
|||||||
extern struct pcidev_status satas_sii[];
|
extern struct pcidev_status satas_sii[];
|
||||||
|
|
||||||
/* ft2232_spi.c */
|
/* ft2232_spi.c */
|
||||||
|
#define FTDI_FT2232H 0x6010
|
||||||
|
#define FTDI_FT4232H 0x6011
|
||||||
|
extern char *ft2232spi_param;
|
||||||
int ft2232_spi_init(void);
|
int ft2232_spi_init(void);
|
||||||
int ft2232_spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
int ft2232_spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
||||||
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||||
|
17
flashrom.8
17
flashrom.8
@ -183,6 +183,23 @@ Example:
|
|||||||
Currently the following programmers support this mechanism:
|
Currently the following programmers support this mechanism:
|
||||||
.BR nic3com ,
|
.BR nic3com ,
|
||||||
.BR satasii .
|
.BR satasii .
|
||||||
|
.sp
|
||||||
|
The ft2232spi has an optional parameter specifying the controller type and
|
||||||
|
interface/port it should support. For that you have to use the
|
||||||
|
.B "flashrom -p ft2232spi=model,port=interface"
|
||||||
|
syntax where
|
||||||
|
.B model
|
||||||
|
can be any of
|
||||||
|
.B 2232H 4232H
|
||||||
|
and
|
||||||
|
.B interface
|
||||||
|
can be any of
|
||||||
|
.B A
|
||||||
|
.BR B .
|
||||||
|
The default model is
|
||||||
|
.B 4232H
|
||||||
|
and the default interface is
|
||||||
|
.BR B .
|
||||||
.TP
|
.TP
|
||||||
.B "\-h, \-\-help"
|
.B "\-h, \-\-help"
|
||||||
Show a help text and exit.
|
Show a help text and exit.
|
||||||
|
10
flashrom.c
10
flashrom.c
@ -649,10 +649,12 @@ int main(int argc, char *argv[])
|
|||||||
programmer = PROGRAMMER_IT87SPI;
|
programmer = PROGRAMMER_IT87SPI;
|
||||||
} else if (strncmp(optarg, "ft2232spi", 9) == 0) {
|
} else if (strncmp(optarg, "ft2232spi", 9) == 0) {
|
||||||
programmer = PROGRAMMER_FT2232SPI;
|
programmer = PROGRAMMER_FT2232SPI;
|
||||||
} else if (strncmp(optarg, "serprog", 7) == 0) {
|
if (optarg[9] == '=')
|
||||||
programmer = PROGRAMMER_SERPROG;
|
ft2232spi_param = strdup(optarg + 10);
|
||||||
if (optarg[7] == '=')
|
} else if (strncmp(optarg, "serprog", 7) == 0) {
|
||||||
serprog_param = strdup(optarg + 8);
|
programmer = PROGRAMMER_SERPROG;
|
||||||
|
if (optarg[7] == '=')
|
||||||
|
serprog_param = strdup(optarg + 8);
|
||||||
} else {
|
} else {
|
||||||
printf("Error: Unknown programmer.\n");
|
printf("Error: Unknown programmer.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
45
ft2232_spi.c
45
ft2232_spi.c
@ -22,9 +22,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
|
char *ft2232spi_param = NULL;
|
||||||
|
|
||||||
#if FT2232_SPI_SUPPORT == 1
|
#if FT2232_SPI_SUPPORT == 1
|
||||||
|
|
||||||
#include <ftdi.h>
|
#include <ftdi.h>
|
||||||
@ -71,15 +74,47 @@ int ft2232_spi_init(void)
|
|||||||
struct ftdi_context *ftdic = &ftdic_context;
|
struct ftdi_context *ftdic = &ftdic_context;
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
unsigned char port_val = 0;
|
unsigned char port_val = 0;
|
||||||
|
char *portpos = NULL;
|
||||||
|
int ft2232_type = FTDI_FT4232H;
|
||||||
|
enum ftdi_interface ft2232_interface = INTERFACE_B;
|
||||||
|
|
||||||
if (ftdi_init(ftdic) < 0) {
|
if (ftdi_init(ftdic) < 0) {
|
||||||
fprintf(stderr, "ftdi_init failed\n");
|
fprintf(stderr, "ftdi_init failed\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// f = ftdi_usb_open(ftdic, 0x0403, 0x6010); // FT2232
|
if (ft2232spi_param && !strlen(ft2232spi_param)) {
|
||||||
f = ftdi_usb_open(ftdic, 0x0403, 0x6011); // FT4232
|
free(ft2232spi_param);
|
||||||
|
ft2232spi_param = NULL;
|
||||||
|
}
|
||||||
|
if (ft2232spi_param) {
|
||||||
|
if (strstr(ft2232spi_param, "2232"))
|
||||||
|
ft2232_type = FTDI_FT2232H;
|
||||||
|
if (strstr(ft2232spi_param, "4232"))
|
||||||
|
ft2232_type = FTDI_FT4232H;
|
||||||
|
portpos = strstr(ft2232spi_param, "port=");
|
||||||
|
if (portpos) {
|
||||||
|
portpos += 5;
|
||||||
|
switch (toupper(*portpos)) {
|
||||||
|
case 'A':
|
||||||
|
ft2232_interface = INTERFACE_A;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
ft2232_interface = INTERFACE_B;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Invalid interface specified, "
|
||||||
|
"using default.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(ft2232spi_param);
|
||||||
|
}
|
||||||
|
printf_debug("Using device type %s ",
|
||||||
|
(ft2232_type == FTDI_FT2232H) ? "2232H" : "4232H");
|
||||||
|
printf_debug("interface %s\n",
|
||||||
|
(ft2232_interface == INTERFACE_A) ? "A" : "B");
|
||||||
|
|
||||||
|
f = ftdi_usb_open(ftdic, 0x0403, ft2232_type);
|
||||||
|
|
||||||
if (f < 0 && f != -5) {
|
if (f < 0 && f != -5) {
|
||||||
fprintf(stderr, "Unable to open ftdi device: %d (%s)\n", f,
|
fprintf(stderr, "Unable to open ftdi device: %d (%s)\n", f,
|
||||||
@ -87,8 +122,8 @@ int ft2232_spi_init(void)
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftdi_set_interface(ftdic, INTERFACE_B) < 0) {
|
if (ftdi_set_interface(ftdic, ft2232_interface) < 0) {
|
||||||
fprintf(stderr, "Unable to select FT2232 channel B: %s\n",
|
fprintf(stderr, "Unable to select interface: %s\n",
|
||||||
ftdic->error_str);
|
ftdic->error_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user