From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 2/2] mci: wait for card to leave programming state after block writes
Date: Mon, 19 Oct 2026 11:52:44 +0200 [thread overview]
Message-ID: <20261019-atmel-mci-fixes-v1-2-6a636f3b28ca@pengutronix.de> (raw)
In-Reply-To: <20261019-atmel-mci-fixes-v1-0-6a636f3b28ca@pengutronix.de>
Commit d8c3bab30542 ("mci: only write blocks when card out of programming
mode") polls the card status before a block write, so that CMD24/25 is
not sent while the card is still programming the previous write. Reads
are not covered: a read following a write can still find the card in
prg state. CMD17/18 are illegal there and the card does not answer
them, so the host sees a response timeout.
On a KSZ9477-EVB (SAMA5D3) with a freshly flashed SD card, the first
saveenv fails with:
ERROR: atmel_mci f0000000.mmc@f0000000.of: command/data timeout
ERROR: atmel_mci f0000000.mmc@f0000000.of: command/data timeout
With more verbose error reporting, the failing commands turn out to be
a multi-block read and the stop command sent after it:
CMD18: response timeout (SR=0x04100005)
CMD12: response timeout (SR=0x04100005)
The same happens without any filesystem involved when writing larger
amounts of data to the raw device:
memcpy -s /dev/ram0 -d /dev/mmc0.root-A 0 0 2M
Also poll the card status after each block write, like U-Boot does, so
that any command following a write finds the card back in transfer
state.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mci/mci-core.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 874ee40cb3..1954de8053 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -266,7 +266,7 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
{
struct mci_cmd cmd = {};
unsigned mmccmd;
- int ret;
+ int ret, err;
/*
* Quoting eMMC Spec v5.1 (JEDEC Standard No. 84-B51):
@@ -304,6 +304,15 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
mci_send_cmd(mci, &cmd);
}
+ /*
+ * The card stays in prg state for a while after the write. Polling
+ * before the next write is not enough: a read sent in prg state is
+ * an illegal command, which the card does not answer at all.
+ */
+ err = mci_poll_until_ready(mci, 1000 /* ms */);
+ if (!ret && err != -ENOSYS)
+ ret = err;
+
return ret;
}
--
2.47.3
next prev parent reply other threads:[~2026-10-19 9:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 9:52 [PATCH 0/2] mci: fix read timeouts following SD card writes Sascha Hauer
2026-10-19 9:52 ` [PATCH 1/2] mci: atmel_mci: improve timeout error message Sascha Hauer
2026-10-19 9:52 ` Sascha Hauer [this message]
2026-10-19 11:44 ` [PATCH 0/2] mci: fix read timeouts following SD card writes Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019-atmel-mci-fixes-v1-2-6a636f3b28ca@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox