From b01741cbb12db9bf484df3c62e6414268b4e40cc Mon Sep 17 00:00:00 2001 From: consts Date: Fri, 2 Mar 2018 07:03:37 +0000 Subject: [PATCH 1/1] spi: keep CS hot before sending a command Merge note (from committer, Leah Rowe): In the normal command loop, some flash ICs might briefly become unresponsive and thus the flash will fail. This is mitigated by spamming non-operation to keep the flash alive. This is required for stability on some flash ICs, or the flash will fail completely. This does have a minor impact on speed, but not enough to warrant making it a toggle. This does not hurt operation on more stable ICs, so it makes sense to enable this behaviour myself. I've adapted this patch from the one I sent flashprog, which is based on the patch that was sent to be by consts on 2 March 2018. Without this patch, coreboot-based projects may often receive complaints from users about flashing issues that are mitigated most of the time by enabling the behaviour in this patch. This should be merged for that reason. Note that this does not mean anything for internal flashing, but it makes external flashing much more reliable. On some flash ICs, flashing won't even work at all without this patch, depending on the mainboard. This was originally written for users flashing coreboot on the Lenovo ThinkPad X200, but I have since seen the same issue fixed by this patch appear on many other boards, on various flash ICs. Thus, this patch version hardcodes the new behaviour. Signed-off-by: Leah Rowe --- spi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spi.c b/spi.c index 67a081ab..4df9d614 100644 --- a/spi.c +++ b/spi.c @@ -54,8 +54,16 @@ int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) { - if (flash->mst->spi.command) + if (flash->mst->spi.command) { return flash->mst->spi.command(flash, writecnt, readcnt, writearr, readarr); + } else { + const unsigned char cmd[JEDEC_READ_OUTSIZE] = {JEDEC_READ, 0, 0, 0}; + unsigned char buf[256]; + /* keep the flash busy (keep CS hot) before sending a command, needed + * for stability on some ICs or else read/write will fail. + */ + default_spi_send_command(flash, sizeof(cmd), sizeof(buf), cmd, buf); + } return default_spi_send_command(flash, writecnt, readcnt, writearr, readarr); } -- 2.47.3