controllerqemusd-cardbus

QEMU: How to connect a SD card to a specific controller?


I want to connect a SD card to the first SD controller of an i.MX6 SoC (the one with base address 0x2190000). However QEMU defaults to adding it to the third controller (tested with version 4.2 and 5.1).

QEMU arguments:

qemu-system-arm -m 2G -M sabrelite -kernel zImage \
-drive file=img.sdcard,format=raw,id=mysdcard \
-device sd-card,drive=mysdcard \
-append "console=ttymxc0, rootfstype=ext4 root=/dev/mmcblk0p2 rw rootwait" \
-dtb mydtb.dtb -serial stdio

Output of "info qtree":

  dev: imx-usdhc, id ""
    gpio-out "sysbus-irq" 1
    sd-spec-version = 3 (0x3)
    uhs = 0 (0x0)
    capareg = 91763892 (0x57834b4)
    maxcurr = 0 (0x0)
    pending-insert-quirk = false
    dma = ""
    mmio 000000000219c000/0000000000000100
    bus: sd-bus
      type sdhci-bus
      dev: sd-card, id ""       <-- I do not want the SD card to appear here
        spec_version = 2 (0x2)
        drive = "mysdcard"
        spi = false
  dev: imx-usdhc, id ""
    [...]
  dev: imx-usdhc, id ""
    [...]
  dev: imx-usdhc, id ""
    gpio-out "sysbus-irq" 1
    sd-spec-version = 3 (0x3)
    uhs = 0 (0x0)
    capareg = 91763892 (0x57834b4)
    maxcurr = 0 (0x0)
    pending-insert-quirk = false
    dma = ""
    mmio 0000000002190000/0000000000000100
    bus: sd-bus
      type sdhci-bus           <-- This is where the card needs to be

I wanted to specify the id of the controller, but all imx-usdhc have an empty string as id.

So how can I specify which controller to use (or at least tell QEMU to default to the first one)?


Solution

  • This ought to be possible, but currently it is not, due to a bug/missing feature in QEMU. This was reported here: https://bugs.launchpad.net/qemu/+bug/1895895 and there is mailing list discussion of it here: https://lore.kernel.org/qemu-devel/CAFEAcA_PFGc2Ka-egqYqzMq0Nu_aRiNUPif0yntg4L56UTi7MQ@mail.gmail.com/ but nobody has yet got round to writing the (fairly small) patch to implement the fix.

    In summary, the SoC device object in QEMU for the imx6 SoC should create aliased "sd-bus0", "sd-bus1", etc for the 4 controllers. Then on the command line you would be able to add ",bus=sd-bus2" to the -device sd-card option to tell QEMU which specific bus to plug it into. At the moment that doesn't work because all the sd-buses have the same name.