hw/sd: Fix broken ssi-sd implementation since v9.1.0
cover hw/sd: Fix broken ssi-sd implementation since v9.1.0
The U-Boot community reported a CI failure [1] where the sifive_unleashed target failed to boot from an SD card after upgrading from QEMU v8.2.0 to v9.2.3.
At that time, the issue was traced to commit da954d0e ("hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)") which was introduced in v9.1.0.
Testing with the latest QEMU mainline shows that the problem still persists, although the underlying cause has changed due to refactoring since then.
This series fixes the broken ssi-sd model. After applying these patches, U-Boot successfully boots again on the sifive_unleashed target using QEMU’s sifive_u machine.
[1] https://gitlab.com/qemu-project/qemu/-/issues/2945
Bin Meng (2):
hw/sd: Fix incorrect idle state reporting in R1 response for SPI mode hw/sd: Fix ACMD41 state machine in SPI mode
hw/sd/sd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 hw/sd: Fix incorrect idle state reporting in R1 response for SPI mode
Since commit b66f73a0 ("hw/sd: Add SDHC support for SD card SPI-mode"), the CARD_POWER_UP bit in the OCR register has been set after reset. Therefore, checking this bit against zero in sd_response_r1_make() to determine the card’s idle state is incorrect in SPI mode. As a result, QEMU makes the U-Boot mmc-spi driver believe the card never leaves the reset state.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2945
---
hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/sd/sd.c +1 -2
@@ -789,8 +789,7 @@ static size_t sd_response_size(SDState *sd, sd_rsp_type_t rtype)static void sd_response_r1_make (SDState *sd,uint8_t *response) {if (sd_is_spi (sd)) { - response[0 ] = sd->state == sd_idle_state - && !FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP ); + response[0 ] = sd->state == sd_idle_state; response[0 ] |=FIELD_EX32 (sd->card_status,CSR ,ERASE_RESET ) <<1 ; response[0 ] |=FIELD_EX32 (sd->card_status,CSR ,ILLEGAL_COMMAND ) <<2 ; response[0 ] |=FIELD_EX32 (sd->card_status,CSR ,COM_CRC_ERROR ) <<3 ;
Signature · 1 line
2.34.1
Re: [PATCH 1/2] hw/sd: Fix incorrect idle state reporting in R1 response for SPI mode
Quoted 7 lines · Bin Meng
Since commit
b66f73a0("hw/sd: Add SDHC support for SD card SPI-mode"), theCARD_POWER_UPbit in the OCR register has been set after reset. Therefore, checking this bit against zero insd_response_r1_make()to determine the card’s idle state is incorrect in SPI mode. As a result, QEMU makes the U-Boot mmc-spi driver believe the card never leaves the reset state.
Quoted 8 lines
Fixes 1585ab9f ("hw/sd/sdcard: Fill SPI response bits in card code")Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2945
Reported-by Tom Rini <[email protected]>Signed-off-by Bin Meng <[email protected]>---
hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH 2/2 hw/sd: Fix ACMD41 state machine in SPI mode
In reply to Bin MengIn SPI mode, the ACMD41 argument only defines bit 30 (HCS); all other bits are reserved. The current implementation incorrectly checks the voltage window bits even in SPI mode, preventing the state machine from transitioning to the READY state. As a result, the U-Boot mmc-spi driver falls into an endless CMD55/ACMD41 loop.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2945
---
hw/sd/sd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
hw/sd/sd.c +12 -11
@@ -2289,20 +2289,21 @@ static sd_rsp_type_t sd_cmd_SEND_OP_COND(SDState *sd, SDRequest req) } } -if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { -/* -* We accept any voltage. 10000 V is nothing. -* -* Once we're powered up, we advance straight to ready state -* unless it's an enquiry ACMD41 (bits 23:0 == 0). -*/ - sd->state = sd_ready_state; - } -if (sd_is_spi (sd)) { + sd->state = sd_ready_state;return sd_r1; + }else { +if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { +/* +* We accept any voltage. 10000 V is nothing. +* +* Once we're powered up, we advance straight to ready state +* unless it's an enquiry ACMD41 (bits 23:0 == 0). +*/ + sd->state = sd_ready_state; + } +return sd_r3; } -return sd_r3; }/* ACMD42 */
Signature · 1 line
2.34.1
Re: [PATCH 2/2] hw/sd: Fix ACMD41 state machine in SPI mode
Quoted 7 lines · Bin Meng
In SPI mode, the ACMD41 argument only defines bit 30 (HCS); all other bits are reserved. The current implementation incorrectly checks the voltage window bits even in SPI mode, preventing the state machine from transitioning to the READY state. As a result, the U-Boot mmc-spi driver falls into an endless CMD55/ACMD41 loop.
Fixes 3241a61a ("hw/sd/sdcard: Use complete SEND_OP_COND implementation in SPI mode")
Quoted 8 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2945
Reported-by Tom Rini <[email protected]>Signed-off-by Bin Meng <[email protected]>---
hw/sd/sd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
Hi Bin, Tom,
Quoted 9 lines · Bin Meng
The U-Boot community reported a CI failure [1] where the
sifive_unleashedtarget failed to boot from an SD card after upgrading from QEMU v8.2.0 to v9.2.3.At that time, the issue was traced to commit
da954d0e("hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)") which was introduced in v9.1.0.
Quoted 7 lines
Testing with the latest QEMU mainline shows that the problem still persists, although the underlying cause has changed due to refactoring since then.
This series fixes the broken
ssi-sdmodel. After applying these patches, U-Boot successfully boots again on thesifive_unleashedtarget using QEMU’ssifive_umachine.
Thanks for fixing this issue!
Do you mind adding this test as a functional one, so we get this code path covered?
Quoted 11 lines
[1] https://gitlab.com/qemu-project/qemu/-/issues/2945
Bin Meng (2):
hw/sd: Fix incorrect idle state reporting in R1 response for SPI mode hw/sd: Fix ACMD41 state machine in SPI modehw/sd/sd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
Hi Philippe,
Quoted 17 lines · Philippe Mathieu-Daudé
Hi Bin, Tom,
Quoted 13 lines · Bin Meng
The U-Boot community reported a CI failure [1] where the
sifive_unleashedtarget failed to boot from an SD card after upgrading from QEMU v8.2.0 to v9.2.3.At that time, the issue was traced to commit
da954d0e("hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)") which was introduced in v9.1.0.Testing with the latest QEMU mainline shows that the problem still persists, although the underlying cause has changed due to refactoring since then.
Quoted 9 lines
Quoted 3 lines
This series fixes the broken
ssi-sdmodel. After applying these patches, U-Boot successfully boots again on thesifive_unleashedtarget using QEMU’ssifive_umachine.Thanks for fixing this issue!
Do you mind adding this test as a functional one, so we get this code path covered?
Sure, I will try to add a test in v2.
Regards,
Bin
Quoted 3 lines · Bin Meng
Bin Meng (2):
hw/sd: Fix incorrect idle state reporting in R1 response for SPI mode hw/sd: Fix ACMD41 state machine in SPI mode
Series queued, thanks.
Quoted 13 lines · Bin Meng
The U-Boot community reported a CI failure [1] where the
sifive_unleashedtarget failed to boot from an SD card after upgrading from QEMU v8.2.0 to v9.2.3.At that time, the issue was traced to commit
da954d0e("hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)") which was introduced in v9.1.0.Testing with the latest QEMU mainline shows that the problem still persists, although the underlying cause has changed due to refactoring since then.
Quoted 5 lines
This series fixes the broken
ssi-sdmodel. After applying these patches, U-Boot successfully boots again on thesifive_unleashedtarget using QEMU’ssifive_umachine.
Hi!
This seems to be a qemu-stable material.
The refactoring mentioned above happened between 10.1.0-rc1 and
10.1.0-rc2, which is quite a hot spot for a refactoring. So the
changes are definitely relevant for 10.1.x series, where I applied them already.
But we've 10.0.x series which supposed to be long-term support series, where we have the problem too (since the issue were introduced before 10.0), but the 2 fixes here don't apply to 10.0, obviously, due to refactoring.
Now I wonder should we fix this in 10.0.x at all, should we create some unique fix for 10.0.x, or should we pick the refactoring done in 10.1.0-rc stage, to 10.0.x?
This is the original refactoring patchset:
https://lore.kernel.org/qemu-devel/[email protected]/
The patchset applies cleanly to 10.0.x, with these 2 fixes on top, and the resulting thing seem to work fine, so far anyway:
https://gitlab.com/mjt0k/qemu/-/commits/10.0-sdcard
(and with local tests, including the test in the above series).
What do you think? How important it is to make this whole thing work in 10.0.x lts series (including distribution(s) based on this, such as current debian stable "trixie")?
Thanks,
/mjt
On 11/19/25 13:44, Michael Tokarev wrote:
...
Quoted 11 lines
This is the original refactoring patchset:
https://lore.kernel.org/qemu-devel/20250804133406.17456-1- [email protected]/The patchset applies cleanly to 10.0.x, with these 2 fixes on top, and the resulting thing seem to work fine, so far anyway:
https://gitlab.com/mjt0k/qemu/-/commits/10.0-sdcard
(and with local tests, including the test in the above series).What do you think? How important it is to make this whole thing work in 10.0.x lts series (including distribution(s) based on this, such as current debian stable "trixie")?
And I already considered picking this patchset to 10.0.x, see
https://lore.kernel.org/qemu-devel/[email protected]/
and the reply to its message :)
Thanks,
/mjt
Quoted 41 lines · Michael Tokarev
Quoted 13 lines · Bin Meng
The U-Boot community reported a CI failure [1] where the
sifive_unleashedtarget failed to boot from an SD card after upgrading from QEMU v8.2.0 to v9.2.3.At that time, the issue was traced to commit
da954d0e("hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)") which was introduced in v9.1.0.Testing with the latest QEMU mainline shows that the problem still persists, although the underlying cause has changed due to refactoring since then.
Quoted 5 lines
This series fixes the broken
ssi-sdmodel. After applying these patches, U-Boot successfully boots again on thesifive_unleashedtarget using QEMU’ssifive_umachine.Hi!
This seems to be a qemu-stable material.
The refactoring mentioned above happened between 10.1.0-rc1 and
10.1.0-rc2, which is quite a hot spot for a refactoring. So the
changes are definitely relevant for 10.1.x series, where I applied them already.But we've 10.0.x series which supposed to be long-term support series, where we have the problem too (since the issue were introduced before 10.0), but the 2 fixes here don't apply to 10.0, obviously, due to refactoring.
Now I wonder should we fix this in 10.0.x at all, should we create some unique fix for 10.0.x, or should we pick the refactoring done in 10.1.0-rc stage, to 10.0.x?
This is the original refactoring patchset:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 8 lines
The patchset applies cleanly to 10.0.x, with these 2 fixes on top, and the resulting thing seem to work fine, so far anyway:
https://gitlab.com/mjt0k/qemu/-/commits/10.0-sdcard
(and with local tests, including the test in the above series).What do you think? How important it is to make this whole thing work in 10.0.x lts series (including distribution(s) based on this, such as current debian stable "trixie")?
With my U-Boot hat on (which is where we found the issue), it's not critical. I need to get us in the habit of "do a release, upgrade ancillary tooling we test too" so that we find potential problems like this much quicker. We should be, but aren't, on 10.1.x already for v2026.04 and on 10.0.6 not 10.0.2 for v2026.01.
Signature · 1 line
Tom