mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
Use a distinct return code for SPI commands with unsupported/invalid length
Some drivers support only a few combinations of read/write length and return error otherwise. Having a distinct return code for this error means we can handle it in upper layers. Corresponding to flashrom svn r653. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Reinauer <stepan@coresystems.de>
This commit is contained in:
parent
78e4e12712
commit
142e30fcaa
@ -201,6 +201,9 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
unsigned char port_val = 0;
|
unsigned char port_val = 0;
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
|
if (writecnt > 65536 || readcnt > 65536)
|
||||||
|
return SPI_INVALID_LENGTH;
|
||||||
|
|
||||||
buf = realloc(buf, writecnt + readcnt + 100);
|
buf = realloc(buf, writecnt + readcnt + 100);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
|
13
ichspi.c
13
ichspi.c
@ -599,10 +599,16 @@ static int run_opcode(OPCODE op, uint32_t offset,
|
|||||||
{
|
{
|
||||||
switch (spi_controller) {
|
switch (spi_controller) {
|
||||||
case SPI_CONTROLLER_VIA:
|
case SPI_CONTROLLER_VIA:
|
||||||
|
if (datalength > 16)
|
||||||
|
return SPI_INVALID_LENGTH;
|
||||||
return ich7_run_opcode(op, offset, datalength, data, 16);
|
return ich7_run_opcode(op, offset, datalength, data, 16);
|
||||||
case SPI_CONTROLLER_ICH7:
|
case SPI_CONTROLLER_ICH7:
|
||||||
|
if (datalength > 64)
|
||||||
|
return SPI_INVALID_LENGTH;
|
||||||
return ich7_run_opcode(op, offset, datalength, data, 64);
|
return ich7_run_opcode(op, offset, datalength, data, 64);
|
||||||
case SPI_CONTROLLER_ICH9:
|
case SPI_CONTROLLER_ICH9:
|
||||||
|
if (datalength > 64)
|
||||||
|
return SPI_INVALID_LENGTH;
|
||||||
return ich9_run_opcode(op, offset, datalength, data);
|
return ich9_run_opcode(op, offset, datalength, data);
|
||||||
default:
|
default:
|
||||||
printf_debug("%s: unsupported chipset\n", __FUNCTION__);
|
printf_debug("%s: unsupported chipset\n", __FUNCTION__);
|
||||||
@ -686,6 +692,7 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
const unsigned char *writearr, unsigned char *readarr)
|
const unsigned char *writearr, unsigned char *readarr)
|
||||||
{
|
{
|
||||||
int a;
|
int a;
|
||||||
|
int result;
|
||||||
int opcode_index = -1;
|
int opcode_index = -1;
|
||||||
const unsigned char cmd = *writearr;
|
const unsigned char cmd = *writearr;
|
||||||
OPCODE *opcode;
|
OPCODE *opcode;
|
||||||
@ -728,10 +735,10 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
count = readcnt;
|
count = readcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run_opcode(*opcode, addr, count, data) != 0) {
|
result = run_opcode(*opcode, addr, count, data);
|
||||||
|
if (result) {
|
||||||
printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);
|
printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
if (readcnt > 3) {
|
if (readcnt > 3) {
|
||||||
printf("%s called with unsupported readcnt %i.\n",
|
printf("%s called with unsupported readcnt %i.\n",
|
||||||
__FUNCTION__, readcnt);
|
__FUNCTION__, readcnt);
|
||||||
return 1;
|
return SPI_INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
switch (writecnt) {
|
switch (writecnt) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -200,7 +200,7 @@ int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
default:
|
default:
|
||||||
printf("%s called with unsupported writecnt %i.\n",
|
printf("%s called with unsupported writecnt %i.\n",
|
||||||
__FUNCTION__, writecnt);
|
__FUNCTION__, writecnt);
|
||||||
return 1;
|
return SPI_INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Start IO, 33 or 16 MHz, readcnt input bytes, writecnt output bytes.
|
* Start IO, 33 or 16 MHz, readcnt input bytes, writecnt output bytes.
|
||||||
|
10
sb600spi.c
10
sb600spi.c
@ -114,14 +114,14 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
|
|
||||||
if (readcnt > 8) {
|
if (readcnt > 8) {
|
||||||
printf("%s, SB600 SPI controller can not receive %d bytes, "
|
printf("%s, SB600 SPI controller can not receive %d bytes, "
|
||||||
"which is limited with 8 bytes\n", __func__, readcnt);
|
"it is limited to 8 bytes\n", __func__, readcnt);
|
||||||
return 1;
|
return SPI_INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writecnt > 8) {
|
if (writecnt > 8) {
|
||||||
printf("%s, SB600 SPI controller can not sent %d bytes, "
|
printf("%s, SB600 SPI controller can not send %d bytes, "
|
||||||
"which is limited with 8 bytes\n", __func__, writecnt);
|
"it is limited to 8 bytes\n", __func__, writecnt);
|
||||||
return 1;
|
return SPI_INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
mmio_writeb(cmd, sb600_spibar + 0);
|
mmio_writeb(cmd, sb600_spibar + 0);
|
||||||
|
1
spi.h
1
spi.h
@ -108,5 +108,6 @@
|
|||||||
/* Error codes */
|
/* Error codes */
|
||||||
#define SPI_INVALID_OPCODE -2
|
#define SPI_INVALID_OPCODE -2
|
||||||
#define SPI_INVALID_ADDRESS -3
|
#define SPI_INVALID_ADDRESS -3
|
||||||
|
#define SPI_INVALID_LENGTH -4
|
||||||
|
|
||||||
#endif /* !__SPI_H__ */
|
#endif /* !__SPI_H__ */
|
||||||
|
@ -154,7 +154,8 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
|||||||
if (!mode) {
|
if (!mode) {
|
||||||
fprintf(stderr, "%s: unsupported command type wr=%d rd=%d\n",
|
fprintf(stderr, "%s: unsupported command type wr=%d rd=%d\n",
|
||||||
__func__, writecnt, readcnt);
|
__func__, writecnt, readcnt);
|
||||||
return 1;
|
/* Command type refers to the number of bytes read/written. */
|
||||||
|
return SPI_INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTB(writearr[0], wbsio_spibase);
|
OUTB(writearr[0], wbsio_spibase);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user