From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB6534DAF87; Wed, 16 Sep 2026 17:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580504; cv=none; b=VCqQ5d/z1CsuT8ti/Yt0OuOZmXWcV/H3aJk5uNSNax8izEu5tQjCQTNqy/Y+t9SdCWdn1jl3+j5M9co098gttsjM0da3e9lGCgo+ad2hfF+FASLFk0YkaV1715Bxxr0nzj55FelbrZ252y6fAX/0O5HExHsoJ8UrY9g425Zdni4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580504; c=relaxed/simple; bh=AD1URK+HnrOJEzAB2nmAHcQI6H62TNiIISUuQGItQUQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q+L3Jl0Zd7lH9gaRIJ1QjzinmRfydw79lNQ6mcYROFygqD8yVNzZWcph1rL2y8j3cecfIeRdN67SnUJ+vyE/dGQamPJulMN3N97xVJkhsHmZWai8hyM6mm4TCyHz8gcJkwqvybUsDZcGK+XW2K9nXkb6J8DGdcHtqn7XAWDKUV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 91051200A7A; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-1Z; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:19 +0200 Subject: [PATCH v2 1/8] spi: spidev_test: include tools/include Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-1-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1266; i=jre@pengutronix.de; h=from:subject:message-id; bh=AD1URK+HnrOJEzAB2nmAHcQI6H62TNiIISUuQGItQUQ=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeXopK0iroFvJmpoPcq8s+anR5DZvECPPycbpufeU JwhYHqbpaOUhUGMi0FWTJElVk1OQcjY/7pZpV0szBxWJpAhDFycAjCRrfWMDJsVLpSGp27ozDSp OjxP0y/O5LrN/rdHZq//H/0n8In5h05GhmUP/6oHL7owyW6/0n5/TfF7Eb2L2W6mftHUFH7ropZ ewwcA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 Add tools/include to include paths to allow using macro helpers. Use ARRAY_SIZE() from tools/include/linux/kernel.h instead of maintaining a copy. Signed-off-by: Jonas Rebmann --- tools/spi/Makefile | 2 +- tools/spi/spidev_test.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/spi/Makefile b/tools/spi/Makefile index 7fccd245a535..8cf21ff8cd03 100644 --- a/tools/spi/Makefile +++ b/tools/spi/Makefile @@ -12,7 +12,7 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS +=3D -r =20 -CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/too= ls/include =20 ALL_TARGETS :=3D spidev_test spidev_fdx ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index f2135d619a0b..8058a7830b50 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -22,8 +22,7 @@ #include #include #include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#include =20 static void pabort(const char *s) { --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED1644DAF8B; Wed, 16 Sep 2026 17:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580510; cv=none; b=CWB4Xtal5jht3tQXBTEkdXcANZzpZQ6a0X07QF+DTmSFz2AYCEFZTr6YYJyBMIBDLXFBLE64V3VG7a2LST2TltFztRHC8hfexijmNM/j5pGyCyBm9GN0e2WDnToo4vULZQsxsOmdvl+QBO/hOnUBLoLeVovfDCbiHKxsQeWl7Y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580510; c=relaxed/simple; bh=JNy5Yx6yMWs5muypVNFnb3t95l2rqfGz1sk3N5YG4jw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nfv6t4LxA+7TuzoEdZfVAgN5P3WaUpwdlnCU33pAqGOMobsP0UBaVd8d3V5RiqZumkLekgVGU4wa/QuiMyxiy7iJM6JgziQZLSo40kACzuLchgNBwxeLqT6Fg8rdw0Z7c0l7JibxoImJCKwQjsfQWLSC5d5k3J0FUlstmDHG0SU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 99B162020F4; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-1h; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:20 +0200 Subject: [PATCH v2 2/8] spi: spidev_test: add compare mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-2-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3130; i=jre@pengutronix.de; h=from:subject:message-id; bh=ZounDEadQtVHLQGrV4KbDawt+D1nnNjTZAyAwrk6gl8=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeWYnEgwz9nQu4W7ROR2119Y5jFh4vYr9R3+K/7pt vxbd0TjbEcpC4MYF4OsmCJLrJqcgpCx/3WzSrtYmDmsTCBDGLg4BWAiwV4M/6P2ZNbH/E7Pr5ux R577rbSu7bMqfWZvm3nxyRWbNk1U/8nIcM7qzvmaLjYHicMbtq7515HtJHrtwKtvUxXDcqy6DvE JMgIA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Check whether the received data correspond to the transferred data but without enabling loopback mode in the controller. This is for testing with TX physically bridged to RX which is useful if a loopback mode is unavailable or insufficient. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 8058a7830b50..6ff103bdea5c 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -46,6 +46,7 @@ static int verbose; static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ +static int compare; =20 static uint8_t default_tx[] =3D { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -173,13 +174,14 @@ static void transfer(int fd, uint8_t const *tx, uint8= _t const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilopsvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbcdilopsvw]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" " -d --delay delay (usec)\n" " -w --word-delay word delay (usec)\n" " -l --loop loopback\n" + " -c --compare compare RX'ed and TX'ed data\n" "spi mode:\n" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" @@ -217,6 +219,7 @@ static void parse_opts(int argc, char *argv[]) { "delay", 1, 0, 'd' }, { "word-delay", 1, 0, 'w' }, { "loop", 0, 0, 'l' }, + { "compare", 0, 0, 'c' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, { "rx-cpha-flip", 0, 0, 'F' }, @@ -240,7 +243,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lcHOLC3ZFMNR248p:vS:I:", lopts, NULL); =20 if (c =3D=3D -1) @@ -270,6 +273,10 @@ static void parse_opts(int argc, char *argv[]) break; case 'l': mode |=3D SPI_LOOP; + compare =3D 1; + break; + case 'c': + compare =3D 1; break; case 'H': mode |=3D SPI_CPHA; @@ -427,7 +434,7 @@ static void transfer_buf(int fd, int len) _write_count +=3D len; _read_count +=3D len; =20 - if (mode & SPI_LOOP) { + if (compare) { if (memcmp(tx, rx, len)) { fprintf(stderr, "transfer error !\n"); hex_dump(tx, len, 32, "TX"); @@ -451,6 +458,9 @@ int main(int argc, char *argv[]) if (input_tx && input_file) pabort("only one of -p and --input may be selected"); =20 + if (compare & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) + pabort("-c (--compare) conflicts with -2 (--dual), -4 (--quad) or -8 (--= octal)"); + fd =3D open(device, O_RDWR); if (fd < 0) pabort("can't open device"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C535B4D957E; Wed, 16 Sep 2026 17:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580507; cv=none; b=VWlT0CqKM8dWl32YE2ymk65cLyhEUj/S3CPnHDEXDPc4XZoqK1XIjPk/lw/uvzwpGfrfQpAzfFhyOwm+gFGCD9AVB6sTAnTh7BvNWkoPwMug9G9EFrZz4mF4QbnBBlOiJreKzWarNBZvCGufupS/AjS9Q9fox0PgwKt2kNmWLWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580507; c=relaxed/simple; bh=nEZScjsdudW8G7BwAH++bkryBsvgnsHuy1SUvnKB7vk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GB/JQCqMsRmh29BsdiY08UGLn1x9bl45SQB9pjZC+6pZlQdYVfyWXGAc47j8FfISpNYDYoWnlzxwkp6pk+zhZEpkmlhzNoYyCFVJ5StJSislJESX2PHGSSO0LIZzJTqKLClAUrvbgAYYtw0uMCA4xXe/RzHo++krOt7Dj4+R1BE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id A6FE32028FE; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-1q; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:21 +0200 Subject: [PATCH v2 3/8] spi: spidev_test: allow disabling rx or tx buffers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-3-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5060; i=jre@pengutronix.de; h=from:subject:message-id; bh=B7Bob2z1fLivMiEbkpNc/kLd83K0wg1xz/m/FnhpTws=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeXYysUhb6L6j2s/ydikNO1/ofUMSeHOo+F8vDtZ+ 7I67gSt7ihlYRDjYpAVU2SJVZNTEDL2v25WaRcLM4eVCWQIAxenAExE8wYjQ39eZcDtBq30jltJ s62lD83cc/yhy/EHETvLbxkmril5x8PwvzavYUVm1KR7T2fcdX2ewSd1M6nm7OS8xRYrZktmBMW E8gIA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Allow not providing rx or tx buffers. This is useful to check if drivers that don't use SPI_CONTROLLER_MUST_RX (or -TX respectively) handle their operations correctly without a buffer. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 66 ++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 6ff103bdea5c..b4f9c40a246a 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -47,6 +47,8 @@ static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; +static int do_tx =3D 1, do_rx =3D 1; +static int input_choices =3D 0; =20 static uint8_t default_tx[] =3D { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -153,7 +155,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) if (ret < 1) pabort("can't send spi message"); =20 - if (verbose) + if (verbose && tx) hex_dump(tx, len, 32, "TX"); =20 if (output_file) { @@ -168,13 +170,13 @@ static void transfer(int fd, uint8_t const *tx, uint8= _t const *rx, size_t len) close(out_fd); } =20 - if (verbose) + if (verbose && rx) hex_dump(rx, len, 32, "RX"); } =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbcdilopsvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvw]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -182,6 +184,8 @@ static void print_usage(const char *prog) " -w --word-delay word delay (usec)\n" " -l --loop loopback\n" " -c --compare compare RX'ed and TX'ed data\n" + " -t --no-tx don't send data\n" + " -r --no-rx don't receive data\n" "spi mode:\n" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" @@ -220,6 +224,8 @@ static void parse_opts(int argc, char *argv[]) { "word-delay", 1, 0, 'w' }, { "loop", 0, 0, 'l' }, { "compare", 0, 0, 'c' }, + { "no-tx", 0, 0, 't' }, + { "no-rx", 0, 0, 'r' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, { "rx-cpha-flip", 0, 0, 'F' }, @@ -243,7 +249,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lcHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:", lopts, NULL); =20 if (c =3D=3D -1) @@ -267,6 +273,7 @@ static void parse_opts(int argc, char *argv[]) break; case 'i': input_file =3D optarg; + input_choices++; break; case 'o': output_file =3D optarg; @@ -278,6 +285,13 @@ static void parse_opts(int argc, char *argv[]) case 'c': compare =3D 1; break; + case 't': + do_tx =3D 0; + input_choices++; + break; + case 'r': + do_rx =3D 0; + break; case 'H': mode |=3D SPI_CPHA; break; @@ -313,6 +327,7 @@ static void parse_opts(int argc, char *argv[]) break; case 'p': input_tx =3D optarg; + input_choices++; break; case '2': mode |=3D SPI_TX_DUAL; @@ -415,26 +430,31 @@ static void show_transfer_rate(void) =20 static void transfer_buf(int fd, int len) { - uint8_t *tx; - uint8_t *rx; + uint8_t *tx =3D NULL; + uint8_t *rx =3D NULL; int i; =20 - tx =3D malloc(len); - if (!tx) - pabort("can't allocate tx buffer"); - for (i =3D 0; i < len; i++) - tx[i] =3D random(); + if (do_tx) { + tx =3D malloc(len); + if (!tx) + pabort("can't allocate tx buffer"); + for (i =3D 0; i < len; i++) + tx[i] =3D random(); + } =20 - rx =3D malloc(len); - if (!rx) - pabort("can't allocate rx buffer"); + if (do_rx) { + rx =3D malloc(len); + if (!rx) + pabort("can't allocate rx buffer"); + } =20 transfer(fd, tx, rx, len); + if (do_tx) + _write_count +=3D len; + if (do_rx) + _read_count +=3D len; =20 - _write_count +=3D len; - _read_count +=3D len; - - if (compare) { + if (tx && rx && compare) { if (memcmp(tx, rx, len)) { fprintf(stderr, "transfer error !\n"); hex_dump(tx, len, 32, "TX"); @@ -455,8 +475,14 @@ int main(int argc, char *argv[]) =20 parse_opts(argc, argv); =20 - if (input_tx && input_file) - pabort("only one of -p and --input may be selected"); + if (input_choices > 1) + pabort("only one of -p, -i (--input), -t (--no-tx) may be selected"); + + if (compare && (!do_tx || !do_rx)) + pabort("-l/-c (--loop/--compare) conflict with -t (--no-tx) or -r (--no-= rx)"); + + if (!do_rx && output_file) + pabort("-t (--no-rx) conflicts with -o (--output)"); =20 if (compare & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) pabort("-c (--compare) conflicts with -2 (--dual), -4 (--quad) or -8 (--= octal)"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C29A54D9572; Wed, 16 Sep 2026 17:41:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580511; cv=none; b=aZR0Qz2h1dtCBwLeMlYuafw2ssB3ASd3udOrLWhs5itBqSB5HtLYt833NsxDJBwl2sd7n1oh3/OmDeoXZSR/GBD6T6yFb6AqPMK7H0rV+xfo64inylV/TMumk88t5qcCuxT5O7ovmfCu0Nl2bbq3cZtco3mhR5QyZephmEBL4qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580511; c=relaxed/simple; bh=YAgUVcdbbMUdE+Der1NuFD51gUOg60O+5KQPe/r8y2w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GkKcB/AsWasW7kPvLyFlFKkTLlHPLVJA2lVmNPAN6CelYVjONGw5voLT2e4Kj5JYV76ivvxZVaVmifmk2ylcNfQK1LrbVf0bAxNjvFhrWMWxhmepf5+Q6Q6yuvN2cQrYei8d6v9CAo62Mfkia3MvKidPvOfS92vHMP3Ajc53qKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id AF479202B14; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-1y; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:22 +0200 Subject: [PATCH v2 4/8] spi: spidev_test: don't send 0x0 or 0xff Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-4-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3450; i=jre@pengutronix.de; h=from:subject:message-id; bh=V5HOW+qe9y1hoBD5xHMMTx63hQXLftppCsPjFTs6X6w=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeW4ZgpjXuujD2Hc3Xc+XLT4dCSmtZ7ViYVlcb1H3 o0fP17v7yhlYRDjYpAVU2SJVZNTEDL2v25WaRcLM4eVCWQIAxenAExklzsjw4EZ/sb3THP31ml+ 3sVidCHUVOnzFxWOa0oLtZPuPrtXdpzhf/FlsYvN30VuyC7Rn3iB72DfJX27oP92xxt/z2ZjSVd PZAUA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Particularly when using compare mode, if the controller fails to transfer any data, asserting on a read of 0x00 or 0xff may lead a false negative test, indicating a byte was successfully transferred when the values simply originate from the pull-up or pull-down of RX. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index b4f9c40a246a..b8677fa3d134 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -47,6 +47,7 @@ static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; +static int nonzero; static int do_tx =3D 1, do_rx =3D 1; static int input_choices =3D 0; =20 @@ -176,7 +177,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvwz]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -200,6 +201,7 @@ static void print_usage(const char *prog) " -i --input input data from a file (e.g. \"test.bin\")\n" " -o --output output data to a file (e.g. \"results.bin\")\n" " -p Send data (e.g. \"1234\\xde\\xad\")\n" + " -z --nonzero Don't send 0x00 or 0xff bytes\n" " -S --size transfer size\n" " -I --iter iterations\n" "additional parameters:\n" @@ -237,6 +239,7 @@ static void parse_opts(int argc, char *argv[]) { "input", 1, 0, 'i' }, { "output", 1, 0, 'o' }, { "size", 1, 0, 'S' }, + { "nonzero", 0, 0, 'z' }, { "iter", 1, 0, 'I' }, { "bpw", 1, 0, 'b' }, { "lsb", 0, 0, 'L' }, @@ -249,7 +252,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:", lopts, NULL); =20 if (c =3D=3D -1) @@ -341,6 +344,10 @@ static void parse_opts(int argc, char *argv[]) case 'S': transfer_size =3D atoi(optarg); break; + case 'z': + nonzero =3D 1; + input_choices++; + break; case 'I': iterations =3D atoi(optarg); break; @@ -438,8 +445,11 @@ static void transfer_buf(int fd, int len) tx =3D malloc(len); if (!tx) pabort("can't allocate tx buffer"); - for (i =3D 0; i < len; i++) - tx[i] =3D random(); + for (i =3D 0; i < len; i++) { + do + tx[i] =3D random(); + while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + } } =20 if (do_rx) { @@ -476,7 +486,7 @@ int main(int argc, char *argv[]) parse_opts(argc, argv); =20 if (input_choices > 1) - pabort("only one of -p, -i (--input), -t (--no-tx) may be selected"); + pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero) may b= e selected"); =20 if (compare && (!do_tx || !do_rx)) pabort("-l/-c (--loop/--compare) conflict with -t (--no-tx) or -r (--no-= rx)"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 960E826A08A; Wed, 16 Sep 2026 17:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580522; cv=none; b=bscdVqCuz0ObRcAWAnQDmScfDG5BO9MUryBF+D64VyjXpyb0Rzrz34CoSsfThjA0aNgI3LzWJ2tdDEX+uaI1+uU5xDUNN0wkKuDdH3pcxYbnqBufeuVFekEZb2F5JSW150vXFckc3HKNRlYwjBRcgtEqMgEsucjz4CyY14xe4DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580522; c=relaxed/simple; bh=alY/MSLpjQXDUQkhyHVnle7gatNhjI2petGBHMsclyY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AkhvZdziznAbT1MFcXKobsG2YusZ4qMpSxhls/20nAchRggi1UNhdsyMotC7jvLVUx2+K+DHJpUIYvBfN12OSlrqog552qVPwLD/oCYpO43u0vCUXjlziHd2N4NY/lJ3voXu01jn86dpG03ZdjxOn0xgVBKfuYFpSAmOd1uTixA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id BB4F32059EC; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-27; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:23 +0200 Subject: [PATCH v2 5/8] spi: spidev_test: send predictable data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-5-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3352; i=jre@pengutronix.de; h=from:subject:message-id; bh=M8nFIvqqLdJaANmWo4RNM5k7zz2LnpvueZAYRQ3kbmA=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeW4/iKHRr75HGd07L0miYuq3LsfrszqeEhKVaN3t 6XF62aljlIWBjEuBlkxRZZYNTkFIWP/62aVdrEwc1iZQIYwcHEKwEQO8TEyXOEUPLKoQvrbCbZT WyJF8lXnMARpZisJRBv89KxdWtzcx8jQFudivczbsSvmw3HRa3dl1ihN2vPyWBIfR/D25PX7fYK 5AA== X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Introduce a flag to test on a predictable byte sequence instead of random bytes. This is useful when comparing multiple runs e.g. with an oscilloscope. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index b8677fa3d134..f1837f91a01f 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -49,6 +49,7 @@ static int interval =3D 5; /* interval in seconds for sho= wing transfer rate */ static int compare; static int nonzero; static int do_tx =3D 1, do_rx =3D 1; +static int predictable; static int input_choices =3D 0; =20 static uint8_t default_tx[] =3D { @@ -177,7 +178,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvwz]\n", prog); + printf("Usage: %s [-2348CDFHILMNOPRSZbcdiloprstvwz]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -202,6 +203,7 @@ static void print_usage(const char *prog) " -o --output output data to a file (e.g. \"results.bin\")\n" " -p Send data (e.g. \"1234\\xde\\xad\")\n" " -z --nonzero Don't send 0x00 or 0xff bytes\n" + " -P --predictable Send a predictable sequence instead of random nu= mbers\n" " -S --size transfer size\n" " -I --iter iterations\n" "additional parameters:\n" @@ -247,12 +249,13 @@ static void parse_opts(int argc, char *argv[]) { "no-cs", 0, 0, 'N' }, { "ready", 0, 0, 'R' }, { "mosi-idle-low", 0, 0, 'M' }, + { "predictable", 0, 0, 'P' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 }, }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PvS:zI:", lopts, NULL); =20 if (c =3D=3D -1) @@ -332,6 +335,10 @@ static void parse_opts(int argc, char *argv[]) input_tx =3D optarg; input_choices++; break; + case 'P': + predictable =3D 1; + input_choices++; + break; case '2': mode |=3D SPI_TX_DUAL; break; @@ -446,9 +453,13 @@ static void transfer_buf(int fd, int len) if (!tx) pabort("can't allocate tx buffer"); for (i =3D 0; i < len; i++) { - do - tx[i] =3D random(); - while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + if (predictable) { + tx[i] =3D i - iterations; + } else { + do { + tx[i] =3D random(); + } while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + } } } =20 @@ -486,7 +497,7 @@ int main(int argc, char *argv[]) parse_opts(argc, argv); =20 if (input_choices > 1) - pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero) may b= e selected"); + pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero), -P (= --predictable) may be selected"); =20 if (compare && (!do_tx || !do_rx)) pabort("-l/-c (--loop/--compare) conflict with -t (--no-tx) or -r (--no-= rx)"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06CF54D956F; Wed, 16 Sep 2026 17:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580514; cv=none; b=t8WlBIvZ+qZL/bN5OCPCwA0JGrrWusTKXw1jNIMMvQBIkHeReW+FeAb6PtvHKC7OLCRcazEPAbmZ95bawwkC8o5tdX05zkqY0G9eYZ4/tTvTFx0xDa2B1aU2FTELlfloqX2rt92XQWjnuAc0cG0InkFiuvVpsyoA4dj5l7DzuTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580514; c=relaxed/simple; bh=KSNyzh5YjDOws+odXvAk51oqlkLrUonRPAClwYD+wLs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SQ1QsSnDf72dFL0m2WRMxdxBU4OL30bq59x936ctLvTjWqxHOFvm/wbpte06BRr1GJbPqQKUYyERKKsQ3a4P+Xn1uvJs+32MWkenMmMOEOJk7wFV9EF00IXImfiqY+ownd78wpwPAh9gnjsQ5/5GHBxjmNnavCwDwODul+ViOVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id C296D2059ED; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-2G; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:24 +0200 Subject: [PATCH v2 6/8] spi: spidev_test: add option to split message into multiple transfers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-6-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5442; i=jre@pengutronix.de; h=from:subject:message-id; bh=8KEj3IvzoOXKJs7ZUqJHdLJMvXdjsE/TNRoqrqGGuBo=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeWE0Iv3Eq5c3q/f3xCt64k+lRA5dWv65m1+d9+zL 1+04u59tY5SFgYxLgZZMUWWWDU5BSFj/+tmlXaxMHNYmUCGMHBxCsBE7p5iZLhwJqFi52fN+SJC 1wpZSiesPCNUOdlz4c7CXAWDqYrNLncZGX5q79qiZ3lhToTz9mPG12vac3g/FlzIzVkVXLJuusF 5TRYA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde SPI_IOC_MESSAGE() submits a single SPI message containing one or more transfers. Introduce an option to allow splitting the message into multiple transfers. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 94 +++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index f1837f91a01f..6e5999b621cd 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -44,6 +44,7 @@ static uint16_t delay; static uint16_t word_delay; static int verbose; static int transfer_size; +static int transfers =3D 1; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; @@ -120,40 +121,60 @@ static int unescape(char *_dst, char *_src, size_t le= n) return ret; } =20 -static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t = len) +static void transfer(int fd, uint8_t const * const tx, uint8_t const * con= st rx, size_t len) { int ret; int out_fd; - struct spi_ioc_transfer tr =3D { - .tx_buf =3D (unsigned long)tx, - .rx_buf =3D (unsigned long)rx, - .len =3D len, - .delay_usecs =3D delay, - .word_delay_usecs =3D word_delay, - .speed_hz =3D speed, - .bits_per_word =3D bits, - }; - - if (mode & SPI_TX_OCTAL) - tr.tx_nbits =3D 8; - else if (mode & SPI_TX_QUAD) - tr.tx_nbits =3D 4; - else if (mode & SPI_TX_DUAL) - tr.tx_nbits =3D 2; - if (mode & SPI_RX_OCTAL) - tr.rx_nbits =3D 8; - else if (mode & SPI_RX_QUAD) - tr.rx_nbits =3D 4; - else if (mode & SPI_RX_DUAL) - tr.rx_nbits =3D 2; - if (!(mode & SPI_LOOP)) { - if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) - tr.rx_buf =3D 0; - else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL)) - tr.tx_buf =3D 0; + size_t bytes_per_word =3D DIV_ROUND_UP(bits, 8); + int effective_transfers =3D min_t(int, transfers, DIV_ROUND_UP(len, bytes= _per_word)); + struct spi_ioc_transfer *tr =3D calloc(effective_transfers, sizeof(*tr)); + size_t len_per_transfer =3D roundup(DIV_ROUND_UP(len, effective_transfers= ), bytes_per_word); + const uint8_t *tx_buf =3D tx; + const uint8_t *rx_buf =3D rx; + size_t rem =3D len; + + for (int i =3D 0; i < effective_transfers; i++) { + size_t n =3D min(rem, len_per_transfer); + + tr[i] =3D (struct spi_ioc_transfer) { + .tx_buf =3D (unsigned long)tx_buf, + .rx_buf =3D (unsigned long)rx_buf, + .len =3D n, + .delay_usecs =3D delay, + .word_delay_usecs =3D word_delay, + .speed_hz =3D speed, + .bits_per_word =3D bits, + }; + + if (tx_buf) + tx_buf +=3D n; + + if (rx_buf) + rx_buf +=3D n; + + rem -=3D n; + + if (mode & SPI_TX_OCTAL) + tr[i].tx_nbits =3D 8; + else if (mode & SPI_TX_QUAD) + tr[i].tx_nbits =3D 4; + else if (mode & SPI_TX_DUAL) + tr[i].tx_nbits =3D 2; + if (mode & SPI_RX_OCTAL) + tr[i].rx_nbits =3D 8; + else if (mode & SPI_RX_QUAD) + tr[i].rx_nbits =3D 4; + else if (mode & SPI_RX_DUAL) + tr[i].rx_nbits =3D 2; + if (!(mode & SPI_LOOP)) { + if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) + tr[i].rx_buf =3D 0; + else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL)) + tr[i].tx_buf =3D 0; + } } =20 - ret =3D ioctl(fd, SPI_IOC_MESSAGE(1), &tr); + ret =3D ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), &tr); if (ret < 1) pabort("can't send spi message"); =20 @@ -178,7 +199,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNOPRSZbcdiloprstvwz]\n", prog); + printf("Usage: %s [-2348CDFHILMNOPRSTZbcdiloprstvwz]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -213,6 +234,7 @@ static void print_usage(const char *prog) " -N --no-cs no chip select\n" " -R --ready slave pulls low to pause\n" " -M --mosi-idle-low leave mosi line low when idle\n" + " -T --transfers number of transfers\n" "misc:\n" " -v --verbose Verbose (show tx buffer)\n"); exit(1); @@ -250,12 +272,13 @@ static void parse_opts(int argc, char *argv[]) { "ready", 0, 0, 'R' }, { "mosi-idle-low", 0, 0, 'M' }, { "predictable", 0, 0, 'P' }, + { "transfers", 1, 0, 'T' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 }, }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PvS:zI:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PT:vS:zI= :", lopts, NULL); =20 if (c =3D=3D -1) @@ -322,6 +345,9 @@ static void parse_opts(int argc, char *argv[]) case 'M': mode |=3D SPI_MOSI_IDLE_LOW; break; + case 'T': + transfers =3D atoi(optarg); + break; case 'N': mode |=3D SPI_NO_CS; break; @@ -508,6 +534,12 @@ int main(int argc, char *argv[]) if (compare & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) pabort("-c (--compare) conflicts with -2 (--dual), -4 (--quad) or -8 (--= octal)"); =20 + if (transfers < 1) + pabort("-T (--transfers) must be 1 or above"); + + if (bits < 1) + pabort("-b (--bpw) must be 1 or above"); + fd =3D open(device, O_RDWR); if (fd < 0) pabort("can't open device"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 979464D7D21; Wed, 16 Sep 2026 17:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580532; cv=none; b=WBLGbcTwhvopH/JwYXzt1lTJBDdz6kgy89DFRujpTGEZVmhYx5jELcPWHwxlCHnCAzqLBtgw1ZGgE87KxKATEITmG8CWlIWHmOgVkKlITV451tSl3s5kd8a3WZz932Rv+gRwfslvet0NTlRCt3j6yoLfje6kHjAySguPw/rWxJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580532; c=relaxed/simple; bh=3ZXTXnZRe/6Fa2sgOEhSAIjFrhRlyL9A0z9yxKKFUpA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iQutYUM2MDFxmcEkHCZJWcleMmUv30xy2j3nkfIEUkUtMKYpSbnSstMkg8bpTXz3dGQnQbUZTSKdTSoFNFPkroIGYBM+9UybW+rn9hJhXevAN03hBh8kl0OzqhjdytipvO85ynUJc2NwtIp5HHndMtCydKL0dS15SamyacDABX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id D0D902059F0; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-2P; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:25 +0200 Subject: [PATCH v2 7/8] spi: spidev_test: print TX on error Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-7-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1048; i=jre@pengutronix.de; h=from:subject:message-id; bh=VknB9YyTMiQyXngLqRNCO17XzE00y4Lx4ZePbDwsdLE=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeWEWYaI0otdR0un5ce9n7qo2Eqhbv3vtlv7RHJiT KPcGDcv6ShlYRDjYpAVU2SJVZNTEDL2v25WaRcLM4eVCWQIAxenAEzkXhzDf+eAc0a3HtstlUub +/Pu8/l/dQ+dlm1YkLK9UbLqcNKv47oM/wPW7l8WrJH+oW6Zv88lmR8xrmXPIrYFKHVYzvira8N QwwwA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde If sending an spi message fails, dump its first up to 256 bytes to the console. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 6e5999b621cd..93867ebf39a0 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -175,8 +175,17 @@ static void transfer(int fd, uint8_t const * const tx,= uint8_t const * const rx, } =20 ret =3D ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), &tr); - if (ret < 1) + if (ret < 1) { + const size_t dump_len =3D min_t(size_t, len, 256); + int saved_errno =3D errno; + if (tx) { + hex_dump(tx, dump_len, 32, "TX"); + if (len > dump_len) + printf("... (%zu more bytes)\n", len - dump_len); + } + errno =3D saved_errno; pabort("can't send spi message"); + } =20 if (verbose && tx) hex_dump(tx, len, 32, "TX"); --=20 2.56.0.rc0.108.gf0ef1b96a0 From nobody Fri Sep 25 04:47:02 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D3E54FB9A7; Wed, 16 Sep 2026 17:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580524; cv=none; b=jEuTg/IZBfwQbpasINLg9j0yIWXlcVdTE2henwt0EOf6/e+516aBe3OFS2bqyZM+//KEnDTdGPsZ7bzjyS7wo13K2E3pc/nvOJCb9xun3W6nXRp6M1wuYuKQ6Ca7WC/i1JLUZ4ZvhVmTh69GS5yJ6bF8LnQF+5jXDQ1RPGa5ZH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789580524; c=relaxed/simple; bh=k8uqCdrwxAKZWOP0WarryWspJTDMEfd/+4102GV5LOA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CpknbBAKbirj1WKK7ajBbQmUQgU+GapXLgW8zfhaJxEkJbIWeXqqWe+X8YHGZWzJo2I8NtrgojkYqbDgxP8I+4JKmZBLcamUIsadfV+aEn4VNVuD2+VT2L+5szIxtasZiVbu3CmyVt/l+PG/vGVS9WPloFP/cyFeP9qUdNztIog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id DB46D2059F1; Wed, 16 Sep 2026 19:41:29 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x6tdR-001Gol-2X; Wed, 16 Sep 2026 19:41:29 +0200 From: Jonas Rebmann Date: Wed, 16 Sep 2026 19:41:26 +0200 Subject: [PATCH v2 8/8] spi: spidev_test: rewrite unescape() to stay in bounds Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-spi-sun4i-spidev_test-v2-8-e7d25bf96e4e@pengutronix.de> References: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> In-Reply-To: <20260916-spi-sun4i-spidev_test-v2-0-e7d25bf96e4e@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2406; i=jre@pengutronix.de; h=from:subject:message-id; bh=k8uqCdrwxAKZWOP0WarryWspJTDMEfd/+4102GV5LOA=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshadeXEkZk/70z6E68140fM52lXv1ZJal9elFO24kepw 6YnxpNPPO0oZWEQ42KQFVNkiVWTUxAy9r9uVmkXCzOHlQlkCAMXpwBMpHAHI8PzS7sXZO76JGcx h3F34+31PAx7Px1PZVY3ahPXTv66cpkvw/9S44rfKtMLAhmOL2+MEcueXb/OqEpRbmKjvOT8W7x mgUwA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 unescape() could read the source buffer out of bounds for inputs like "\\x" and could write the destination buffer out of bounds due to lack of checking against the len parameter. For better readability and consistency, rewrite it as a simplified version of unescape_string() in string_helpers.h. This includes rearranging src and dst parameters. Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 93867ebf39a0..a076fb4037e3 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -97,28 +98,31 @@ static void hex_dump(const void *src, size_t length, si= ze_t line_size, * Unescape - process hexadecimal escape character * converts shell input "\x23" -> 0x23 */ -static int unescape(char *_dst, char *_src, size_t len) +static int unescape(char *src, char *dst, size_t size) { - int ret =3D 0; - int match; - char *src =3D _src; - char *dst =3D _dst; + char *out =3D dst; unsigned int ch; =20 - while (*src) { - if (*src =3D=3D '\\' && *(src+1) =3D=3D 'x') { - match =3D sscanf(src + 2, "%2x", &ch); - if (!match) - pabort("malformed input string"); + while (*src && size--) { + if (src[0] =3D=3D '\\' && src[1] !=3D '\0') { + src++; + + if (src[0] =3D=3D 'x' && + isxdigit((unsigned char)src[1]) && + isxdigit((unsigned char)src[2]) && + sscanf(&src[1], "%2x", &ch)) { + *out++ =3D (unsigned char)ch; + src +=3D 3; + continue; + } =20 - src +=3D 4; - *dst++ =3D (unsigned char)ch; - } else { - *dst++ =3D *src++; + *out++ =3D '\\'; + if (!size--) + break; } - ret++; + *out++ =3D *src++; } - return ret; + return out - dst; } =20 static void transfer(int fd, uint8_t const * const tx, uint8_t const * con= st rx, size_t len) @@ -421,7 +425,7 @@ static void transfer_escaped_string(int fd, char *str) if (!rx) pabort("can't allocate rx buffer"); =20 - size =3D unescape((char *)tx, str, size); + size =3D unescape(str, (char *)tx, size); transfer(fd, tx, rx, size); free(rx); free(tx); --=20 2.56.0.rc0.108.gf0ef1b96a0