Skip to contentSkip to conversation

SD/MMC patches for 2025-08-12

GIT PULL Applied Philippe Mathieu-Daudé 3 participants 6 messages Aug 12, 2025 – Aug 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 624d7463043c120facfab2b54985fcfb679d5379:

Merge tag 'pull-nvme-20250811' of https://gitlab.com/birkelund/qemu into staging (2025-08-11 12:57:55 -0400)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/sdmmc-20250812

for you to fetch changes up to 7db162fa013878b06a528686ece79ad99f699c71:

tests/functional: Test SPI-SD adapter without SD card connected (2025-08-12 18:52:12 +0200)

----------------------------------------------------------------
SD/MMC patches queue

- Return noise (dummy byte) when no SD card connected over SPI

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

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

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

[PULL 1/2] 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.

Message-Id: <[email protected]>

---
 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
#2 lore raw

Re: [PULL 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected

Quoted 8 lines · Philippe Mathieu-Daudé

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.
Quoted 7 lines

While the commit which exposed the bug is in 10.1, it looks to me like this is a qemu-stable material (7.2 & 10.0), because the bug is there, it just does not result in qemu assertion failure. Please let me know if it is not.

Thanks,

/mjt

#3 lore raw

Re: [PULL 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected

Quoted 17 lines · Michael Tokarev
Quoted 8 lines · Philippe Mathieu-Daudé

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.

Quoted 7 lines
Quoted 4 lines

While the commit which exposed the bug is in 10.1, it looks to me like this is a qemu-stable material (7.2 & 10.0), because the bug is there, it just does not result in qemu assertion failure.  Please let me know if it is not.

You are correct!

#4 lore raw

[PULL 2/2] tests/functional: Test SPI-SD adapter without SD card connected

In reply to Philippe Mathieu-Daudé

SPI-SD adapter should be usable, even without any SD card wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it more generic and add another test, inspired by this report:
https://lore.kernel.org/qemu-devel/[email protected]/

Message-Id: <[email protected]>

---
 tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
tests/functional/test_riscv64_sifive_u.py +17 -5
index dc4cb8a4a96..358ff0d1f60 100755
@@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest):
          'rootfs.ext2.gz'),
         'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b')
 
-    def test_riscv64_sifive_u_mmc_spi(self):
+    def do_test_riscv64_sifive_u_mmc_spi(self, connect_card):
         self.set_machine('sifive_u')
         kernel_path = self.ASSET_KERNEL.fetch()
         rootfs_path = self.uncompress(self.ASSET_ROOTFS)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
-                               'root=/dev/mmcblk0 rootwait '
                                'earlycon=sbi console=ttySIF0 '
-                               'panic=-1 noreboot')
+                               'root=/dev/mmcblk0 ')
         self.vm.add_args('-kernel', kernel_path,
-                         '-drive', f'file={rootfs_path},if=sd,format=raw',
                          '-append', kernel_command_line,
                          '-no-reboot')
+        if connect_card:
+            kernel_command_line += 'panic=-1 noreboot rootwait '
+            self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw')
+            pattern = 'Boot successful.'
+        else:
+            kernel_command_line += 'panic=0 noreboot '
+            pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)'
+
         self.vm.launch()
-        self.wait_for_console_pattern('Boot successful.')
+        self.wait_for_console_pattern(pattern)
 
         os.remove(rootfs_path)
 
+    def test_riscv64_sifive_u_nommc_spi(self):
+        self.do_test_riscv64_sifive_u_mmc_spi(False)
+
+    def test_riscv64_sifive_u_mmc_spi(self):
+        self.do_test_riscv64_sifive_u_mmc_spi(True)
+
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.49.0