Skip to contentSkip to conversation

hw/sd/ssi-sd: Return noise (dummy byte) when no card connected

PATCH Superseded Philippe Mathieu-Daudé 1 participant 2 messages Aug 12, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover hw/sd/ssi-sd: Return noise (dummy byte) when no card connected

Trivial fix for the issue reported by Guenter here:
https://lore.kernel.org/qemu-devel/[email protected]/

- Return dummy byte when no card is connected
- Add a test
- Document ssi_transfer()

Since v1:
- Reworded patch #1 description (Alex)
- Removed '_' test method prefix (Alex)

Philippe Mathieu-Daudé (3):
hw/sd/ssi-sd: Return noise (dummy byte) when no card connected tests/functional: Test SPI-SD adapter without SD card connected hw/ssi: Document ssi_transfer() method

 include/hw/ssi/ssi.h                      | 14 ++++++++++++++
 hw/sd/ssi-sd.c                            |  4 ++++
 tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 1/3 hw/sd/ssi-sd: Return noise (dummy byte) when no card connected

Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card code") exposed a bug in the SPI adapter: if no SD card is plugged, we are returning "there is a card with an error". This is wrong, we shouldn't return any particular packet response, but the noise shifted on the MISO line. Return the dummy byte, otherwise we get:

qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed.

Fixes 775616c3ae8 ("Partial SD card SPI mode support")
---
 hw/sd/ssi-sd.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/sd/ssi-sd.c +4 -0
index 594dead19ee..3aacbd03871 100644
@@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
     SDRequest request;
     uint8_t longresp[5];
 
+    if (!sdbus_get_inserted(&s->sdbus)) {
+        return SSI_DUMMY;
+    }
+
     /*
      * Special case: allow CMD12 (STOP TRANSMISSION) while reading data.
      *
Signature · 1 line
2.49.0