Hi,

I got this email from a mailing list somewhere. I'm experiencing an issue where I'm unable to flash using spidev on a Raspberry Pi.

I'm running "4.14.79-1.rpi.fc27.armv7hl", which is based on Fedberry. I'm experiencing two issues:

1) I'm completely unable to access any SPI chips. This appears to be due to a bug in the kernel driver, which always yanks the CS line high despite the cs_change set to 0. A workaround I've come up with is to do everything as a single transaction, which seems to fix the problem on my device:

diff --git a/linux_spi.c b/linux_spi.c
index 3e60492..50f8220 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -183,14 +183,12 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
                                  unsigned char *rxbuf)
 {
        int iocontrol_code;
+ char tmp_buf[readcnt + writecnt];
        struct spi_ioc_transfer msg[2] = {
                {
                        .tx_buf = (uint64_t)(uintptr_t)txbuf,
- .len = writecnt,
- },
- {
- .rx_buf = (uint64_t)(uintptr_t)rxbuf,
- .len = readcnt,
+ .rx_buf = (uint64_t)(uintptr_t)tmp_buf,
+ .len = writecnt+readcnt,
                },
        };

@@ -203,15 +201,14 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,

/* Just submit the first (write) request in case there is nothing
           to read. Otherwise submit both requests. */
- if (readcnt == 0)
- iocontrol_code = SPI_IOC_MESSAGE(1);
- else
- iocontrol_code = SPI_IOC_MESSAGE(2);
+ iocontrol_code = SPI_IOC_MESSAGE(1);

        if (ioctl(fd, iocontrol_code, msg) == -1) {
                msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno));
                return -1;
        }
+
+ memcpy(rxbuf, tmp_buf + writecnt, readcnt);
        return 0;
 }

-------------------

2) The other issue is that my device appears to want SPI_MODE_1. When I set SPI_MODE_1, it is able to detect and program the board, but fails to verify. The image that gets loaded still works, but I'm unsure of what's causing the issue.

I can do some more debugging, but changing SPI_MODE_1 and applying the above-mentioned patch solves the issue for me.


Sean


_______________________________________________
flashrom mailing list
[email protected]
https://mail.coreboot.org/mailman/listinfo/flashrom

Reply via email to