qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Peter Maydell <peter.maydell@linaro.org>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>
Subject: [Qemu-devel] [PATCH v2 06/14] sdcard: Add test_sd_verify_cksum_frame136()
Date: Wed,  9 May 2018 00:46:50 -0300	[thread overview]
Message-ID: <20180509034658.26455-7-f4bug@amsat.org> (raw)
In-Reply-To: <20180509034658.26455-1-f4bug@amsat.org>

Per the Physical Layer Simplified Spec. "3.6 Bus Protocol":

  There are two types of Data packet format for the SD card.

  (1) Usual data (8-bit width): The usual data (8-bit width) are sent in
      LSB (Least Significant Byte) first, MSB (Most Significant Byte) last
      sequence. But in the individual byte, it is MSB (Most Significant Bit)
      first, LSB (Least Significant Bit) last.

  (2) Wide width data (SD Memory Register): The wide width data is shifted
      from the MSB bit.

Since the SD frames use different byte order, we use the lm32 target
for big-endian qtesting, and aarch64 for the little-endian qtesting.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/sdcard-test.c    | 35 +++++++++++++++++++++++++++++++++++
 tests/Makefile.include |  4 ++++
 2 files changed, 39 insertions(+)
 create mode 100644 tests/sdcard-test.c

diff --git a/tests/sdcard-test.c b/tests/sdcard-test.c
new file mode 100644
index 0000000000..c59af28382
--- /dev/null
+++ b/tests/sdcard-test.c
@@ -0,0 +1,35 @@
+/*
+ * QTest testcase for SD protocol and cards
+ *
+ * Examples taken from:
+ *
+ * - Physical Layer Simplified Specification (chap. 4.5: Cyclic Redundancy Code)
+ * - http://wiki.seabright.co.nz/wiki/SdCardProtocol.html
+ *
+ * Tests written by Philippe Mathieu-Daudé <f4bug@amsat.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "hw/sd/sd.h"
+
+static void test_sd_response_frame136_crc7(void)
+{
+    uint8_t buf[16];
+
+    /* response to CMD2 ALL_SEND_CID */
+    memcpy(&buf, "\x1d\x41\x44\x53\x44\x20\x20\x20\x10\xa0\x40\x0b\xc1\x00\x88",
+           sizeof(buf));
+    buf[15] = sd_frame136_calc_checksum(buf);
+    g_assert_cmphex(buf[15], ==, 0xad);
+}
+
+int main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    qtest_add_func("sd/prepare_resp136_crc7", test_sd_response_frame136_crc7);
+
+    return g_test_run();
+}
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 3b9a5e31a2..34230b150e 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -384,6 +384,9 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/sdcard-test$(EXESUF)
+
+check-qtest-lm32-y += tests/sdcard-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
@@ -835,6 +838,7 @@ tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y)
 tests/numa-test$(EXESUF): tests/numa-test.o
 tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o
 tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y)
+tests/sdcard-test$(EXESUF): tests/sdcard-test.o hw/sd/sdmmc-internal.o
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
 	$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")
-- 
2.17.0

  parent reply	other threads:[~2018-05-09  3:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  3:46 [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 01/14] sdcard: Use the ldst API Philippe Mathieu-Daudé
2018-06-28 17:13   ` Peter Maydell
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 02/14] sdcard: Constify sd_crc*()'s message argument Philippe Mathieu-Daudé
2018-05-09 17:58   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 03/14] sdcard: Fix sd_crc*() style Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_checksum() Philippe Mathieu-Daudé
2018-05-09 18:00   ` Alistair Francis
2018-05-09 19:15     ` Philippe Mathieu-Daudé
2018-05-09 23:04       ` Alistair Francis
2018-05-10  0:16         ` Philippe Mathieu-Daudé
2018-05-10 17:41           ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 05/14] sdcard: Move sd_crc7() and calc_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-09  3:46 ` Philippe Mathieu-Daudé [this message]
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 07/14] sdcard: Invert the sd_req_crc_is_valid() logic Philippe Mathieu-Daudé
2018-05-09 18:02   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 08/14] sdcard: Extract sd_frame48_verify_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-10  0:02   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 09/14] sdcard: Add sd_frame136_verify_checksum() Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 10/14] sdcard: Remove the SDRequest argument from internal functions Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 11/14] sdcard: Add sd_frame48_init(), replace SDRequest by a raw buffer Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 12/14] sdcard: Add tests to validate the 7-bit CRC checksum of 48-bit SD frame Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 13/14] sdcard: Add a "validate-crc" property Philippe Mathieu-Daudé
2018-05-21 12:59   ` Michael Walle
2018-05-09  3:46 ` [Qemu-devel] [RFC PATCH v2 14/14] hw/sd/ssi-sd: Enable CRC validation Philippe Mathieu-Daudé
2018-05-09 23:06   ` Alistair Francis
2018-05-10 15:18 ` [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180509034658.26455-7-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=alistair@alistair23.me \
    --cc=edgar.iglesias@xilinx.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).