6
votes

Goal: emulate the "sabrelite : Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)" that Qemu specifically supports (doing 'qemu-system-arm -M ?' it shows up).

Qemu ver: 2.10.1 (host: fedora-27).

I have successfully cross-compiled and built a 4.1.46 Linux kernel (used the imx_v6_v7_defconfig config file) as well as a simple "skeleton" root filesystem (busybox-based). (FYI, I have a similar working setup for the ARM Cortex-A9 Versatile Express platform - I do this using my own home-spun embedded Linux system called SEALS).

Looking at the U-Boot config file used by similar boards, I figured to use 'root=/dev/mmcblk0p0' as the root= param for the kernel. So, to try it out I then run qemu as follows (pl scroll horizontally as well to see):

qemu-system-arm -m 512 -M sabrelite -kernel zImage -drive file=rfs.img,format=raw -append "console=ttymxc0 rootfstype=ext4 root=/dev/mmcblk0p0 rw rootwait init=/sbin/init " -nographic -dtb imx6dl-sabresd.dtb

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.1.46 (kai@klaptop) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29) ) #2 SMP Mon Nov 27 17:16:22 IST 2017
[    0.000000] CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine model: Freescale i.MX6 DualLite SABRE Smart Device Board
[    0.000000] cma: Reserved 16 MiB at 0x2f000000

[...]

So it starts to boot up just fine. But then:

[...]
[    2.210965] /soc/aips-bus@02100000/usdhc@02194000: voltage-ranges unspecified
[    2.211796] sdhci-esdhc-imx 2194000.usdhc: Got CD GPIO
[    2.212199] sdhci-esdhc-imx 2194000.usdhc: Got WP GPIO
[    2.214392] sdhci-esdhc-imx 2194000.usdhc: could not get ultra high speed state, work on normal mode
[    2.218084] sdhci-esdhc-imx 2194000.usdhc: No vmmc regulator found
[    2.218367] sdhci-esdhc-imx 2194000.usdhc: No vqmmc regulator found
[    2.265431] mmc0: SDHCI controller on 2194000.usdhc [2194000.usdhc] using ADMA
[    2.267300] mmc0: mmc_rescan_try_freq: trying to init card at 400000 Hz
[    2.281912] /soc/aips-bus@02100000/usdhc@02198000: voltage-ranges unspecified
[    2.282956] sdhci-esdhc-imx 2198000.usdhc: Got CD GPIO
[    2.283703] sdhci-esdhc-imx 2198000.usdhc: Got WP GPIO
[    2.284044] sdhci-esdhc-imx 2198000.usdhc: could not get ultra high speed state, work on normal mode
[    2.284892] sdhci-esdhc-imx 2198000.usdhc: No vmmc regulator found
[    2.285167] sdhci-esdhc-imx 2198000.usdhc: No vqmmc regulator found
[    2.298029] mmc0: mmc_rescan_try_freq: trying to init card at 300000 Hz
[    2.337904] mmc1: SDHCI controller on 2198000.usdhc [2198000.usdhc] using ADMA
[    2.357051] /soc/aips-bus@02100000/usdhc@0219c000: voltage-ranges unspecified
[    2.358313] sdhci-esdhc-imx 219c000.usdhc: No vmmc regulator found
[    2.358642] sdhci-esdhc-imx 219c000.usdhc: No vqmmc regulator found
[    2.368204] mmc0: mmc_rescan_try_freq: trying to init card at 200000 Hz
[    2.414722] mmc2: SDHCI controller on 219c000.usdhc [219c000.usdhc] using ADMA
[    2.440456] mmc0: mmc_rescan_try_freq: trying to init card at 100000 Hz

[...]

[    2.986441]   No soundcards found.
[    3.007698] Waiting for root device /dev/mmcblk0p0...

Keeps waiting forever here ...

I understand that, on an actual physical board, one would have to "format" or partition the MMC (or SD) card, and have u-boot load up the kernel and rootfs into RAM. But am currently interested in getting the IMX6 working on Qemu... So, my actual question: how can I get the root filesystem mounted and operational on Qemu? Any help appreciated! TIA,

1

1 Answers

7
votes

There are two problems here. Firstly, your command line isn't actually creating an SD card: the -drive option creates a drive object but doesn't try to plug it in anywhere (because the sabrelite board doesn't define a "default kind of block drive"). To actually plug in the drive to an emulated sd card you need

-drive file=yourfile.img,format=raw,id=mycard -device sd-card,drive=mycard

Secondly, there are bugs in QEMU's current imx6 sd controller emulation, because if you do that then the guest kernel continuously prints

[   28.971663] mmc1: Timeout waiting for hardware interrupt.
[   28.973619] mmc1: error -110 whilst initialising SD card

...so it has found the emulated card but isn't getting an interrupt it expects.

These can be fixed by a patch currently on the qemu-devel mailing lists and going through code review: http://patchwork.ozlabs.org/patch/834805/ plus a simple change to hw/arm/fsl-imx6.c to make it create TYPE_IMX_USDHC devices rather than TYPE_SYSBUS_SDHCI. (Basically the imx6's SD controller isn't a completely standard compatible sdhci controller but what we were creating in the QEMU model was the plain variety.)

If you do all that then you can boot a kernel that can see the mmc card:

[    8.878283] mmc1: new SD card at address 4567
[    8.910566] mmcblk0: mmc1:4567 QEMU! 256 MiB 

With a little luck we'll be able to have this fixed in the 2.12 release of QEMU, which will be out in some time in spring 2018.

Edit as of 9 Mar 2018 -- the relevant fixes are now in QEMU master (commits fd1e5c81796, df2a5cf4c8) and will be in 2.12.