qapi-schema.json | 41 ++++ hw/sd/core.c | 43 ++++ hw/sd/sd.c | 519 +++++++++++++++++++++++++++++++------------------ stubs/qmp_sdbus.c | 11 ++ hw/sd/trace-events | 17 ++ stubs/Makefile.objs | 1 + tests/Makefile.include | 2 + tests/sdcard_tests.py | 172 ++++++++++++++++ 8 files changed, 617 insertions(+), 189 deletions(-) create mode 100644 stubs/qmp_sdbus.c create mode 100755 tests/sdcard_tests.py
Now that we have a way to write qtest in Python, lets start with a simple test to perform basic card identification, covering many functions of the sd/sd.c file. [patch 1] When a device is not MMIO-connected but rather plugged into a Bus, it is easier to write tests using QMP. So we add a 'sdbus-command' entry to directly operate on a SD Bus. (Note this method should also work with all other QBus). [patch 2] We write a simple pyqtest, which - resolve the SDBus QOM path in the test setup() - verify default values for SD Spec v2. Since have a test, lets run after each patch, so we are sure we don't break things. [patch 4-14,20-23] Add a bunch of trace events [patch 3,11,15-18] Aesthetic changes mostly [other patches] Trivial changes Once this series applied, booting some Linux on a vexpress-a9 with few sd*command traces enabled result in this outputs (which result useful to understand/fix the different SD implementations): 48.687227:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x00000c00 (state idle) 48.687233:sdcard_command_response (no response) (state idle) 48.689237:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x80000c08 (state idle) 48.689244:sdcard_command_response (no response) (state idle) 48.690877:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) 48.690890:sdcard_command_response (no response) (state idle) 48.723486:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) 48.723507:sdcard_command_response 00 00 01 aa (state idle) 48.723886:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 48.723892:sdcard_command_response (no response) (state idle) 48.724019:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 48.724023:sdcard_command_response (no response) (state idle) 48.724110:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 48.724115:sdcard_command_response (no response) (state idle) 48.724178:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 48.724181:sdcard_command_response (no response) (state idle) 48.724999:sdcard_command_response 00 40 01 20 (state idle) 48.725214:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x00000000 (state idle) 48.725225:sdcard_command_response 40 ff ff 00 (state idle) 48.727113:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) 48.727125:sdcard_command_response (no response) (state idle) 48.729206:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) 48.729213:sdcard_command_response 00 00 01 aa (state idle) 48.729339:sdcard_command_response 00 00 01 20 (state idle) 48.729412:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x40300000 (state idle) 48.729419:sdcard_command_response c0 ff ff 00 (state ready) 48.729786:sdcard_normal_command ALL_SEND_CID/ CMD02 arg 0x00000000 (state ready) 48.729797:sdcard_command_response aa 58 59 51 45 4d 55 21 01 de ad be ef 00 62 19 (state identification) 48.730825:sdcard_normal_command SEND_RELATIVE_ADDR/ CMD03 arg 0x00000000 (state identification) 48.730835:sdcard_command_response 45 67 05 00 (state standby) 48.731221:sdcard_normal_command SEND_CSD/ CMD09 arg 0x45670000 (state standby) 48.731228:sdcard_command_response 40 0e 00 32 5b 59 00 00 0d 47 7f 80 0a 40 00 00 (state standby) 48.732012:sdcard_normal_command SELECT/DESELECT_CARD/ CMD07 arg 0x45670000 (state standby) 48.732021:sdcard_command_response 00 00 07 00 (state transfer) 48.732419:sdcard_command_response 00 00 09 20 (state transfer) 48.764983:sdcard_app_command SEND_SCR/ACMD51 arg 0x00000000 (state transfer) 48.765000:sdcard_command_response 00 00 09 20 (state sendingdata) 48.766951:sdcard_command_response 00 00 09 20 (state transfer) 48.767159:sdcard_app_command SD_STATUS/ACMD13 arg 0x00000000 (state transfer) 48.767168:sdcard_command_response 00 00 09 20 (state sendingdata) 48.966731:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00000000 (state transfer) 48.966763:sdcard_command_response 00 00 09 00 (state sendingdata) 48.974869:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 48.974877:sdcard_command_response 00 00 0b 00 (state transfer) 50.044308:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 50.044330:sdcard_command_response 00 00 09 00 (state transfer) [...] Regards, Phil. Based-on: 20171213213557.26561-7-f4bug@amsat.org (QTests: use Python to run complex tests) Philippe Mathieu-Daudé (26): sdbus: add a QMP command to access a SDBus sdcard: add Python qtests sdcard: use ldst API sdcard: replace fprintf() -> qemu_log_mask() sdcard: rename sd_set_mode() -> sd_update_mode() sdcard: add sd_set_mode() sdcard: add sdcard_set_mode() trace event sdcard: add sd_set_state() sdcard: add a sdcard_set_state() trace event sdcard: use more detailled state/mode trace events sdcard: use warn_report() instead of fprintf() sdcard: replace DPRINTF() by trace events sdcard: add more trace events sdcard: use qemu_hexbuf_strdup() to trace command response sdcard: use PW_LEN define instead of '16' magic sdcard: let cmd_valid_while_locked() returns a bool sdcard: rename sd_set_REG() functions called by sd_reset() as sd_reset_REG() sdcard: move Memory Card registers together sdcard: add DSR register sdcard: add/use SD_CMD_MAX to check valid SD commands sdcard: add sd_cmd_abbreviation() to resolve the SD command id sdcard: reduce sd_cmd traces sdcard: add ACMD trace events sdcard: use a 16-bit type for the 16-bit RCA register sdcard: add/use a SDCardCommandClass enum instead of magic numbers sdcard: add/use a ccc_spi enum for the commands supported in SPI mode qapi-schema.json | 41 ++++ hw/sd/core.c | 43 ++++ hw/sd/sd.c | 519 +++++++++++++++++++++++++++++++------------------ stubs/qmp_sdbus.c | 11 ++ hw/sd/trace-events | 17 ++ stubs/Makefile.objs | 1 + tests/Makefile.include | 2 + tests/sdcard_tests.py | 172 ++++++++++++++++ 8 files changed, 617 insertions(+), 189 deletions(-) create mode 100644 stubs/qmp_sdbus.c create mode 100755 tests/sdcard_tests.py -- 2.15.1
attaching a more complete boot log. > Once this series applied, booting some Linux on a vexpress-a9 with few > sd*command traces enabled result in this outputs (which result useful to > understand/fix the different SD implementations): $ cat /tmp/events sd*command* sdcard_set_mode sdcard_read_block $ qemu-system-arm \ -M vexpress-a9 \ -kernel vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress \ -drive if=sd,cache=unsafe,file=a10-debian-server-2gb.2014-02-17.img \ -append "root=/dev/mmcblk0p2 console=ttyAMA0 console=tty" -nographic \ -trace events=/tmp/events Uncompressing Linux... done, booting the kernel. [ 0.000000] Booting Linux on physical CPU 0 [ 0.000000] Linux version 3.2.0-4-vexpress (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-12) ) #1 SMP Debian 3.2.35-2 [ 0.000000] CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d [ 0.000000] Machine: ARM-Versatile Express [ 0.000000] Kernel command line: root=/dev/mmcblk0p2 console=ttyAMA0 console=tty [ 0.000000] Memory: 128MB = 128MB total [ 0.000000] Console: colour dummy device 80x30 [ 0.000000] console [tty0] enabled [ 0.319496] Brought up 1 CPUs [ 0.319905] SMP: Total of 1 processors activated (617.67 BogoMIPS). [ 0.444966] Serial: AMBA PL011 UART driver [ 0.450544] mb:uart0: ttyAMA0 at MMIO 0x10009000 (irq = 37) is a PL011 rev1 [ 0.481078] console [ttyAMA0] enabled [ 3.081225] mmci-pl18x mb:mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 41,42 (pio) 86.660802:sdcard_set_mode inactive -> card_identification (state: idle) 86.660815:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x00000c00 (state idle) 86.660829:sdcard_command_response (no response) (state idle) 86.689998:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x80000c08 (state idle) 86.690014:sdcard_command_response (no response) (state idle) 86.692380:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) 86.692392:sdcard_command_response (no response) (state idle) 86.695229:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) 86.695247:sdcard_command_response 00 00 01 aa (state idle) 86.695887:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 86.695898:sdcard_command_response (no response) (state idle) 86.696065:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 86.696072:sdcard_command_response (no response) (state idle) 86.696198:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 86.696207:sdcard_command_response (no response) (state idle) 86.696311:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) 86.696320:sdcard_command_response (no response) (state idle) [ 3.298428] mmc0: host does not support reading read-only switch. assuming write-enable. 86.697384:sdcard_command_response 00 40 01 20 (state idle) 86.697639:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x00000000 (state idle) 86.697656:sdcard_command_response 40 ff ff 00 (state idle) 86.699975:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) 86.700000:sdcard_command_response (no response) (state idle) 86.732420:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) 86.732460:sdcard_command_response 00 00 01 aa (state idle) 86.732700:sdcard_command_response 00 00 01 20 (state idle) 86.732812:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x40300000 (state idle) 86.732825:sdcard_command_response c0 ff ff 00 (state ready) 86.733272:sdcard_normal_command ALL_SEND_CID/ CMD02 arg 0x00000000 (state ready) 86.733307:sdcard_command_response aa 58 59 51 45 4d 55 21 01 de ad be ef 00 62 19 (state identification) 86.734086:sdcard_normal_command SEND_RELATIVE_ADDR/ CMD03 arg 0x00000000 (state identification) 86.734107:sdcard_command_response 45 67 05 00 (state standby) 86.734573:sdcard_set_mode card_identification -> data_transfer (state: standby) 86.734580:sdcard_normal_command SEND_CSD/ CMD09 arg 0x45670000 (state standby) 86.734593:sdcard_command_response 40 0e 00 32 5b 59 00 00 0d 47 7f 80 0a 40 00 00 (state standby) 86.735447:sdcard_normal_command SELECT/DESELECT_CARD/ CMD07 arg 0x45670000 (state standby) 86.735462:sdcard_command_response 00 00 07 00 (state transfer) 86.735917:sdcard_command_response 00 00 09 20 (state transfer) 86.737808:sdcard_app_command SEND_SCR/ACMD51 arg 0x00000000 (state transfer) 86.737818:sdcard_command_response 00 00 09 20 (state sendingdata) 86.739778:sdcard_command_response 00 00 09 20 (state transfer) 86.740004:sdcard_app_command SD_STATUS/ACMD13 arg 0x00000000 (state transfer) 86.740011:sdcard_command_response 00 00 09 20 (state sendingdata) [ 3.319526] mmc0: new SDHC card at address 4567 [ 3.401452] mmcblk0: mmc0:4567 QEMU! 1.66 GiB 86.939168:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00000000 (state transfer) 86.939198:sdcard_command_response 00 00 09 00 (state sendingdata) 86.939201:sdcard_read_block addr 0x00000000 size 0x200 86.939768:sdcard_read_block addr 0x00000200 size 0x200 86.940137:sdcard_read_block addr 0x00000400 size 0x200 86.940549:sdcard_read_block addr 0x00000600 size 0x200 86.940918:sdcard_read_block addr 0x00000800 size 0x200 86.941506:sdcard_read_block addr 0x00000a00 size 0x200 86.941796:sdcard_read_block addr 0x00000c00 size 0x200 86.942080:sdcard_read_block addr 0x00000e00 size 0x200 86.942451:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 86.942463:sdcard_command_response 00 00 0b 00 (state transfer) [ 3.522382] mmcblk0: p1 p2 88.022437:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 88.022459:sdcard_command_response 00 00 09 00 (state transfer) 89.025296:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 89.025315:sdcard_command_response 00 00 09 00 (state transfer) [ 5.777261] udevd[45]: starting version 175 90.032049:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 90.032069:sdcard_command_response 00 00 09 00 (state transfer) 91.032126:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 91.032148:sdcard_command_response 00 00 09 00 (state transfer) 91.854517:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00351f80 (state transfer) 91.854547:sdcard_command_response 00 00 09 00 (state sendingdata) 91.854550:sdcard_read_block addr 0x6a3f0000 size 0x200 91.856100:sdcard_read_block addr 0x6a3f0200 size 0x200 91.856393:sdcard_read_block addr 0x6a3f0400 size 0x200 91.856692:sdcard_read_block addr 0x6a3f0600 size 0x200 91.857342:sdcard_read_block addr 0x6a3f0800 size 0x200 91.857652:sdcard_read_block addr 0x6a3f0a00 size 0x200 91.857955:sdcard_read_block addr 0x6a3f0c00 size 0x200 91.858256:sdcard_read_block addr 0x6a3f0e00 size 0x200 91.858979:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 91.858990:sdcard_command_response 00 00 0b 00 (state transfer) 92.003670:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00351ff0 (state transfer) 92.003692:sdcard_command_response 00 00 09 00 (state sendingdata) 92.003696:sdcard_read_block addr 0x6a3fe000 size 0x200 92.004126:sdcard_read_block addr 0x6a3fe200 size 0x200 92.004418:sdcard_read_block addr 0x6a3fe400 size 0x200 92.004704:sdcard_read_block addr 0x6a3fe600 size 0x200 92.005011:sdcard_read_block addr 0x6a3fe800 size 0x200 92.005313:sdcard_read_block addr 0x6a3fea00 size 0x200 92.005665:sdcard_read_block addr 0x6a3fec00 size 0x200 92.006023:sdcard_read_block addr 0x6a3fee00 size 0x200 92.006466:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 92.006481:sdcard_command_response 00 00 0b 00 (state transfer) 92.022454:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00000000 (state transfer) 92.022488:sdcard_command_response 00 00 09 00 (state sendingdata) 92.022497:sdcard_read_block addr 0x00000000 size 0x200 92.023021:sdcard_read_block addr 0x00000200 size 0x200 92.023436:sdcard_read_block addr 0x00000400 size 0x200 92.023841:sdcard_read_block addr 0x00000600 size 0x200 92.024179:sdcard_read_block addr 0x00000800 size 0x200 92.024555:sdcard_read_block addr 0x00000a00 size 0x200 92.024849:sdcard_read_block addr 0x00000c00 size 0x200 92.025151:sdcard_read_block addr 0x00000e00 size 0x200 92.025507:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 92.025518:sdcard_command_response 00 00 0b 00 (state transfer) 92.043359:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) 92.043403:sdcard_command_response 00 00 09 00 (state transfer) 92.071967:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00000008 (state transfer) 92.072003:sdcard_command_response 00 00 09 00 (state sendingdata) 92.072008:sdcard_read_block addr 0x00001000 size 0x200 92.072429:sdcard_read_block addr 0x00001200 size 0x200 92.072763:sdcard_read_block addr 0x00001400 size 0x200 92.073064:sdcard_read_block addr 0x00001600 size 0x200 92.073383:sdcard_read_block addr 0x00001800 size 0x200 92.073670:sdcard_read_block addr 0x00001a00 size 0x200 92.073949:sdcard_read_block addr 0x00001c00 size 0x200 92.074224:sdcard_read_block addr 0x00001e00 size 0x200 92.074552:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) 92.074562:sdcard_command_response 00 00 0b 00 (state transfer) 92.093569:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00351ff8 (state transfer) 92.093590:sdcard_command_response 00 00 09 00 (state sendingdata) 92.093596:sdcard_read_block addr 0x6a3ff000 size 0x200 92.093994:sdcard_read_block addr 0x6a3ff200 size 0x200 92.094281:sdcard_read_block addr 0x6a3ff400 size 0x200 92.094568:sdcard_read_block addr 0x6a3ff600 size 0x200 92.094843:sdcard_read_block addr 0x6a3ff800 size 0x200 92.095118:sdcard_read_block addr 0x6a3ffa00 size 0x200 92.095389:sdcard_read_block addr 0x6a3ffc00 size 0x200 92.095654:sdcard_read_block addr 0x6a3ffe00 size 0x200 qemu-system-arm: terminating on signal 15 from pid 12630 (killall)
On Wed, Dec 13, 2017 at 3:19 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > Now that we have a way to write qtest in Python, lets start with a simple test > to perform basic card identification, covering many functions of the sd/sd.c > file. > > [patch 1] > When a device is not MMIO-connected but rather plugged into a Bus, it is easier > to write tests using QMP. > So we add a 'sdbus-command' entry to directly operate on a SD Bus. > (Note this method should also work with all other QBus). > > [patch 2] > We write a simple pyqtest, which > - resolve the SDBus QOM path in the test setup() > - verify default values for SD Spec v2. > > Since have a test, lets run after each patch, so we are sure we don't break things. > > [patch 4-14,20-23] > Add a bunch of trace events > [patch 3,11,15-18] > Aesthetic changes mostly > [other patches] > Trivial changes > > Once this series applied, booting some Linux on a vexpress-a9 with few > sd*command traces enabled result in this outputs (which result useful to > understand/fix the different SD implementations): > > 48.687227:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x00000c00 (state idle) > 48.687233:sdcard_command_response (no response) (state idle) > 48.689237:sdcard_normal_command IO_RW_DIRECT/ CMD52 arg 0x80000c08 (state idle) > 48.689244:sdcard_command_response (no response) (state idle) > 48.690877:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) > 48.690890:sdcard_command_response (no response) (state idle) > 48.723486:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) > 48.723507:sdcard_command_response 00 00 01 aa (state idle) > 48.723886:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) > 48.723892:sdcard_command_response (no response) (state idle) > 48.724019:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) > 48.724023:sdcard_command_response (no response) (state idle) > 48.724110:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) > 48.724115:sdcard_command_response (no response) (state idle) > 48.724178:sdcard_normal_command IO_SEND_OP_COND/ CMD05 arg 0x00000000 (state idle) > 48.724181:sdcard_command_response (no response) (state idle) > 48.724999:sdcard_command_response 00 40 01 20 (state idle) > 48.725214:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x00000000 (state idle) > 48.725225:sdcard_command_response 40 ff ff 00 (state idle) > 48.727113:sdcard_normal_command GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) > 48.727125:sdcard_command_response (no response) (state idle) > 48.729206:sdcard_normal_command SEND_IF_COND/ CMD08 arg 0x000001aa (state idle) > 48.729213:sdcard_command_response 00 00 01 aa (state idle) > 48.729339:sdcard_command_response 00 00 01 20 (state idle) > 48.729412:sdcard_app_command SD_SEND_OP_COND/ACMD41 arg 0x40300000 (state idle) > 48.729419:sdcard_command_response c0 ff ff 00 (state ready) > 48.729786:sdcard_normal_command ALL_SEND_CID/ CMD02 arg 0x00000000 (state ready) > 48.729797:sdcard_command_response aa 58 59 51 45 4d 55 21 01 de ad be ef 00 62 19 (state identification) > 48.730825:sdcard_normal_command SEND_RELATIVE_ADDR/ CMD03 arg 0x00000000 (state identification) > 48.730835:sdcard_command_response 45 67 05 00 (state standby) > 48.731221:sdcard_normal_command SEND_CSD/ CMD09 arg 0x45670000 (state standby) > 48.731228:sdcard_command_response 40 0e 00 32 5b 59 00 00 0d 47 7f 80 0a 40 00 00 (state standby) > 48.732012:sdcard_normal_command SELECT/DESELECT_CARD/ CMD07 arg 0x45670000 (state standby) > 48.732021:sdcard_command_response 00 00 07 00 (state transfer) > 48.732419:sdcard_command_response 00 00 09 20 (state transfer) > 48.764983:sdcard_app_command SEND_SCR/ACMD51 arg 0x00000000 (state transfer) > 48.765000:sdcard_command_response 00 00 09 20 (state sendingdata) > 48.766951:sdcard_command_response 00 00 09 20 (state transfer) > 48.767159:sdcard_app_command SD_STATUS/ACMD13 arg 0x00000000 (state transfer) > 48.767168:sdcard_command_response 00 00 09 20 (state sendingdata) > 48.966731:sdcard_normal_command READ_MULTIPLE_BLOCK/ CMD18 arg 0x00000000 (state transfer) > 48.966763:sdcard_command_response 00 00 09 00 (state sendingdata) > 48.974869:sdcard_normal_command STOP_TRANSMISSION/ CMD12 arg 0x00000000 (state sendingdata) > 48.974877:sdcard_command_response 00 00 0b 00 (state transfer) > 50.044308:sdcard_normal_command SEND_STATUS/ CMD13 arg 0x45670000 (state transfer) > 50.044330:sdcard_command_response 00 00 09 00 (state transfer) > [...] > > Regards, > > Phil. > > Based-on: 20171213213557.26561-7-f4bug@amsat.org > (QTests: use Python to run complex tests) As this series can't be merged until the Python for Qtest series is merged I'm not going to go over this now. Let's wait and see how that discussion goes first. Alistair > > Philippe Mathieu-Daudé (26): > sdbus: add a QMP command to access a SDBus > sdcard: add Python qtests > sdcard: use ldst API > sdcard: replace fprintf() -> qemu_log_mask() > sdcard: rename sd_set_mode() -> sd_update_mode() > sdcard: add sd_set_mode() > sdcard: add sdcard_set_mode() trace event > sdcard: add sd_set_state() > sdcard: add a sdcard_set_state() trace event > sdcard: use more detailled state/mode trace events > sdcard: use warn_report() instead of fprintf() > sdcard: replace DPRINTF() by trace events > sdcard: add more trace events > sdcard: use qemu_hexbuf_strdup() to trace command response > sdcard: use PW_LEN define instead of '16' magic > sdcard: let cmd_valid_while_locked() returns a bool > sdcard: rename sd_set_REG() functions called by sd_reset() as sd_reset_REG() > sdcard: move Memory Card registers together > sdcard: add DSR register > sdcard: add/use SD_CMD_MAX to check valid SD commands > sdcard: add sd_cmd_abbreviation() to resolve the SD command id > sdcard: reduce sd_cmd traces > sdcard: add ACMD trace events > sdcard: use a 16-bit type for the 16-bit RCA register > sdcard: add/use a SDCardCommandClass enum instead of magic numbers > sdcard: add/use a ccc_spi enum for the commands supported in SPI mode > > qapi-schema.json | 41 ++++ > hw/sd/core.c | 43 ++++ > hw/sd/sd.c | 519 +++++++++++++++++++++++++++++++------------------ > stubs/qmp_sdbus.c | 11 ++ > hw/sd/trace-events | 17 ++ > stubs/Makefile.objs | 1 + > tests/Makefile.include | 2 + > tests/sdcard_tests.py | 172 ++++++++++++++++ > 8 files changed, 617 insertions(+), 189 deletions(-) > create mode 100644 stubs/qmp_sdbus.c > create mode 100755 tests/sdcard_tests.py > > -- > 2.15.1 > >
I'll try to give a status on this series. First, let me collect few subthreads here to recapitulate: >> On 14/12/2017 10:06, Kevin Wolf wrote: > [...] >> Doing this kind of thing over QMP doesn't look right to me. qtests >> should access hardware the same way as real guests access the hardware >> (i.e. MMIO and I/O ports). > > Yes, I agree with you, however this command does not implement a guest > access behavior (MMIO and I/O ports) but a _bus_ access. > > Guests access buses via MMIO/IOP hardware frontend (bus master), bus > slave devices might be considered as backend, like the BlockBackend. > > As the current iotests are meant for backend testing, this command is > meant for SDBus backend testing. > > Actually with SDHCI I started to qtest the hardware frontend then > realized the backend was incorrect, so I had to go this way to fix it. > Later series do test the HCI using C qtests. > > This approach should works for any buses, and start to be quite > interesting with: > - hot-plug buses to unplug/plug slaves > - multi-master buses like I2C to inject noise on the bus and see if the > host can recover/continue > - testing slave failures like a bricked SPI slave keeping some bus lines > held and checking if the HCI expose this failure to the guest (or the > guest checking the HCI for failures) > [...] >> On 12/14/2017 06:34 AM, Paolo Bonzini wrote: >> Yeah, what we usually do is not test the device (e.g. SCSI) directly, >> but only through the HBA (e.g. virtio-scsi or AHCI, it would be SDHCI in >> this case). > > Yes, a SDHCI qtest is added in a later series (in C) using MMIO access: > http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg02391.html > > But to be sure the SDHCI is correct I needed a SD slave to behave > correctly ;) Hence this "bus test". On 12/15/2017 09:13 PM, Alistair Francis wrote: >> Based-on: 20171213213557.26561-7-f4bug@amsat.org >> (QTests: use Python to run complex tests) > > As this series can't be merged until the Python for Qtest series is > merged I'm not going to go over this now. Let's wait and see how that > discussion goes first. On 12/14/2017 06:34 AM, Paolo Bonzini wrote: >> create mode 100755 tests/sdcard_tests.py > > How hard would it be to rewrite this test as an SDHCI test? Sadly, more than two weeks later, I can tell you it was somehow hard. I previously spent 1 day to write this quick python test, 1 more to write more tests (different sdcard size and handle SD/MMC/SPI protocols). Remember this series' goal was to have a correct sdcard model so we could improve the various SDHCI safely (fix bugs, add support for Spec v3.01). Back to C. Apparently the easiest HCI was the PXA2xx one. First let find an image and boot it to see how it behaves. After spending time digging on the Gumstix web, I could find a correct set of u-boot + uImage + rootfs, and generate the test image. Let's boot it: $ qemu-system-arm -M connex -nographic -pflash connex.img \ -drive if=sd,cache=unsafe,file=sdcard.img qemu: hardware error: pxa2xx_timer_write: Bad offset 0x00000000000000d8 CPU #0: R00=40f00030 R01=40a000d8 R02=000000c9 R03=48000004 R04=00000300 R05=00000000 R06=00000000 R07=00000000 R08=00000000 R09=00000000 R10=00000000 R11=00000000 R12=00000868 R13=00000000 R14=0000090c R15=00000f0c PSR=000001d3 ---- A svc32 FPSCR: 00000000 Aborted Ok, let's find the PXA255 datasheet, find the timer section, look registers, implement what's missing, try again later... $ qemu-system-arm -M connex -nographic -pflash connex.img \ -drive if=sd,cache=unsafe,file=sdcard.img U-Boot 1.2.0 (May 10 2008 - 21:17:19) - PXA270@400 MHz - 1604 Hit any key to stop autoboot: 0 ## Booting image at a2000000 ... Image Name: Angstrom/2.6.21/gumstix-custom-c Image Type: ARM Linux Kernel Image (uncompressed) Starting kernel ... Linux version 2.6.21 (otto@otto) (gcc version 4.1.2) #1 PREEMPT Mon May 12 14:33:32 PDT 2008 CPU: XScale-PXA255 [69052d00] revision 0 (ARMv5TE), cr=00007977 Machine: The Gumstix Platform Probing Gumstix Flash ROM at physical address 0x00000000 (16-bit bankwidth) Gumstix Flash ROM: Found 1 x16 devices at 0x0 in 16-bit bank Creating 3 MTD partitions on "Gumstix Flash ROM": 0x00000000-0x00040000 : "Bootloader" 0x00040000-0x00f00000 : "RootFS" 0x00f00000-0x01000000 : "Kernel" VFS: Mounted root (jffs2 filesystem). INIT: version 2.86 booting qemu-system-arm: Trying to execute code outside RAM or ROM at 0x000618e8 qemu: fatal: Trying to execute code outside RAM or ROM at 0x000618e8 Your guest kernel has a bug and crashed by jumping off into nowhere Execution cannot continue; stopping here. R00=00000000 R01=beda1d04 R02=000bd818 R03=000b1d78 R04=000bd838 R05=000bd80c R06=00000001 R07=000bda88 R08=00000000 R09=00000000 R10=401d7000 R11=00000000 R12=00000000 R13=beda1a38 R14=000876b8 R15=000618e8 PSR=60000010 -ZC- A usr32 FPSCR: 00000000 No time to figure out this, but at least U-Boot worked and have shell accessible: U-Boot 1.2.0 (May 10 2008 - 21:17:19) - PXA270@400 MHz - 1604 Hit any key to stop autoboot: 0 GUM> mmcinit 5366@1514908231.461749:sdcard_normal_command SD GO_IDLE_STATE/ CMD00 arg 0x00000000 (state idle) 5366@1514908231.461760:sdcard_reset 5366@1514908231.662147:sdcard_app_command SD SD_SEND_OP_COND/ACMD41 arg 0x00200000 (state idle) 5366@1514908231.662278:sdcard_normal_command SD ALL_SEND_CID/ CMD02 arg 0x00000000 (state ready) 5366@1514908231.662419:sdcard_normal_command SD SEND_RELATIVE_ADDR/ CMD03 arg 0x00000000 (state identification) 5366@1514908231.662515:sdcard_normal_command SD SEND_CSD/ CMD09 arg 0x45670000 (state standby) Detected: 32768 blocks of 512 bytes (16MB) SD card. Vendor: Man aa OEM XY "QEMU!" Date 02/2006 Product: 3735928559 Revision: 0.1 5366@1514908231.664080:sdcard_normal_command SD SELECT/DESELECT_CARD/ CMD07 arg 0x45670000 (state standby) 5366@1514908231.664168:sdcard_app_command SD SET_BUS_WIDTH/ACMD06 arg 0x00000002 (state transfer) 5366@1514908231.664568:sdcard_normal_command SD SET_BLOCKLEN/ CMD16 arg 0x00000200 (state transfer) 5366@1514908231.664642:sdcard_normal_command SD READ_SINGLE_BLOCK/ CMD17 arg 0x00000000 (state transfer) 5366@1514908231.664648:sdcard_read_block addr 0x0 size 0x200 GUM> Ok this might be useful, however this board is supposed to have the card plugged in MMC mode which is not yet modelled. We'll can still use it to test the SD protocol! Good. Let's write a MMC qtest adapter using this MMIO device. We have to follow the datashit state machines change, [........] 3 days later: I still didn't succeed to reproduce U-Boot SD commands. Bad choice, this wasn't probably the easiest HCI. Let's try with another one. What about this simple SPI mode modelled in hw/sd/ssi-sd.c? $ git grep ssi-sd hw/arm/stellaris.c:1377: sddev = ssi_create_slave(bus, "ssi-sd"); Cool, let's use the lm3s6965evb machine. [...] write SPI test [...] [...] implement the qtest SD SPI adapter [...] test it! not working, the bus is never accessed... :( After a few debugging, it seems we correctly MMIO access the PL022 but then our sdcard isn't responding, why? Looking at the monitor: $ arm-softmmu/qemu-system-arm -M lm3s6965evb -monitor stdio \ -drive if=sd,cache=unsafe,file=/tmp/ok -accel qtest (qemu) info qtree bus: main-system-bus type System dev: pl022, id "" gpio-out "sysbus-irq" 1 mmio 0000000040008000/0000000000001000 bus: ssi type SSI dev: ssd0323, id "" gpio-in "" 1 gpio-in "ssi-gpio-cs" 1 dev: ssi-sd, id "" gpio-in "ssi-gpio-cs" 1 Where is dangling our sdcard?... Looking at the code, stellaris_init() never use a SD card. I suppose the code using ssi-sd.c was lost during some refactor, we'll look later in git history, for now let's add the missing code to plug/use our card. [...] (qemu) info qtree bus: main-system-bus type System dev: pl022, id "" gpio-out "sysbus-irq" 1 mmio 0000000040008000/0000000000001000 bus: ssi type SSI dev: ssd0323, id "" gpio-in "" 1 gpio-in "ssi-gpio-cs" 1 dev: ssi-sd, id "" gpio-in "ssi-gpio-cs" 1 bus: sd-bus type sd-bus dev: sd-card, id "" drive = "sd0" spi = true Cool, our card is here! Now run qtests! Oops, many many failures... Again, probably nobody used the sdcard code in SPI mode since age. Remember, I try to have a working card to test the generic SDHCI to implement the v3... This SPI mode could have been the simpler way to test the card if it was working but it isn't, no time for that. Let's drop our MMC and SPI tests and find some working board using the SD mode. Ok we have the nuri board (exynos4210), with a SDHCI v2. Hmm but wait ... Am I going to test the card with the HCI I want to test? ... Ok, clock is ticking, let's forget about using HCI via MMIO and try again our first idea, access the _bus_ via QMP! [... lot of fun trying with qobjects, qobject_to_qdict, qlist = qdict_get(), qobject_to_qstring, qstring_get_str, ...] 4 days. lots of leaks, not enough QDECREF()? 2 days. What am I doing with valgrind? I'm supposed to spend time on the SDHCI model. Let's ignore those leaks, and run the test. Plug a card. We need a Spec v3 working to plug a SDXC card, but smaller cards are supposed to work. Let's test the easiest, the smaller card! Plug a SDSC card: tests fail.... Oh, SDSC support broken for cards between 1G-2G. Now I remember and understand the warning I read when preparing the first Connex card: "The current qemu version seems to be limited to 1GB card images." [1] Luckily the SDHC cards work better, cool! let's start working! Oh but wait which day is it...?! The deadline is over, I'm out of schedule, too late. No time to write more qtests, I'll just run the first python sample test and send the series as it :( Regards, Phil. https://wiki.gumstix.com/index.php/Making_qemu_images#mmc.2FCF_images
© 2016 - 2024 Red Hat, Inc.